Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

[VX] Fogs

i have a idea how to fix it:
if you teleport, check if you on the same map, if not set the fog.

PS: answer my question please
 
I'm still relatively new to RGSS2 but I'm trying to set up a condition switch to enable/disable the fogs, because I am using Kylock's day/night script.

I tried putting a:

"if $game_switches[6] == true"
or
"when $game_switches[6]"

under module, but I'm getting strange errors and I don't know Ruby enough to get through this.  Any help is much appreciated.
 
MukanshinBlack":1fm7rg2b said:
I'm still relatively new to RGSS2 but I'm trying to set up a condition switch to enable/disable the fogs, because I am using Kylock's day/night script.

I tried putting a:

"if $game_switches[6] == true"
or
"when $game_switches[6]"

under module, but I'm getting strange errors and I don't know Ruby enough to get through this.  Any help is much appreciated.

Tell me if this works.

Code:
#==============================================================================
# ** RMXP Fog feature for RMVX
#------------------------------------------------------------------------------
# Allows you to display a fog on map. Brings back the "old" Fog feature from 
# RPG Maker XP.
# 08-03-2008 (dd-mm-yyyy) © Hevendor of rmxp.org
# 09-03-2008 Edits/additions by Jirbytaylor
# 09-03-2008 (dd-mm-yyyy) Edited by Hevendor
# 30-05-2008 (dd-mm-yyyy) Edited by Hevendor
# Version 1.3
# Latest update: added fog diasbling switch.
#==============================================================================

module Fog_Map_Settings
  #============================================================================
  # * Configure map names for setup timesaving. Format:
  # {fognumber => 'fogname.extension', ...}
  #============================================================================
  Fog_names = {1 => 'fog01.png', 2 => 'fog01.png', 3 => 'fog01.png',
  4 => 'fog01.png'}
  #============================================================================
  # * Set maps you wish to have fogs here. Format:
  # Fog_maps = {mapID => Fog number, mapID2 => Fog number, ...}
  #============================================================================
  Fog_maps = {11 => 1, 3 => 2, 7 => 1, 16 => 2, 17 => 2, 18 => 2, 19 => 2,
  23 => 3, 25 => 4}
  #============================================================================
  # * Set up fog settings. Uses (fog number => setting, ...) format
  # - Opacity - Opacity of fog, ranging from 0 (invisible) to 255 (opaque)
  # - Zoom - size of fog. '1' is normal not '100'.
  # - Blend - 0 - Normal, 1 - Add, 2 - Subtract
  # - SxSy - Scroll settings. (fog number => [sx,sy] ...)
  #============================================================================
  Fog_opacity = {1 => 90, 2 => 60, 3 => 60, 4 => 20}
  Fog_zoom = {1 => 3, 2 => 3, 3 => 3, 4 => 3}
  Fog_blend = {1 => 2, 2 => 2, 3 => 2, 4 => 1}
  Fog_sxsy = {1 => [4, 4], 2 => [4, 4], 3 => [0, 0], 4 => [4, 4]}
  #============================================================================
  # * A switch number. When off, fogs will display; when on, fogs
  # will not display. Nil by default.
  #============================================================================
  Fog_disabling_switch = 6
  #============================================================================  
end

class Game_Map
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_reader :map_id                     # map ID
  attr_reader :fog_ox                     # fog oX
  attr_reader :fog_oy                     # fog oY
  attr_accessor :fog_over_pictures        # does fog go over pictures?
  #--------------------------------------------------------------------------
  # * Alias Definitions
  #--------------------------------------------------------------------------
  alias hev_fog_feature_map_update update
  alias hev_fog_feature_map_initialize initialize
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    @fog_ox = 0
    @fog_oy = 0
    @fog_over_pictures = false
    hev_fog_feature_map_initialize
  end
  #--------------------------------------------------------------------------
  # * Update Fog
  #--------------------------------------------------------------------------   
  def update_fog
    if Fog_Map_Settings::Fog_maps.include?($game_map.map_id)
      @fog_ox -= Fog_Map_Settings::Fog_sxsy[Fog_Map_Settings::Fog_maps[@map_id]][0] / 8.0
      @fog_oy -= Fog_Map_Settings::Fog_sxsy[Fog_Map_Settings::Fog_maps[@map_id]][1] / 8.0
    end
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #-------------------------------------------------------------------------- 
  def update
    update_fog if (Fog_Map_Settings::Fog_disabling_switch == nil || $game_switches[Fog_Map_Settings::Fog_disabling_switch] == false)
    hev_fog_feature_map_update
  end
