KWeatherArea VX + ACE
#1
KWeatherArea VX + ACE

by Kyonides

Introduction

Did you ever want to set a custom weather effect depending on a given area on the current map?
Now you can do it in RMVX & RMVX ACE! Grinning

NOTES
  • This scriptlet uses script calls to make that happen. Winking
  • Here an area is synonymous with a rectangle.
  • You can add and remove areas.
  • These custom areas are NOT related to RM's map areas.
  • Removing an active weather area reverts the effects to the last effect you've set via Set Weather Effects event command.
  • If you change the weather in battle, it will revert it to the current area's weather, if any.
  • Please Book read the embedded notes to learn how to use it properly.

VX Script

Code:
# * KWeatherArea VX * #
#   Scripter : Kyonides
#   v1.2.0 - 2025-03-25

# This scriptlet allows you to set regional weather effects on the current map.
# It works as usual. If you enter an area, the rain or snow will soon appear.
# Obviously, it will quickly vanish once you leave that area.

# If you ever remove an active weather area, it will revert the weather to
# the last effect set via weather effects event command if any.

# * Script Call * #

# - Add a Regional Weather Area
# - Step #1
#   Create 2 local variables: Use integers only, i.e. 1, 16 or 25.
#   W stands for Width or how wide this rectangle is supposed to be.
#   H stands for Height or how tall this rectangle is supposed to be.
# area = [X, Y, W, H]
# gm = $game_map

#   Example:
# area = [7, 10, 4, 6]
# gm = $game_map

# - Step #2
#   Use this call now:
#   - AreaID is an integer, 1+.
#   - Type is one of the RM's weather types: 1 being rain, 2 storm & 3 snow.
# gm.add_weather_area(AreaID, Type, area)
#   Example:
# gm.add_weather_area(1, 1, area)

# - Remove a Regional Weather Area (Temporarily?)
#   - AreaID is an integer, 1+.
# $game_map.remove_weather_area(AreaID)

class WeatherArea
  def initialize
    @id = 0
    @type = 0
    @area = Rect.new(0, 0, 0, 0)
  end

  def set_rect(*coords)
    coords = coords.flatten
    @area.x = coords.shift
    @area.y = coords.shift
    @area.width = coords.shift
    @area.height = coords.shift
  end

  def inside?(px, py)
    w = @area.x + @area.width - 1
    h = @area.y + @area.height - 1
    px.between?(@area.x, w) and py.between?(@area.y, h)
  end
  attr_accessor :id, :type, :area
end

class Game_Screen
  def change_weather(type, max)
    @weather_type = type
    @weather_max = (max + 1) * 4.0
    @weather_duration = 0
  end

  def previous_weather
    @weather_type = @weather_type_target
    @weather_max = @weather_max_target
    @weather_duration = 0
  end
end

class Game_Map
  alias :kyon_weather_area_gm_map_init :initialize
  alias :kyon_weather_area_gm_map_stp :setup
  alias :kyon_weather_area_gm_map_up :update
  def initialize
    kyon_weather_area_gm_map_init
    init_weather
  end

  def init_weather
    @weather_map_areas = {}
    @weather_area_id = 0
  end

  def setup(map_id)
    kyon_weather_area_gm_map_stp(map_id)
    load_weather_areas
  end

  def load_weather_areas
    @weather_areas = @weather_map_areas[@map_id] || {}
  end

  def add_weather_area(area_id, new_type, *coords)
    area = WeatherArea.new
    area.id = area_id
    area.type = new_type
    area.set_rect(*coords)
    areas = @weather_map_areas[@map_id] ||= {}
    areas[area_id] = area
    @weather_areas = areas
  end

  def remove_weather_area(area_id)
    @weather_areas.delete(area_id)
    return if @weather_area_id != area_id
    reset_weather
  end

  def reset_weather
    @screen.previous_weather
    @weather_area_id = 0
  end

  def update
    kyon_weather_area_gm_map_up
    update_weather_areas
  end

  def update_weather_areas
    return if @weather_areas.empty?
    px, py = $game_player.xy
    return if @weather_x == px and @weather_y == py
    @weather_x = px
    @weather_y = py
    new_area = @weather_areas.find {|key, val| val.inside?(px, py) }
    unless new_area
      reset_weather
      return
    end
    return if @weather_area_id == new_area[0]
    @weather_area_id, area = new_area
    @screen.change_weather(area.type, 10)
  end

  def aftermath_weather_area
    if @weather_area_id == 0
      reset_weather
    else
      area = @weather_areas[@weather_area_id]
      @screen.change_weather(area.type, 10)
    end
  end
