[XP] Unlimited Fogs

Started by G_G, April 09, 2012, 12:43:22 pm

Previous topic - Next topic

G_G

April 09, 2012, 12:43:22 pm Last Edit: October 12, 2013, 10:24:08 am by gameus
Unlimited Fogs
Authors: game_guy
Version: 1.2
Type: Graphical Enhancement
Key Term: Environment Add-on



Introduction

No offense to LiTTleDRAgo or his script, but after I over viewed his Multiple Fogs script, I thought to myself it could have been done a lot better. And why limit it to just 3 extra fogs? I also noticed how he let users have little control over fogs. You couldn't set the z index, the hue, or anything of the sort. I had  bit of extra time on my hands, so I made this.

Ever need more than one fog for a map? Maybe more than two fogs? With this unique script, you can have unlimited fogs on one map! And with a few easy script calls, you can customize every aspect of a fog at anytime!


Features


  • Unlimited Fogs on Any Map

  • Change Fog's properties at any time

  • Easy to use script calls




Screenshots

Spoiler: ShowHide



Demo

Demo 1.1 (Bugged, but shows you how to setup fogs)


Script

Spoiler: ShowHide

#===============================================================================
# Unlimited Fogs
# Version 1.2
# Author game_guy
#-------------------------------------------------------------------------------
# Intro:
# Ever need more than one fog for a map? Maybe more than two fogs? With this
# unique script, you can have unlimited fogs on one map! And with a few
# easy script calls, you can customize every aspect of a fog at anytime!
#
# Features:
# Unlimited Fogs on Any Map
# Change Fog's properties at any time
# Easy to use script calls
#
# Instructions:
# There is nothing to configure so lets get onto the script calls!
#-------------------------------------------------------------------------------
# add_fog(index, file, [z, scroll_x, scroll_y, opacity, zoom, blend, hue])
#  index    - This is to keep track of the fogs on screen (more on this later)
#  file     - Filename for the fog
#  z        - The z index of the fog. This is used for layering. (Default: 3000)
#  scroll_x - Horizontal scrolling speed for the fog. (Default: 0)
#  scroll_y - Vertical scrolling speed for the fog. (Default: 0)
#  opacity  - Opacity level for the fog. (Default: 64)
#  zoom     - Zoom level for the fog. (Default: 1.0)
#  blend    - Blend type for the fog. (Default: 0)
#  hue      - Hue for the fog. (Default: 0)
#
#  Note: When using this script call, the parameters with default values don't
#        need to be set when calling it.
#        e.g. add_fox(1, "001-Fog01") - Works because all parameters after
#        has a default value.
# This script call simply adds a fog with the set parameters.
#-------------------------------------------------------------------------------
# remove_fog(index)
#  index - Remember the index we set in "add_fog"? Put the same number in here
#          to remove it.
#
# This script call simply removes a fog.
#-------------------------------------------------------------------------------
# fogs(index)
#  index - The index we used to create our original fog.
#
# This handy script call returns the actual fog so you can edit individual
# properties. For example:
#   fog = fogs(1)
#   fog.scroll_x = 2
#   fog.scroll_y = 2
# This grabs the fog at index "1" and sets the scroll speed for x and y.
# (See below for all the properties/methods you can use)
#-------------------------------------------------------------------------------
# Fog Properties:
# These are the following properties/methods you can use when editing
# individual fogs.
#   visible    = Whether fog is visible or not (true/false)
#   opacity    = Opacity of the fog. (0 to 255)
#   z          = Z index of the fog.
#   scroll_x   = Horizontal scroll speed.
#   scroll_y   = Vertical scroll speed.
#   zoom_x     = Horizontal zoom factor.
#   zoom_y     = Vertical zoom factor.
#   blend_type = Blend mode for fog. (0, 1, or 2)
#   filename(new_file, [hue])
#    -new_file = New fog file.
#    -hue      = Hue for new fog. (Default: 0)
#-------------------------------------------------------------------------------
# Thats about it. Due take warning that the more fogs you add, the more
# probable lag you'll run into. Adding an extra two or three shouldn't hurt too
# much though. ;)
#
# Compatibility:
# Not tested with SDK.
# Should be compatible with everything.
#
# Credits:
# game_guy ~ For making the script.
# LiTTleDRAgo ~ For the original idea.
#===============================================================================
class Spriteset_Map
 
 alias gg_fogs_init_spriteset_map_lat initialize
 def initialize
   @fogs = []
   gg_fogs_init_spriteset_map_lat
 end
 
 alias gg_fogs_update_spriteset_map_lat update
 def update
   @fogs.each {|fog| fog.update if fog != nil }
   gg_fogs_update_spriteset_map_lat
 end
 
 alias gg_fogs_dispose_spriteset_map_lat dispose
 def dispose
   @fogs.each {|fog| fog.dispose if fog != nil }
   gg_fogs_dispose_spriteset_map_lat
 end
 
 def fogs(n)
   if @fogs[n] == nil
     @fogs[n] = ScrollPlane.new(@viewport1)
   end
   return @fogs[n]
 end
 
 def add_fog(index, file, z = 3000, ox = 0, oy = 0, opacity = 64, zoom = 1.0, blend = 0, hue = 0)
   remove_fog(index)
   fog = ScrollPlane.new(@viewport1)
   fog.bitmap = RPG::Cache.fog(file, hue)
   fog.z = z
   fog.blend_type = blend
   fog.opacity = opacity
   fog.zoom_x = zoom
   fog.zoom_y = zoom
   fog.scroll_x = ox
   fog.scroll_y = oy
   @fogs[index] = fog
 end
 
 def remove_fog(index)
   if (@fogs[index] != nil)
     @fogs[index].dispose
     @fogs[index] = nil
   end
 end
 