end

class Spriteset_Map
  #--------------------------------------------------------------------------
  # * Alias Definitions
  #--------------------------------------------------------------------------
  alias hev_fog_feature_initialize initialize
  alias hev_fog_feature_create_viewports create_viewports
  alias hev_fog_feature_dispose dispose
  alias hev_fog_feature_update_viewports update_viewports
  alias hev_fog_feature_update update
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    hev_fog_feature_initialize
    @fog_removal = nil
    create_fog if (Fog_Map_Settings::Fog_disabling_switch == nil || $game_switches[Fog_Map_Settings::Fog_disabling_switch] == false)
  end
  #--------------------------------------------------------------------------
  # * Create Viewport
  #--------------------------------------------------------------------------
  def create_viewports
    @viewport4 = Viewport.new(0, 0, 544, 416)
    if @fog_over_pictures == false
      @viewport4.z = 9
    else
      @viewport4.z = 501
    end
    hev_fog_feature_create_viewports
  end
  #--------------------------------------------------------------------------
  # * Create Fog
  #-------------------------------------------------------------------------- 
  def create_fog
    @fog_removal = false
    @fog = Plane.new(@viewport4)
    if Fog_Map_Settings::Fog_maps.include?($game_map.map_id)
      fog_number = Fog_Map_Settings::Fog_maps[$game_map.map_id]
      update_fog
      @fog.bitmap = Cache.picture(Fog_Map_Settings::Fog_names[fog_number]) 
      @fog.opacity = Fog_Map_Settings::Fog_opacity[fog_number]
      @fog.zoom_x = @fog.zoom_y = Fog_Map_Settings::Fog_zoom[fog_number]
      @fog.blend_type = Fog_Map_Settings::Fog_blend[fog_number]
    end
  end
  #--------------------------------------------------------------------------
  # * Update Fog Sprite
  #--------------------------------------------------------------------------
  def update_fog
    if @fog != nil
      @fog.ox = $game_map.display_x / 8 + $game_map.fog_ox
      @fog.oy = $game_map.display_y / 8 + $game_map.fog_oy
    end
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    hev_fog_feature_update
    if @fog_removal == true && $game_switches[Fog_Map_Settings::Fog_disabling_switch] == false
      create_fog
      @fog_removal = false
    end
    update_fog if (Fog_Map_Settings::Fog_disabling_switch == nil || $game_switches[Fog_Map_Settings::Fog_disabling_switch] == false)
    if @fog_removal == false && $game_switches[Fog_Map_Settings::Fog_disabling_switch] == true
      dispose_fog if @fog != nil
      @fog_removal = true
    end
  end
  #--------------------------------------------------------------------------
  # * Dispose of Fog Sprite
  #--------------------------------------------------------------------------
  def dispose_fog
    @fog.dispose
  end
  #--------------------------------------------------------------------------
  # * Dispose
  #--------------------------------------------------------------------------
  def dispose
    dispose_fog
    hev_fog_feature_dispose
  end
end

You can turn on a switch to disable the fog. Set the switch in the fog settings.
 
Got an error:

line 168: NoMethodError occurred
undefined method 'dispose' for nil:NilClass

I'm guessing this is because the step above it was skipped so there is nothing to dispose but what would I know...
 
Damn, thought I was specific but guess I wasn't. >,<

line 168 of the updated Fog Feature script.  I got it when I was exiting the Menu.
I am using Ring Menu script, but after I commented (=begin,=end) that script out, I didn't get the same error the first time, but after going in and out of the menu 2-3 times I started to get the exact same error.
 
Update to my error:

By editing the script, I no longer get that error I was getting.

  def dispose_fog
    @fog.dispose if @fog != nil
  end

I included "if @fog != nil" and it's sort of working now.  Only problem at the moment is that when I bring up the main menu when @fog==nil, and make the Fog_disabling_switch=false, it does not re-create the fog.  This ONLY happens when I open the menu with the switch on.  If I do not open the menu with the disabling switch on, it works perfectly.

I am currently trying to figure this out, but since I'm new to ruby I won't get too far.  Any help is appreciated.  And thanks for what you've done so far, Hevendor. ^_^

EDIT:  Woot! I was able to solve the problem.  I changed:
"
  def initialize
    hev_fog_feature_initialize
    @fog_removal = nil
    create_fog if (Fog_Map_Settings::Fog_disabling_switch == nil || $game_switches[Fog_Map_Settings::Fog_disabling_switch] == false)
  end
"

into

"
  def initialize
    hev_fog_feature_initialize
    @fog_removal = nil
    create_fog
  end
"

My guess is because while it was nil, after entering and leaving the menu...  It froze the create_fog process?
Nevermind, I don't know... :P
 

Mean1

Member

I got an error saying
Line 118: typeError occured nil can't be coerced into fixnum
It says this right as soon as the game starts. (after selecting a new game or continue). I have no clue how to fix this. I love scripting and all but I dont know how to fix them
 
That was an oversight on my part, change the fog disabling switch to a number and it will work fine. I did set it to nil by default and didn't realize it can't actually be nil.
 

Mean1

Member

unless I have another version of this, this is where the error is found
#--------------------------------------------------------------------------
  # * Update Fog Sprite
  #--------------------------------------------------------------------------
  def update_fog
    if @fog != nil
           @fog.ox = $game_map.display_x / 8 + $game_map.fog_ox                    
           @fog.oy = $game_map.display_y / 8 + $game_map.fog_oy

that is where the error occurs. Is that really a switch??? (and I thought scripting was easy I see why ever one like events)
Oh and on a minor note when I choose a new game and play through the error doesnt appear but the fog isnt there as well. All most as if the script wasnt even there.
 
Script version... along with exactly what were you doing when the error ocurred, and so forth. At the moment, I have no flipping idea what your problem is.
 

Mean1

Member

It just says "Latest update" you posted it up March 9th. I about chose the one you first posted but you said you updated it so I chose that one instead.it basically states what Im doing a few replys up. I press continue and the error comes up immediatley. I dont get to do anything. But when I start a new game it plays fine untill I reach the part where the fog is suppossed to be and there is no fog. I have no clue what is going on there that it has an error on continuing but doesnt on a new game
 
Sorry if this is a stupid question... but why won't my fog show up... I assigned the fog number to my mapID and it won't show up when I test play it. My fog picture is in my "picture folder". Heres my settings right now:

  #============================================================================
  # * Configure Fog numbers -> names for setup timesaving. Format:
  # {fognumber => 'fogname.extension', ...}
  # where 'Fogname.extension' must be the name of a fog picture and its extension
  # located in the pictures folder
  #============================================================================
  Fog_names = {01 => 'mistfog.png'}
    #============================================================================
  # * Set maps you wish to have fogs here. Format:
  # Fog_maps = {mapID => Fog number, mapID2 => Fog number, ...}
  #============================================================================
  Fog_maps = {'TestMapIntroWM' => 01}
  #============================================================================
  # * Set up fog settings. Uses (fog number => setting, ...) format
  # - Opacity - Opacity of fog, ranging from 0 (invisible) to 255 (opaque)
  # - Zoom - size of fog. '1' is normal not '100'.
  # - Blend - 0 - Normal, 1 - Add, 2 - Subtract
  # - SxSy - Scroll settings. (fog number => [sx,sy] ...)
  #============================================================================
  Fog_opacity = {01 => 255}
  Fog_zoom = {01 => 3}
  Fog_blend = {01 => 2}
  Fog_sxsy = {01 => [2, 0]}

If I'm doing anything wrong I'd really appreciate the help.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top