end

class Game_Player
  def xy
    [@x, @y]
  end
end

class Spriteset_Battle
  alias :kyon_weather_area_sprtst_btl_crt_pix :create_pictures
  alias :kyon_weather_area_sprtst_btl_up_pix :update_pictures
  alias :kyon_weather_area_sprtst_btl_disp :dispose
  def create_pictures
    create_weather
    kyon_weather_area_sprtst_btl_crt_pix
  end

  def create_weather
    @weather = Spriteset_Weather.new(@viewport2)
    update_weather
  end

  def update_weather
    @weather.type = $game_map.screen.weather_type
    @weather.max = $game_map.screen.weather_max
    @weather.ox = $game_map.display_x / 8
    @weather.oy = $game_map.display_y / 8
    @weather.update
  end

  def update_pictures
    kyon_weather_area_sprtst_btl_up_pix
    update_weather
  end

  def dispose
    @weather.dispose
    kyon_weather_area_sprtst_btl_disp
  end
end

class Scene_Battle
  alias :kyon_weather_area_scn_btl_end :battle_end
  def battle_end(result)
    $game_map.aftermath_weather_area
    kyon_weather_area_scn_btl_end(result)
  end
end

VX ACE Script

Code:
# * KWeatherArea ACE * #
#   Scripter : Kyonides
#   v1.2.0 - 2025-03-23

# This scriptlet allows you to set regional weather effects on the current map.
# It works as usual. If you enter an area, the rain or snow will soon appear.
# Obviously, it will quickly vanish once you leave that area.

# If you ever remove an active weather area, it will revert the weather to
# the last effect set via weather effects event command if any.

# * Script Call * #

# - Add a Regional Weather Area
# - Step #1
#   Create 1 local variable: Use integers only, i.e. 1, 16 or 25.
#   W stands for Width or how wide this rectangle is supposed to be.
#   H stands for Height or how tall this rectangle is supposed to be.
# area = [X, Y, W, H]
#   Example:
# area = [7, 10, 4, 6]

# - Step #2
#   Use this call now:
#   - AreaID is an integer, 1+.
#   - Type is one of the RM's weather types: :none, :rain, :storm & :snow
# $game_map.add_weather_area(AreaID, Type, area)
#   Example:
# $game_map.add_weather_area(1, :rain, area)

# - Remove a Regional Weather Area (Temporarily?)
#   - AreaID is an integer, 1+.
# $game_map.remove_weather_area(AreaID)

class WeatherArea
  def initialize
    @id = 0
    @type = 0
    @area = Rect.new(0, 0, 0, 0)
  end

  def set_rect(*coords)
    coords = coords.flatten
    @area.x = coords.shift
    @area.y = coords.shift
    @area.width = coords.shift
    @area.height = coords.shift
  end

  def inside?(px, py)
    w = @area.x + @area.width - 1
    h = @area.y + @area.height - 1
    px.between?(@area.x, w) and py.between?(@area.y, h)
  end
  attr_accessor :id, :type, :area
end

class << BattleManager
  alias :kyon_weather_area_scn_btl_end :battle_end
  def battle_end(result)
    $game_map.aftermath_weather_area
    kyon_weather_area_scn_btl_end(result)
  end
end

class Game_Screen
  alias :kyon_weather_area_gm_scr_chng_wthr :change_weather
  def change_weather(type, power, duration)
    kyon_weather_area_gm_scr_chng_wthr(type, power, duration)
    @old_weather_type = @weather_type
  end

  def modify_weather(type, max)
    @weather_type = type
    @weather_power = max
    @weather_duration = 0
  end

  def previous_weather
    @weather_type = @old_weather_type || :none
    @weather_power_target = 0.0 if @weather_type == :none
    @weather_power = @weather_power_target
    @weather_duration = 0
  end
end