end

class ScrollPlane < Plane
 
 attr_accessor :scroll_x
 attr_accessor :scroll_y
 
 def initialize(viewport = nil)
   super(viewport)
   @scroll_x = 0
   @scroll_y = 0
   @real_ox  = 0
   @real_oy  = 0
 end
 
 def update
   @real_ox -= @scroll_x / 8.0
   @real_oy -= @scroll_y / 8.0
   self.ox = $game_map.display_x / 4 + @real_ox
   self.oy = $game_map.display_y / 4 + @real_oy
 end
 
 def filename(file, hue = 0)
   self.bitmap = RPG::Cache.fog(file, hue)
 end
 
end

class Interpreter
 
 def spriteset
   return $scene.spriteset if $scene.is_a?(Scene_Map)
   return nil
 end
 
 def add_fog(index, file, z = 3000, ox = 0, oy = 0, opacity = 64, zoom = 1.0, blend = 0, hue = 0)
   spriteset.add_fog(index, file, z, ox, oy, opacity, zoom, blend, hue)
 end
 
 def remove_fog(index)
   spriteset.remove_fog(index)
 end
 
 def fogs(n)
   return spriteset.fogs(n)
 end
 
end

class Scene_Map
 attr_accessor :spriteset
end



Instructions

Place above main. All script calls and needed instructions are in the script. Be sure to check out the demo for a few script call examples.


Compatibility

Not tested with SDK.
Should be compatible with anything.


Credits and Thanks


  • game_guy ~ For creating it.

  • LiTTleDRAgo ~ For the original idea.




Author's Notes

Enjoy! (Okay, probably my last public script. I just had a bit of extra time on my hands.)

Magus

SERIOUSLY!?! DUDE, If this works, YOU ARE FUCKING AWESOME. I need something like this so fucking bad that I'm using the "f" word in this post. OSHIT, *downloads*
LEVEL ME DOWN. THE ANTI-BLIZZ GROUP IS AMONG YOU... Do it for the chick below...She watches..<br />

G_G

Haha, thanks. You might wanna update it. I fixed a scrolling bug caused by a typo. :S

Magus

April 09, 2012, 06:00:16 pm #3 Last Edit: April 09, 2012, 06:05:15 pm by Magus
Quote from: game_guy on April 09, 2012, 05:22:41 pm
Haha, thanks. You might wanna update it. I fixed a scrolling bug caused by a typo. :S

*Updates*  

Edit: found something when rereading over script:  add_fox(1, "001-Fog01")     "Add_fox"   That's correct right? Or did you mean add_fog
Not too big --any user with common sense could correct this on there own xD,. *continues to review.* I have to apply this to my World boss stage :3.
LEVEL ME DOWN. THE ANTI-BLIZZ GROUP IS AMONG YOU... Do it for the chick below...She watches..<br />

G_G

