Dynamic Weather and Time System

Dynamic Weather and Time SystemVersion: 1.0
By: ThallionDarkshine

Introduction

When the game starts, the weather system picks a random time of day. The screen tone changes as time passes, with each minute taking a certain amount of seconds specified in configuration. After a random amount of time, the weather changes, either to normal, rain, storm, snow, fog, or clouds. The storm includes random lightning as well.

Features
  • Specify if a map is indoors by placing (in) in the map name
  • Completely dynamic weather with user-defined varience and base time between switching of weather
  • Screen tint changes with time of day

Screenshots



Demo

Demo

https://rapidshare.com/files/2898565759/Weather_Demo.exe

Script

script Spoiler
  1. module Weather_Config
  2.   # Config
  3.  
  4.   WEATHER_VARIENCE = 520
  5.   WEATHER_BASE = 200
  6.   RANDOM_WEATHER = true
  7.   MIN_EQUIV = 1/40
  8. end
  9.  
  10. class Weather
  11.   attr_accessor :varience
  12.   attr_accessor :base
  13.   attr_accessor :rand_weather
  14.   attr_accessor :min_equiv
  15.  
  16.   def initialize
  17.     @varience = Weather_Config::WEATHER_VARIENCE
  18.     @base = Weather_Config::WEATHER_BASE
  19.     @rand_weather = Weather_Config::RANDOM_WEATHER
  20.     @min_equiv = Weather_Config::MIN_EQUIV
  21.     @counter = [0, 0]
  22.     @time = rand(24) * 60
  23.     @wthr = 0
  24.     hour = @time / 60
  25.     if hour > 13
  26.       change = hour - 14
  27.     else
  28.       change = 12 - hour
  29.     end
  30.     red = change * -9
  31.     green = change * -9
  32.     blue = change * -9
  33.     gray = change * 12
  34.     $game_screen.start_tone_change(Tone.new(red, green, blue, gray), 0)
  35.     @weather_change = rand(@varience) + @base
  36.     @red = red
  37.     @green = green
  38.     @blue = blue
  39.     @s_hour = hour
  40.     @s_wthr = 0
  41.   end
  42.  
  43.   def rand_weather=(bool)
  44.     @rand_weather = bool
  45.     if @rand_weather == false
  46.       $game_screen.weather(0, 0, 0)
  47.       $game_system.bgs_fade(5)
  48.       @wthr = 0
  49.       $game_map.fog_name = ""
  50.     end
  51.   end
  52.  
  53.   def update
  54.     if $game_temp.inside == true
  55.       @counter[1] = nil
  56.       $game_screen.weather(0, 0, 0)
  57.     else
  58.       @counter[1] = 0 if @counter[1] == nil
  59.     end
  60.     @counter[0] += 1
  61.     @counter[1] += 1 if @counter[1] != nil
  62.    
  63.     if @counter[0] > Graphics.frame_rate * @min_equiv
  64.       @time = (@time + 1) % (24 * 60 + 1)
  65.       @counter[0] = 0
  66.       hour = @time / 60
  67.       if hour > 13
  68.         change = hour - 14
  69.       else
  70.         change = 12 - hour
  71.       end
  72.       red = change * -9
  73.       green = change * -9
  74.       blue = change * -9
  75.       gray = change * 12
  76.       if @rand_weather == true
  77.         if @counter[1] != nil and @counter[1] > @weather_change
  78.           @lightning = false
  79.           rnd = rand(8)
  80.           case rnd
  81.             when 0
  82.               $game_screen.weather(0, 0, 60)
  83.               $game_system.bgs_fade(10)
  84.             when 1
  85.               $game_screen.weather(0, 0, 60)
  86.               $game_system.bgs_fade(10)
  87.               $game_screen.weather(1, rand(10), 200)
  88.               bgs = RPG::AudioFile.new("005-Rain01", 80, 100)
  89.               $game_system.bgs_play(bgs)
  90.             when 2
  91.               $game_screen.weather(0, 0, 60)
  92.               $game_system.bgs_fade(10)
  93.               $game_screen.weather(2, rand(10), 200)
  94.               @lightning = true
  95.               bgs = RPG::AudioFile.new("007-Rain03", 100, 100)
  96.               $game_system.bgs_play(bgs)
  97.             when 3
  98.               $game_screen.weather(0, 0, 60)
  99.               $game_system.bgs_fade(10)
  100.               $game_screen.weather(3, rand(10), 200)
  101.             when 4
  102.               unless @wthr == 4
  103.                 $game_screen.weather(0, 0, 60)
  104.                 $game_system.bgs_fade(10)
  105.                 $game_map.fog_name = "001-Fog01"
  106.                 $game_map.fog_hue = 0
  107.                 @fog_opac = rand(75) + 100
  108.                 $game_map.fog_opacity = 0
  109.                 $game_map.fog_sx = (rand(5) + 1) * 2
  110.                 $game_map.fog_sy = (rand(5) + 1) * 2
  111.               end
  112.             when 5
  113.               unless @wthr == 5
  114.                 $game_screen.weather(0, 0, 60)
  115.                 $game_system.bgs_fade(10)
  116.                 $game_map.fog_name = "002-Clouds01"
  117.                 $game_map.fog_hue = 0
  118.                 @fog_opac = rand(75) + 50
  119.                 $game_map.fog_opacity = 0
  120.                 $game_map.fog_sx = (rand(5) + 1) * 4
  121.                 $game_map.fog_sy = (rand(5) + 1) * 4
  122.               end
  123.             when 6
  124.               $game_screen.weather(0, 0, 60)
  125.               $game_system.bgs_fade(10)
  126.             when 7
  127.               $game_screen.weather(0, 0, 60)
  128.               $game_system.bgs_fade(10)
  129.           end
  130.           @wthr = rnd
  131.           @weather_change = rand(@varience) + @base
  132.           @counter[1] = 0
  133.         end
  134.         case @wthr
  135.           when 1
  136.             red -= 20
  137.             blue -= 15
  138.             green -= 20
  139.           when 2
  140.             red -= 30
  141.             blue -= 20
  142.             green -= 30
  143.           when 3
  144.             red += 5
  145.             blue += 10
  146.             green += 5
  147.           when 4
  148.             red -= 5
  149.             green -= 5
  150.             gray -= 20
  151.         end
  152.       end
  153.       if @wthr != @s_wthr or hour != @s_hour  
  154.         $game_screen.start_tone_change(Tone.new(red, green, blue, gray), 60)
  155.       end
  156.      
  157.       if (@wthr == 4 or @wthr == 5) and $game_map.fog_opacity != @fog_opac
  158.         $game_map.fog_opacity += 1
  159.       else
  160.         if $game_map.fog_name != ""
  161.           $game_map.fog_opacity -= 1
  162.           if $game_map.fog_opacity == 0
  163.             $game_map.fog_name = ""
  164.             $game_map.fog_sx = 0
  165.             $game_map.fog_sy = 0
  166.           end
  167.         end
  168.       end
  169.      
  170.       if @lightning == true
  171.         if rand(120) == 0
  172.           $game_screen.start_flash(Color.new(255, 255, 255), rand(9) + 1)
  173.         end
  174.       end
  175.     end
  176.   end
  177. end
  178.  
  179. class Scene_Map
  180.   alias dwt_orig_update update
  181.  
  182.   def update
  183.     $weather.update
  184.     dwt_orig_update
  185.   end
  186. end
  187.  
  188. class Scene_Title
  189.   alias dwt_orig_command_new_game command_new_game
  190.  
  191.   def command_new_game
  192.     dwt_orig_command_new_game
  193.     $weather = Weather.new
  194.   end
  195. end
  196.  
  197. class Game_Temp
  198.   attr_accessor :inside
  199.  
  200.   alias dwt_orig_init initialize
  201.  
  202.   def initialize
  203.     dwt_orig_init
  204.     @inside = false
  205.   end
  206. end
  207.  
  208. class Scene_Save
  209.   alias dwt_orig_write_save_data write_save_data
  210.  
  211.   def write_save_data(file)
  212.     dwt_orig_write_save_data(file)
  213.     Marshal.dump($weather, file)
  214.   end
  215. end
  216.  
  217. class Scene_Load
  218.   alias dwt_orig_read_save_data read_save_data
  219.  
  220.   def read_save_data(file)
  221.     dwt_orig_read_save_data(file)
  222.     $weather = Marshal.load(file)
  223.   end
  224. end