class Game_Map
  alias :kyon_weather_area_gm_map_init :initialize
  alias :kyon_weather_area_gm_map_stp :setup
  alias :kyon_weather_area_gm_map_up :update
  def initialize
    kyon_weather_area_gm_map_init
    init_weather
  end

  def init_weather
    @weather_map_areas = {}
    @weather_area_id = 0
  end

  def setup(map_id)
    kyon_weather_area_gm_map_stp(map_id)
    load_weather_areas
  end

  def load_weather_areas
    @weather_areas = @weather_map_areas[@map_id] || {}
  end

  def add_weather_area(area_id, new_type, *coords)
    area = WeatherArea.new
    area.id = area_id
    area.type = new_type
    area.set_rect(*coords)
    areas = @weather_map_areas[@map_id] ||= {}
    areas[area_id] = area
    @weather_areas = areas
  end

  def remove_weather_area(area_id)
    @weather_areas.delete(area_id)
    return if @weather_area_id != area_id
    reset_weather
  end

  def reset_weather
    @screen.previous_weather
    @weather_area_id = 0
  end

  def update(main=false)
    kyon_weather_area_gm_map_up(main)
    update_weather_areas
  end

  def update_weather_areas
    return if @weather_areas.empty?
    px, py = $game_player.xy
    return if @weather_x == px and @weather_y == py
    @weather_x = px
    @weather_y = py
    new_area = @weather_areas.find {|key, val| val.inside?(px, py) }
    unless new_area
      reset_weather
      return
    end
    return if @weather_area_id == new_area[0]
    @weather_area_id, area = new_area
    @screen.modify_weather(area.type, 9)
  end

  def aftermath_weather_area
    if @weather_area_id == 0
      reset_weather
    else
      area = @weather_areas[@weather_area_id]
      @screen.modify_weather(area.type, 9)
    end
  end
end

class Game_Player
  def xy
    [@x, @y]
  end
end

class Spriteset_Battle
  alias :kyon_weather_area_sprtst_btl_crt_pix :create_pictures
  alias :kyon_weather_area_sprtst_btl_up_pix :update_pictures
  alias :kyon_weather_area_sprtst_btl_disp :dispose
  def create_pictures
    create_weather
    kyon_weather_area_sprtst_btl_crt_pix
  end

  def create_weather
    @weather = Spriteset_Weather.new(@viewport2)
    update_weather
  end

  def update_weather
    @weather.type = $game_map.screen.weather_type
    @weather.power = $game_map.screen.weather_power
    @weather.ox = $game_map.display_x * 32
    @weather.oy = $game_map.display_y * 32
    @weather.update
  end

  def update_pictures
    kyon_weather_area_sprtst_btl_up_pix
    update_weather
  end

  def dispose
    @weather.dispose
    kyon_weather_area_sprtst_btl_disp
  end
end

Supported Engines

VX, VX ACE and HiddenChest! Two Thumbs Up! 


Terms & Conditions

Free for use in ANY game. Gamer 
Please include my nickname in your game credits.
Also mention the forum where you found it. Winking
That's it! Tongue sticking out
"For God has not destined us for wrath, but for obtaining salvation through our Lord Jesus Christ," 1 Thessalonians 5:9

Maranatha!

The Internet might be either your friend or enemy. It just depends on whether or not she has a bad hair day.

[Image: SP1-Scripter.png]
[Image: SP1-Writer.png]
[Image: SP1-Poet.png]
[Image: SP1-PixelArtist.png]
[Image: SP1-Reporter.png]

My Original Stories (available in English and Spanish)

List of Compiled Binary Executables I have published...
HiddenChest & Roole

Give me a free copy of your completed game if you include at least 3 of my scripts! Laughing + Tongue sticking out

Just some scripts I've already published on the board...
KyoGemBoost XP VX & ACE, RandomEnkounters XP, KSkillShop XP, Kolloseum States XP, KEvents XP, KScenario XP & Gosu, KyoPrizeShop XP Mangostan, Kuests XP, KyoDiscounts XP VX, ACE & MV, KChest XP VX & ACE 2016, KTelePort XP, KSkillMax XP & VX & ACE, Gem Roulette XP VX & VX Ace, KRespawnPoint XP, VX & VX Ace, GiveAway XP VX & ACE, Klearance XP VX & ACE, KUnits XP VX, ACE & Gosu 2017, KLevel XP, KRumors XP & ACE, KMonsterPals XP VX & ACE, KStatsRefill XP VX & ACE, KLotto XP VX & ACE, KItemDesc XP & VX, KPocket XP & VX, OpenChest XP VX & ACE
Reply
#2
A New Script Port