April 09, 2012, 06:51:01 pm #4 Last Edit: April 09, 2012, 06:53:50 pm by game_guy
Fixed. ._. I made that same typo so many times while making this script. I guess I have some sort of fox fetish I dunno about.

Magus

Quote from: game_guy on April 09, 2012, 06:51:01 pm
Fixed. ._. I made that same typo so many times while making this script. I guess I have some sort of fox fetish I dunno about.

xD  It works and it looks pretty cool. I mixed Sandstorm, a greenish hue, and fog01 to make an eerie-looking fog. Now FOLS1R will have an entire haunted world.   I'm still trying to get the scrolling to work, unfortunately. I probably made a mistake in the script call. Here's what it looks like:

Quoteadd_fog(1, "006-Sandstorm02", 3000,24,
3, 123, 1.0, 0, 300)


and

Quoteadd_fog(2, "001-Fog01", 3000,24,
3, 123, 1.0, 0, 400)


LEVEL ME DOWN. THE ANTI-BLIZZ GROUP IS AMONG YOU... Do it for the chick below...She watches..<br />

G_G

Try this afterwards.
fog = fogs(1)
fog.scroll_x = 24
fog.scroll_y = 3


There should be no reason why its not working. :S

Sin86

April 21, 2012, 01:35:26 pm #7 Last Edit: April 21, 2012, 01:42:10 pm by Sin86
Having an issue with moving the fog. I put in this code.

add_fog(3, "clouds")
fog = fogs(3)
fogs(3).z = 4000
fog.scroll_x = 20
fog.scroll_y = 0
fog.opacity = 48
fog.zoom_x = 1.0
fog.zoom_y = 1.0
fog.blend_type = 0


The fog will show up trigged by the event. However, the event is a parallel process and I get this error unless the event is trigged by a switch, then no error. Aside from that, the fog scroll x is not moving the fog.

"Script 'Fogs' line:160 NoMethodError occurred