Expand to see the code.


Instructions

To use, place directly under main.
To turn on or off random weather (replace true with false to turn off):
  1. $weather.rand_weather = true
  2. $weather.update
Expand to see the code.

To change the varience of weather:
  1. $weather.varience =
Expand to see the code.

To change the base time between weather changes:
  1. $weather.base =
Expand to see the code.

To change the second equivalent of one minute realtime:
  1. $weather.min_equiv =
Expand to see the code.


FAQ

No questions yet.

Compatibility

I'm trying to make this compatible with MAWS (Modified Advanced Weather System), which is a rewrite of the weather module incorporating many extra weather effects.

Credits and Thanks

Right now, I am using a rewrite of MAWS in my demo, so thank you Ccoa, ForeverZer0, and Agckuu Coceg

Author's Notes

Right now, I'm trying to add in some extra weather functions to go with the dynamic weather.

Terms and Conditions

I don't care what you use it for, just don't claim that it's yours.
I'm going to bookmark this and test it out when I have the time, sounds damn nice.

Can you make characters say different things based on the weather/time this script makes?
I think so. Not sure if it's in this release, but check $weather.wthr.
this is a good little script here, well done.. only problem I have with it
is that you HAVE to put IN or whatever in the maps name, where as if
your using a script that shows ur map names it will show IN on the names
too.
I fixed that in my test project that I was using it in, so I'll put the fix in the script.

Edit: I realized that my fix edited the actual location window script, so just post the script you're using and I'll fix it.
im not actually using this script yet.. but will be wen i start my new project after the one
im wrking on atm.. the last post i made was really more of a thought that.. "if ppl were
gonna use it.. it would show the IN.. if they were using a location script".
Oh, because to take the (in) out of the name of the map, I would have to edit the map infos file, but that would change it permanently, so I would have to change the name of the map in the location script.
well.. its maybe an idea for a future updated release of this script,
if you decide ever to update it that is ^^ (tho its fine as it is as a
stand-alone weather script), maybe you could..

change from having to put (in) in the map name and maybe change
the script so all you need to do is put an "event" on inside maps with
a comment, something like, "inside", and have it set to run as a..
parallel or auto event continuosly running when in an inside area.

if that makes sense, anyhows... i personally think by doing this it would
make your weather script so much more user friendly and will allow people
then to be able to use your script along with "map name/location" scripts
that use the map name to show locations.

Only downside I think by doing the way I suggested would be it would require
you to put an extra event running on all inside areas you have.
As I said tho.. maybe its something you could add in a future release if your
bored one day and got time to change ur script for an update, but as stated
before its an awesome script.

well done ^^

Original thread: https://www.hbgames.org/forums/viewtopic.php?t=76611