The RPG Maker Resource Kit

RMRK RPG Maker Creation => RPG Maker General => General Scripting => Topic started by: Decadent Sympozium on April 11, 2007, 12:14:44 PM

Title: Handling Fog
Post by: Decadent Sympozium on April 11, 2007, 12:14:44 PM
Warm greetings.

This may sound dumb but do you have an idea of how to make at least two fogs work at the same time? I did use search and didn't come up with what I wanted. I tried some of the tricks and failed to achieve it. It's the RPGM XP PK I'm talking about. To make it more precise, I want a forest shade fog to stand still while the mist fog moves around, I can deal with all just don't know how to put two of them.
Title: Re: Handling Fog
Post by: Snailer on April 11, 2007, 08:43:59 PM
I think this can only be done by scripting not sure though..
Title: Re: Handling Fog
Post by: Decadent Sympozium on April 12, 2007, 03:28:55 PM
Bumpysh
Title: Re: Handling Fog
Post by: Blizzard on April 12, 2007, 05:41:30 PM
If you need a "standing" fog, just use the "Show picture" command. ;8

EDIT:

Nvm, I didn't get the question right. Let me script it for you.

EDIT:

Code: [Select]
FOGNAMES = {}

# template:
# FOGNAMES[MAP_ID] = ["FOG_NAME", HUE, OPACITY, BLENDTYPE, ZOOM, X_OFF, Y_OFF]

FOGNAMES[1] = ["001-Fog01", 0, 80, 0, 0, 100.0, 0]

#==============================================================================
# Game_Map
#==============================================================================

class Game_Map
 
  attr_accessor :fog2_name
  attr_accessor :fog2_hue
  attr_accessor :fog2_opacity
  attr_accessor :fog2_blend_type
  attr_accessor :fog2_zoom
  attr_accessor :fog2_sx
  attr_accessor :fog2_sy
  attr_reader   :fog2_ox
  attr_reader   :fog2_oy
  attr_reader   :fog2_tone
 
  alias setup_fog2_later setup
  def setup(map_id)
    setup_fog2_later(map_id)
    @fog2_name = (FOGNAMES[map_id][0] == nil ? "" : FOGNAMES[map_id][0])
    @fog2_hue = (FOGNAMES[map_id][1] == nil ? 0 : FOGNAMES[map_id][1])
    @fog2_opacity = (FOGNAMES[map_id][2] == nil ? 0 : FOGNAMES[map_id][2])
    @fog2_blend_type = (FOGNAMES[map_id][3] == nil ? 0 : FOGNAMES[map_id][3])
    @fog2_zoom = (FOGNAMES[map_id][4] == nil ? 100.0 : FOGNAMES[map_id][4])
    @fog2_sx = (FOGNAMES[map_id][5] == nil ? 0 : FOGNAMES[map_id][5])
    @fog2_sy = (FOGNAMES[map_id][6] == nil ? 0 : FOGNAMES[map_id][6])
    @fog2_ox = 0
    @fog2_oy = 0
    @fog2_tone = Tone.new(0, 0, 0, 0)
    @fog2_tone_target = Tone.new(0, 0, 0, 0)
    @fog2_tone_duration = 0
    @fog2_opacity_duration = 0
    @fog2_opacity_target = 0
  end
 
  def start_fog2_opacity_change(opacity, duration)
    @fog2_opacity_target = opacity * 1.0
    @fog2_opacity_duration = duration
    @fog2_opacity = @fog2_opacity_target if @fog2_opacity_duration == 0
  end
 
  alias update_fog2_later update
  def update
    update_fog2_later
    @fog2_ox -= @fog2_sx / 8.0
    @fog2_oy -= @fog2_sy / 8.0
    if @fog2_tone_duration >= 1
      d = @fog2_tone_duration
      target = @fog2_tone_target
      @fog2_tone.red = (@fog2_tone.red * (d - 1) + target.red) / d
      @fog2_tone.green = (@fog2_tone.green * (d - 1) + target.green) / d
      @fog2_tone.blue = (@fog2_tone.blue * (d - 1) + target.blue) / d
      @fog2_tone.gray = (@fog2_tone.gray * (d - 1) + target.gray) / d
      @fog2_tone_duration -= 1
    end
    if @fog2_opacity_duration >= 1
      d = @fog2_opacity_duration
      @fog2_opacity = (@fog2_opacity * (d - 1) + @fog2_opacity_target) / d
      @fog2_opacity_duration -= 1
    end
  end
 
end

#==============================================================================
# Spriteset_Map
#==============================================================================