undefined method `add_fog' for nil:NilClass"

G_G

Don't call it in a parallel process. You only need to add the fog once. If the error persists, I'll take a look at it tonight.

Heretic86

On the topic of Fog Scripts in general, I also wrote something that I think could have been done a lot better.

I tried to simulate Clouds that were up over the Players heads instead of at Ground Level.  Its kind of an early version, but functional.  The problem I got stuck on was writing an algorythm to adjust for the Players speed.  It doesnt seem to matter the speed that the clouds scroll at, when the player steps, it seems to max out at whatever speed he goes at.  I was kind of thinking that you might consider incorporating the ability to make a Fog behave more like High Altitude Clouds into your script.

My crappy demo.
http://www.rmxpunlimited.net/forums/topic/8294-cloud-altitude-script-with-an-alpha-channel-fog-rmxp/

Yes, pumping my own crap as usual, just thinking that more experienced scripters can do better than what I did (hence calling my stuff crap), but I think I have good ideas...
Current Scripts:
Heretic's Moving Platforms

Current Demos:
Collection of Art and 100% Compatible Scripts

(Script Demos are all still available in the Collection link above.  I lost some individual demos due to a server crash.)

marjoni01

Uh sorry here if I necroposting or something  :roll:
Anyway, I can't figure out how to make the fog move...  :^_^':
Here is my setup :
add_fog(1, "002-Clouds01")
fog = fogs(1)
fog.scroll_x = 24
fog.scroll_y = 3
fog.opacity = 100
fog.zoom_x = 1.5
fog.zoom_y = 1.5


Hope you can help me  :^_^':
Sorry again and thanks in advance  :haha:
I don't have any signature....

Stray

Thank you. Should've seen this.

Quoteadd_fog(1, shades,
[3000, 0, 0, 20, 1.0, 0, 0])

Did I type in something wrong? It doesn't work. o:
I'm very grateful to you all for your great help.

G_G

Remove the square brackets [ ] and it should work. In the instructions, I put the square brackets there to show you that you don't need to add those parameters in order for the call to work.

Wecoc

May 31, 2013, 07:31:07 pm #13 Last Edit: May 31, 2013, 07:33:20 pm by Wecoc
Sorry for necroposting (again) but I think I fixed the speed issue.

#===============================================================================
# Unlimited Fogs
# Version 1.1
# Author game_guy
#-------------------------------------------------------------------------------
# Intro:
# Ever need more than one fog for a map? Maybe more than two fogs? With this
# unique script, you can have unlimited fogs on one map! And with a few
# easy script calls, you can customize every aspect of a fog at anytime!
#
# Features:
# Unlimited Fogs on Any Map
# Change Fog's properties at any time
# Easy to use script calls
#
# Instructions:
# There is nothing to configure so lets get onto the script calls!
#-------------------------------------------------------------------------------
# add_fog(index, file, [z, scroll_x, scroll_y, opacity, zoom, blend, hue])
#  index    - This is to keep track of the fogs on screen (more on this later)
#  file    - Filename for the fog
#  z        - The z index of the fog. This is used for layering. (Default: 3000)
#  scroll_x - Horizontal scrolling speed for the fog. (Default: 0)
#  scroll_y - Vertical scrolling speed for the fog. (Default: 0)
#  opacity  - Opacity level for the fog. (Default: 64)
#  zoom    - Zoom level for the fog. (Default: 1.0)
#  blend    - Blend type for the fog. (Default: 0)
#  hue      - Hue for the fog. (Default: 0)
#
#  Note: When using this script call, the parameters with default values don't
#        need to be set when calling it.
#        e.g. add_fog(1, "001-Fog01") - Works because all parameters after
#        has a default value.
# This script call simply adds a fog with the set parameters.
#-------------------------------------------------------------------------------
# remove_fog(index)
#  index - Remember the index we set in "add_fog"? Put the same number in here
#          to remove it.
#
# This script call simply removes a fog.
#-------------------------------------------------------------------------------
# fogs(index)
#  index - The index we used to create our original fog.
#
# This handy script call returns the actual fog so you can edit individual
# properties. For example:
#  fog = fogs(1)
#  fog.scroll_x = 2
#  fog.scroll_y = 2
# This grabs the fog at index "1" and sets the scroll speed for x and y.
# (See below for all the properties/methods you can use)
#-------------------------------------------------------------------------------
# Fog Properties:
# These are the following properties/methods you can use when editing
# individual fogs.
#  visible    = Whether fog is visible or not (true/false)
#  opacity    = Opacity of the fog. (0 to 255)
#  z          = Z index of the fog.
#  scroll_x  = Horizontal scroll speed.
#  scroll_y  = Vertical scroll speed.
#  zoom_x    = Horizontal zoom factor.
#  zoom_y    = Vertical zoom factor.
#  blend_type = Blend mode for fog. (0, 1, or 2)
#  filename(new_file, [hue])
#    -new_file = New fog file.
#    -hue      = Hue for new fog. (Default: 0)
#-------------------------------------------------------------------------------
# Thats about it. Due take warning that the more fogs you add, the more
# probable lag you'll run into. Adding an extra two or three shouldn't hurt too
# much though. ;)
#
# Compatibility:
# Not tested with SDK.
# Should be compatible with everything.
#
# Credits:
# game_guy ~ For making the script.
# LiTTleDRAgo ~ For the original idea.
#===============================================================================
class Spriteset_Map

  alias gg_fogs_init_spriteset_map_lat initialize
  def initialize
    @fogs = []
    gg_fogs_init_spriteset_map_lat
  end

  alias gg_fogs_update_spriteset_map_lat update
  def update
    @fogs.each {|fog| fog.update if fog != nil }
    gg_fogs_update_spriteset_map_lat
  end

  alias gg_fogs_dispose_spriteset_map_lat dispose
  def dispose
    @fogs.each {|fog| fog.dispose if fog != nil }
    gg_fogs_dispose_spriteset_map_lat
  end

  def fogs(n)
    if @fogs[n] == nil
      @fogs[n] = ScrollPlane.new(@viewport1)
    end
    return @fogs[n]
  end

  def add_fog(index, file, z = 3000, ox = 0, oy = 0, opacity = 64, zoom = 1.0, blend = 0, hue = 0)
    remove_fog(index)
    fog = ScrollPlane.new(@viewport1)
    fog.bitmap = RPG::Cache.fog(file, hue)
    fog.z = z
    fog.blend_type = blend
    fog.opacity = opacity
    fog.zoom_x = zoom
    fog.zoom_y = zoom
    fog.scroll_x = ox
    fog.scroll_y = oy
    @fogs[index] = fog
  end

  def remove_fog(index)
    if (@fogs[index] != nil)
      @fogs[index].dispose
      @fogs[index] = nil
    end
  end

end

class ScrollPlane < Plane

  attr_accessor :scroll_x
  attr_accessor :scroll_y

  def initialize(viewport = nil)
    super(viewport)
    @scroll_x = 0
    @scroll_y = 0
    @new_ox = 0
    @new_oy = 0
  end

  def update
    @new_ox -= @scroll_x
    @new_oy -= @scroll_y
    self.ox = $game_map.display_x / 4 + (@new_ox / 8.0)
    self.oy = $game_map.display_y / 4 + (@new_oy / 8.0)
  end

  def filename(file, hue = 0)
    self.bitmap = RPG::Cache.fog(file, hue)
  end

end

class Interpreter

  def spriteset
    return $scene.spriteset if $scene.is_a?(Scene_Map)
    return nil
  end

  def add_fog(index, file, z = 3000, ox = 0, oy = 0, opacity = 64, zoom = 1.0, blend = 0, hue = 0)
    spriteset.add_fog(index, file, z, ox, oy, opacity, zoom, blend, hue)
  end

  def remove_fog(index)
    spriteset.remove_fog(index)
  end

  def fogs(n)
    return spriteset.fogs(n)
  end

end

class Scene_Map
  attr_accessor :spriteset
end


Hope it works fine now.

Wecoc

Well, after a slightly more thorough testing, I have found two serious problems on the script.

The first one; fogs will disappear if you change your scene, for example if you go to the menu and back, or if you save the game and open it again.
I can't think of a quick fix to this other than a botched:
If you set in a parallel process in the map that when there's no fog just create it, it will not matter that you leave the scene or even the game.

I did a quick edit for that
#===============================================================================
# Unlimited Fogs
# Version 1.1
# Author game_guy
#-------------------------------------------------------------------------------
# Intro:
# Ever need more than one fog for a map? Maybe more than two fogs? With this
# unique script, you can have unlimited fogs on one map! And with a few
# easy script calls, you can customize every aspect of a fog at anytime!
#
# Features:
# Unlimited Fogs on Any Map
# Change Fog's properties at any time
# Easy to use script calls
#
# Instructions:
# There is nothing to configure so lets get onto the script calls!
#-------------------------------------------------------------------------------
# add_fog(index, file, [z, scroll_x, scroll_y, opacity, zoom, blend, hue])
#  index    - This is to keep track of the fogs on screen (more on this later)
#  file    - Filename for the fog
#  z        - The z index of the fog. This is used for layering. (Default: 3000)
#  scroll_x - Horizontal scrolling speed for the fog. (Default: 0)
#  scroll_y - Vertical scrolling speed for the fog. (Default: 0)
#  opacity  - Opacity level for the fog. (Default: 64)
#  zoom    - Zoom level for the fog. (Default: 1.0)
#  blend    - Blend type for the fog. (Default: 0)
#  hue      - Hue for the fog. (Default: 0)
#
#  Note: When using this script call, the parameters with default values don't
#        need to be set when calling it.
#        e.g. add_fog(1, "001-Fog01") - Works because all parameters after
#        has a default value.
# This script call simply adds a fog with the set parameters.
#-------------------------------------------------------------------------------
# remove_fog(index)
#  index - Remember the index we set in "add_fog"? Put the same number in here
#          to remove it.
#
# This script call simply removes a fog.
#-------------------------------------------------------------------------------
# fogs(index)
#  index - The index we used to create our original fog.
#
# This handy script call returns the actual fog so you can edit individual
# properties. For example:
#  fog = fogs(1)
#  fog.scroll_x = 2
#  fog.scroll_y = 2
# This grabs the fog at index "1" and sets the scroll speed for x and y.
# (See below for all the properties/methods you can use)
#-------------------------------------------------------------------------------
# Fog Properties:
# These are the following properties/methods you can use when editing
# individual fogs.
#  visible    = Whether fog is visible or not (true/false)
#  opacity    = Opacity of the fog. (0 to 255)
#  z          = Z index of the fog.
#  scroll_x  = Horizontal scroll speed.
#  scroll_y  = Vertical scroll speed.
#  zoom_x    = Horizontal zoom factor.
#  zoom_y    = Vertical zoom factor.
#  blend_type = Blend mode for fog. (0, 1, or 2)
#  filename(new_file, [hue])
#    -new_file = New fog file.
#    -hue      = Hue for new fog. (Default: 0)
#-------------------------------------------------------------------------------
# Thats about it. Due take warning that the more fogs you add, the more
# probable lag you'll run into. Adding an extra two or three shouldn't hurt too
# much though. ;)
#
# Compatibility:
# Not tested with SDK.
# Should be compatible with everything.
#
# Credits:
# game_guy ~ For making the script.
# LiTTleDRAgo ~ For the original idea.
#===============================================================================
class Spriteset_Map

  alias gg_fogs_init_spriteset_map_lat initialize
  def initialize
    @fogs = []
    gg_fogs_init_spriteset_map_lat
  end

  alias gg_fogs_update_spriteset_map_lat update
  def update
    @fogs.each {|fog| fog.update if fog != nil }
    gg_fogs_update_spriteset_map_lat
  end

  alias gg_fogs_dispose_spriteset_map_lat dispose
  def dispose
    @fogs.each {|fog| fog.dispose if fog != nil }
    gg_fogs_dispose_spriteset_map_lat
  end

  def fog_data
    return @fogs
  end

  def fogs(n)
    if @fogs[n] == nil
      @fogs[n] = ScrollPlane.new(@viewport1)
    end
    return @fogs[n]
  end

  def add_fog(index, file, z = 3000, ox = 0, oy = 0, opacity = 64, zoom = 1.0, blend = 0, hue = 0)
    remove_fog(index)
    fog = ScrollPlane.new(@viewport1)
    fog.bitmap = RPG::Cache.fog(file, hue)
    fog.z = z
    fog.blend_type = blend
    fog.opacity = opacity
    fog.zoom_x = zoom
    fog.zoom_y = zoom
    fog.scroll_x = ox
    fog.scroll_y = oy
    @fogs[index] = fog
  end

  def remove_fog(index)
    if (@fogs[index] != nil)
      @fogs[index].dispose
      @fogs[index] = nil
    end
  end

end

class ScrollPlane < Plane

  attr_accessor :scroll_x
  attr_accessor :scroll_y

  def initialize(viewport = nil)
    super(viewport)
    @scroll_x = 0
    @scroll_y = 0
    @new_ox = 0
    @new_oy = 0
  end

  def update
    @new_ox -= @scroll_x
    @new_oy -= @scroll_y
    self.ox = $game_map.display_x / 4 + (@new_ox / 8.0)
    self.oy = $game_map.display_y / 4 + (@new_oy / 8.0)
  end

  def filename(file, hue = 0)
    self.bitmap = RPG::Cache.fog(file, hue)
  end

end

class Interpreter

  def spriteset
    return $scene.spriteset if $scene.is_a?(Scene_Map)
    return nil
  end

  def add_fog(index, file, z = 3000, ox = 0, oy = 0, opacity = 64, zoom = 1.0, blend = 0, hue = 0)
    spriteset.add_fog(index, file, z, ox, oy, opacity, zoom, blend, hue)
  end

  def remove_fog(index)
    spriteset.remove_fog(index)
  end
   
  def fogs(n)
    return spriteset.fogs(n)
  end

end

class Scene_Map
  attr_accessor :spriteset
end


And on the parallel process:
if $scene.is_a?(Scene_Map) and
$scene.spriteset.fog_data == []
  add_fog(1, "002-Clouds01",
  3000, 24, 3, 100, 1.5, 0, 0)
end


The second problem; normal fogs are displayed before the screen transition, but not this new fogs, and you will always see it cut at start. I don't know the way to fix that, and it can be disturbing.
Sorry for posting so much here after this long time.

G_G

It's fine. I dunno when I'll have time to look at this (probably within a couple of weeks) but I'll look into the issues and try to go about this a better way.

exile360

Lol, I actually never noticed these issues and I've been using this for a while. I always thought something was odd whenever I went to the menu, but didn't connect the dots. Thanks for the fix!
About the cutting; I use ATES and the day/night tint cuts as well, plus normal fades don't seem to work so it's all terribly obvious. I fixed this by simply putting a screen flash before every teleport command. Creates a nice smooth transition (although I'm not sure why since flash is usually instant?) and masks the cutting from the fogs and ATES.

LiTTleDRAgo

for fog disappear problem

Spoiler: ShowHide
#===============================================================================
# Unlimited Fogs
# Version 1.1
# Author game_guy
#-------------------------------------------------------------------------------
# Intro:
# Ever need more than one fog for a map? Maybe more than two fogs? With this
# unique script, you can have unlimited fogs on one map! And with a few
# easy script calls, you can customize every aspect of a fog at anytime!
#
# Features:
# Unlimited Fogs on Any Map
# Change Fog's properties at any time
# Easy to use script calls
#
# Instructions:
# There is nothing to configure so lets get onto the script calls!
#-------------------------------------------------------------------------------
# add_fog(index, file, [z, scroll_x, scroll_y, opacity, zoom, blend, hue])
#  index    - This is to keep track of the fogs on screen (more on this later)
#  file    - Filename for the fog
#  z        - The z index of the fog. This is used for layering. (Default: 3000)
#  scroll_x - Horizontal scrolling speed for the fog. (Default: 0)
#  scroll_y - Vertical scrolling speed for the fog. (Default: 0)
#  opacity  - Opacity level for the fog. (Default: 64)
#  zoom    - Zoom level for the fog. (Default: 1.0)
#  blend    - Blend type for the fog. (Default: 0)
#  hue      - Hue for the fog. (Default: 0)
#
#  Note: When using this script call, the parameters with default values don't
#        need to be set when calling it.
#        e.g. add_fog(1, "001-Fog01") - Works because all parameters after
#        has a default value.
# This script call simply adds a fog with the set parameters.
#-------------------------------------------------------------------------------
# remove_fog(index)
#  index - Remember the index we set in "add_fog"? Put the same number in here
#          to remove it.
#
# This script call simply removes a fog.
#-------------------------------------------------------------------------------
# fogs(index)
#  index - The index we used to create our original fog.
#
# This handy script call returns the actual fog so you can edit individual
# properties. For example:
#  fog = fogs(1)
#  fog.scroll_x = 2
#  fog.scroll_y = 2
# This grabs the fog at index "1" and sets the scroll speed for x and y.
# (See below for all the properties/methods you can use)
#-------------------------------------------------------------------------------
# Fog Properties:
# These are the following properties/methods you can use when editing
# individual fogs.
#  visible    = Whether fog is visible or not (true/false)
#  opacity    = Opacity of the fog. (0 to 255)
#  z          = Z index of the fog.
#  scroll_x  = Horizontal scroll speed.
#  scroll_y  = Vertical scroll speed.
#  zoom_x    = Horizontal zoom factor.
#  zoom_y    = Vertical zoom factor.
#  blend_type = Blend mode for fog. (0, 1, or 2)
#  filename(new_file, [hue])
#    -new_file = New fog file.
#    -hue      = Hue for new fog. (Default: 0)
#-------------------------------------------------------------------------------
# Thats about it. Due take warning that the more fogs you add, the more
# probable lag you'll run into. Adding an extra two or three shouldn't hurt too
# much though. ;)
#
# Compatibility:
# Not tested with SDK.
# Should be compatible with everything.
#
# Credits:
# game_guy ~ For making the script.
# LiTTleDRAgo ~ For the original idea.
#===============================================================================
class Spriteset_Map
 
  alias gg_fogs_update_spriteset_map_lat update
  def update
    fog_data.compact.each {|fog| fog.update }
    gg_fogs_update_spriteset_map_lat
  end

  alias gg_fogs_dispose_spriteset_map_lat dispose
  def dispose
    fog_data.each_with_index {|fog,i|  next if fog.nil?
        instance_fogs[i][9..10] = [fog.new_ox,fog.new_oy] if instance_fogs[i]
        fog.dispose }
    gg_fogs_dispose_spriteset_map_lat
  end

  def fog_data
    instance_fogs.each_pair { |k,fog| fog ? add_fog(*fog) : '' } if @fogs.nil?
    return @fogs || []
  end

  def fogs(n)
    @fogs[n] = ScrollPlane.new(@viewport1) if @fogs[n] == nil
    return @fogs[n]
  end

  def add_fog(index, file='', z = 3000, ox = 0, oy = 0, opacity = 64,
              zoom = 1.0, blend = 0, hue = 0, new_ox = 0, new_oy = 0)
    remove_fog(index)
    fog = ScrollPlane.new(@viewport1)
    fog.bitmap = RPG::Cache.fog(file, hue)
    fog.z = z
    fog.blend_type = blend
    fog.opacity = opacity
    fog.zoom_x = zoom
    fog.zoom_y = zoom
    fog.scroll_x = ox
    fog.scroll_y = oy
    fog.new_ox = new_ox
    fog.new_oy = new_oy
    @fogs = [] if @fogs.nil?
    @fogs[index] = fog
    instance_fogs[index] = [index,file, z, ox, oy , opacity, zoom, blend, hue]
  end

  def instance_fogs
    map_id = $game_map.map_id
    $game_map.class.send(:attr_accessor, :fogs)
    $game_map.fogs         = {} if $game_map.fogs.nil?
    $game_map.fogs[map_id] = {} if $game_map.fogs[map_id].nil?
    return $game_map.fogs[map_id]
  end
 
  def remove_fog(index)
    if !@fogs.nil? && !@fogs[index].nil?
      instance_fogs[index] = nil
      @fogs[index].dispose
      @fogs[index] = nil
    end
  end

end

class ScrollPlane < Plane

  attr_accessor :scroll_x, :scroll_y, :new_ox, :new_oy

  def initialize(viewport = nil)
    super(viewport)
  end

  def update
    @new_ox = (@new_ox||0) - (@scroll_x||0)
    @new_oy = (@new_oy||0) - (@scroll_y||0)
    self.ox = $game_map.display_x / 4 + (@new_ox / 8.0)
    self.oy = $game_map.display_y / 4 + (@new_oy / 8.0)
  end

  def filename(file, hue = 0)
    self.bitmap = RPG::Cache.fog(file, hue)
  end

end

class Interpreter

  def spriteset
    $scene.instance_variable_get(:@spriteset)
  end

  def add_fog(*args)
    spriteset.add_fog(*args) if !spriteset.nil?
  end

  def remove_fog(*args)
    spriteset.remove_fog(*args) if !spriteset.nil?
  end
   
  def fogs(*args)
    spriteset.fogs(*args) if !spriteset.nil?
  end

end

exile360

Drago, essentially your fix works, but for some reason it seems to reset all the parameters of the fog(s) and reverting them to default when returning from a different scene.

G_G

Okay, I have some time today and tomorrow to work on things. I think I'm going to completely redo this script.

exile360

Sounds great, good luck with it. :3 Asking just in case - could you please try to retain compatibility with Heretic's Cloud Altitude? The reason I use this script is because I want clouds AND fogs. :P

Heretic86

Quote from: exile360 on June 17, 2013, 06:09:25 am
Sounds great, good luck with it. :3 Asking just in case - could you please try to retain compatibility with Heretic's Cloud Altitude? The reason I use this script is because I want clouds AND fogs. :P


Since the author of this script hasnt replied to this request given the time that has passed since this request, I'll make an effort to update my script to include the option for Multiple Fogs.  I've thought of some changes that need to be made to it, so I'll probably get to it this weekend.
Current Scripts:
Heretic's Moving Platforms

Current Demos:
Collection of Art and 100% Compatible Scripts

(Script Demos are all still available in the Collection link above.  I lost some individual demos due to a server crash.)

G_G

There. I'm a complete idiot. I completely fixed the scrolling issue now and it works as it should lol.

Heretic86

Minor Request.

Im making Cloud Altitude compatible with this script.  But I need for you to throw in two custom definitions so I can make Cloud Altitude work with Unlimited Fogs.

class Spriteset_Map
  def fogs?(n)
    return false if @fogs[n] == nil
    return true
  end
end
class Interpreter
  def fogs?(n)
    return spriteset.fogs?(n)
  end
end


New versions of the scripts should be out soon.
Current Scripts:
Heretic's Moving Platforms

Current Demos:
Collection of Art and 100% Compatible Scripts

(Script Demos are all still available in the Collection link above.  I lost some individual demos due to a server crash.)

G_G

It'll have to wait, I'm almost done with the new version.

Heretic86

Take your time and do it right.  I find that a lot of the mistakes I make are when I rush myself because of some pressure someone else puts on me.
Current Scripts:
Heretic's Moving Platforms

Current Demos:
Collection of Art and 100% Compatible Scripts

(Script Demos are all still available in the Collection link above.  I lost some individual demos due to a server crash.)