Now this scriptlet has been fully ported to RMVX ACE! Shocked

At first I thought it won't need any modification to make it run on VX ACE, but I was wrong! Incredible It needed several changes because the developers had applied a lot of changes on how the options would be processed by the Game_Screen class.

Happy with a sweat One example of this was that it no longer relies on numbers but symbols to determine the current weather effect.

They also changed an instance variable's name and removed another one. Confused

Oh and the Game_Map's update method now accepts an optional argument. Indifferent

As a side note I will mention that I was forced to change the name of my Game_Screen custom method because it already existed in VX ACE. Sad
"For God has not destined us for wrath, but for obtaining salvation through our Lord Jesus Christ," 1 Thessalonians 5:9

Maranatha!

The Internet might be either your friend or enemy. It just depends on whether or not she has a bad hair day.

[Image: SP1-Scripter.png]
[Image: SP1-Writer.png]
[Image: SP1-Poet.png]
[Image: SP1-PixelArtist.png]
[Image: SP1-Reporter.png]

My Original Stories (available in English and Spanish)

List of Compiled Binary Executables I have published...
HiddenChest & Roole

Give me a free copy of your completed game if you include at least 3 of my scripts! Laughing + Tongue sticking out

Just some scripts I've already published on the board...
KyoGemBoost XP VX & ACE, RandomEnkounters XP, KSkillShop XP, Kolloseum States XP, KEvents XP, KScenario XP & Gosu, KyoPrizeShop XP Mangostan, Kuests XP, KyoDiscounts XP VX, ACE & MV, KChest XP VX & ACE 2016, KTelePort XP, KSkillMax XP & VX & ACE, Gem Roulette XP VX & VX Ace, KRespawnPoint XP, VX & VX Ace, GiveAway XP VX & ACE, Klearance XP VX & ACE, KUnits XP VX, ACE & Gosu 2017, KLevel XP, KRumors XP & ACE, KMonsterPals XP VX & ACE, KStatsRefill XP VX & ACE, KLotto XP VX & ACE, KItemDesc XP & VX, KPocket XP & VX, OpenChest XP VX & ACE
Reply
#3
Another Script Upgrade!

Version 1.1.0 Has a New Feature!

Once the current battle has finished, the script will revert any changes you might have made to the weather effects in battle to the local area's weather settings, if there's any.

Version 1.2.0 Introduces Battle Weather Effects!

The default battle system in RMVX and RMVX ACE excluded the weather effects from battles, but this upgrade brings them back.
"For God has not destined us for wrath, but for obtaining salvation through our Lord Jesus Christ," 1 Thessalonians 5:9

Maranatha!

The Internet might be either your friend or enemy. It just depends on whether or not she has a bad hair day.

[Image: SP1-Scripter.png]
[Image: SP1-Writer.png]
[Image: SP1-Poet.png]
[Image: SP1-PixelArtist.png]
[Image: SP1-Reporter.png]

My Original Stories (available in English and Spanish)

List of Compiled Binary Executables I have published...
HiddenChest & Roole

Give me a free copy of your completed game if you include at least 3 of my scripts! Laughing + Tongue sticking out

Just some scripts I've already published on the board...
KyoGemBoost XP VX & ACE, RandomEnkounters XP, KSkillShop XP, Kolloseum States XP, KEvents XP, KScenario XP & Gosu, KyoPrizeShop XP Mangostan, Kuests XP, KyoDiscounts XP VX, ACE & MV, KChest XP VX & ACE 2016, KTelePort XP, KSkillMax XP & VX & ACE, Gem Roulette XP VX & VX Ace, KRespawnPoint XP, VX & VX Ace, GiveAway XP VX & ACE, Klearance XP VX & ACE, KUnits XP VX, ACE & Gosu 2017, KLevel XP, KRumors XP & ACE, KMonsterPals XP VX & ACE, KStatsRefill XP VX & ACE, KLotto XP VX & ACE, KItemDesc XP & VX, KPocket XP & VX, OpenChest XP VX & ACE
Reply




Users browsing this thread: 1 Guest(s)