class Spriteset_Map
 
  alias init_fog2_later initialize
  def initialize
    init_fog2_later
    @fog2 = Plane.new(@viewport1)
    @fog2.z = 3000
    update
  end
 
  alias disp_fog2_later dispose
  def dispose
    @fog2.dispose
    disp_fog2_later
  end
 
  alias upd_fog2_later update
  def update
    upd_fog2_later
    if @fog2_name != $game_map.fog2_name or @fog2_hue != $game_map.fog2_hue
      @fog2_name = $game_map.fog2_name
      @fog2_hue = $game_map.fog2_hue
      if @fog2.bitmap != nil
        @fog2.bitmap.dispose
        @fog2.bitmap = nil
      end
      if @fog2_name != ""
        @fog2.bitmap = RPG::Cache.fog(@fog2_name, @fog2_hue)
      end
      Graphics.frame_reset
    end
    @fog2.zoom_x = $game_map.fog2_zoom / 100.0
    @fog2.zoom_y = $game_map.fog2_zoom / 100.0
    @fog2.opacity = $game_map.fog2_opacity
    @fog2.blend_type = $game_map.fog2_blend_type
    @fog2.ox = $game_map.display_x / 4 + $game_map.fog2_ox
    @fog2.oy = $game_map.display_y / 4 + $game_map.fog2_oy
    @fog2.tone = $game_map.fog2_tone
  end
 
end


Use Call script and use this here

Code: [Select]
$game_map.start_fog2_opacity_change(OPACTIY, DURATION)

to change the second fog. This works the same like the fog change event command for the first one.
For any changes during the map you can just use:

Code: [Select]
$game_map.fog2_ATTRIBUTE_NAME = NEW_VALUE

ATTRIBUTE_NAME can be one of those here:

Code: [Select]
name
hue
opacity
blend_type
zoom
sx
sy

Don't forget to set up the configuration FOGNAMES for each map you want. Skip it for any maps you don't want this feature.
Title: Re: Handling Fog
Post by: Edwin VanCleef on April 12, 2007, 08:11:14 PM
Can't this be done with multiple pictures? That would be simpler I think.

By the way.... How do I change the board skin? I'm stuck with the pink one  :'(
Title: Re: Handling Fog
Post by: Blizzard on April 12, 2007, 08:17:16 PM
Profile -> Look and layout preferences (on the top).
Using mulitple pics would increase the lag , maybe even dramatically (and it's harder...). That script I made for you will use the same way to show a fog just like the default fog is shown. I guess this to be the optimal solution.
Title: Re: Handling Fog
Post by: Decadent Sympozium on April 12, 2007, 09:16:14 PM
Bravo. You inspire me. I put that over main index script, yes?
Title: Re: Handling Fog
Post by: Decadent Sympozium on April 20, 2007, 01:44:16 PM
Blizzard, art thou sure of your script? I'm getting an error, but regardless, there's something bugging me, if you take a look at the begining of your script, you wrote

"FOGNAMES[MAP_ID] = ["FOG_NAME", HUE, OPACITY, BLENDTYPE, ZOOM, X_OFF, Y_OFF]"

And beneath

"FOGNAMES[1] = ["001-Fog01", 0, 80, 0, 0, 100.0, 0]"

Now, as far as I know "zoom" is set as 100.0, however, you placed 100.0 at X_OFF, and 0 at Zoom, so I am wondering if you accidently miscripted something else or I'm just being ignorant to something.

As for the error, I may be missing something, I put the script above main (or was that a mistake) and on test I'm getting error

"??? 28 ??? NoMethod Error undefined error "[]" for nil: NillClass"

However, now I'm thinking, am I supposed to replace something else except to write file names there at the begining of your script?
Title: Re: Handling Fog
Post by: Decadent Sympozium on April 25, 2007, 06:27:03 AM
Bump.
Title: Re: Handling Fog
Post by: :) on April 25, 2007, 01:37:16 PM
i'm sorry but blizzard does not visit RMRK anymore. You will have to wait for someone else with scripting knowlege to help.
Title: Re: Handling Fog
Post by: Decadent Sympozium on April 29, 2007, 01:14:52 PM
i'm sorry but blizzard does not visit RMRK anymore. You will have to wait for someone else with scripting knowlege to help.

What do you mean he doesn't visit it anymore? Mind providing some more info?
Title: Re: Handling Fog
Post by: :) on April 29, 2007, 01:56:25 PM
the fact that he "quit" rmrk. There is no "evidence" he just left after some problems around here.

read his sig, you can find his most updated scripts where? not here...at his forum. he left.
Title: Re: Handling Fog
Post by: Zeriab on April 29, 2007, 01:57:30 PM
You can find him at his forums Chaos Project (http://z3.invisionfree.com/ChaosProject/index.php?act=idx)