Vlue

Basic Climate System

Aug 5th, 2012
5,922
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #Basic Climate System v2.2
  2. #----------#
  3. #Features: Provides a basic weather system that will randomly weather!
  4. #          Wooot!
  5. #
  6. #Usage:    Plug and play!
  7. #          Script calls:
  8. #           Climate::still(true/false)    #Stops weather changing
  9. #           Climate::weather              #Returns 0 for clear, 1 for rain
  10. #                                                  2 for storm, 3 for custom1
  11. #                                                  4 for custom2
  12. #        
  13. #Customization: Set below, in comments.
  14. #
  15. #----------#
  16. #-- Script by: V.M of D.T
  17. #
  18. #- Questions or comments can be:
  19. #    given by email: sumptuaryspade@live.ca
  20. #    provided on facebook: http://www.facebook.com/DaimoniousTailsGames
  21. #   All my other scripts and projects can be found here: http://daimonioustails.weebly.com/
  22. #
  23. #--- Free to use in any project, commercial or non-commercial, with credit given
  24. # - - Though a donation's always a nice way to say thank you~ (I also accept actual thank you's)
  25.  
  26. #Approximate duration of weather effects in frames.
  27. MAX_DURATION = 18000
  28.  
  29. #Chance for weather types to occur, higher numbers occure more then lower numbers
  30. SUN     = 40
  31. RAIN    = 30
  32. STORM   = 15
  33. CUSTOM1 = 0  #Custom weather effects chance, advanced
  34. CUSTOM2 = 0  #Custom weather effects chance, advanced
  35.  
  36. #Array of special maps, format of [#,#,#] (I.e. [5,6,54,780])
  37. #Maps where weather is not shown:
  38. NOWEATHERMAPS   = [2]
  39. #Maps where weather is not shown and bgs is played:
  40. INDOORSOUNDMAPS = []
  41. #Maps where it snows instead of rains:
  42. SNOWYMAPS       = []
  43.  
  44. #BGS sound effects! Prefixed with I means Indoor sound effects.
  45. #Format is ["Filename", Volume, Pitch]
  46. USE_SOUND = true
  47.  
  48. RAIN_BGS    = ["Rain",  95, 100]
  49. IRAIN_BGS   = ["Rain",  65, 100]
  50.  
  51. SNOW_BGS    = ["Rain", 0, 100]
  52. ISNOW_BGS   = ["Rain", 0, 100]
  53.  
  54. STORM_BGS   = ["Storm", 75, 100]  
  55. ISTORM_BGS  = ["Storm", 55, 100]  
  56.  
  57. BLIZZ_BGS   = ["Storm", 0, 100]  
  58. IBLIZZ_BGS  = ["Storm", 0, 100]
  59.  
  60. CUSTOM1_BGS = ["Rain",  95, 100] #Custom weather effects sounds, ADVANCED
  61. CUSTOM2_BGS = ["Rain",  95, 100] #Custom weather effects sounds, ADVANCED
  62.  
  63. #ADVANCED CUSTOMIZATION#
  64. #Have a custom Weather System like Atelier's? Now you can use that weather!
  65. #Just switch out these commands for the ones from that system, keep the quotes!
  66. CLEARCOMMAND = "$game_map.screen.change_weather(:none, 0, 0)"
  67. SUNCOMMAND = "$game_map.screen.change_weather(:none, 0, 120)"
  68. RAINCOMMAND = "$game_map.screen.change_weather(:rain, 9, 120)"
  69. SNOWCOMMAND = "$game_map.screen.change_weather(:snow, 5, 120)"
  70. STORMCOMMAND = "$game_map.screen.change_weather(:storm, 9, 120)"
  71. BLIZZCOMMAND = "$game_map.screen.change_weather(:snow, 9, 120)"
  72. CUSTOM1COMMAND = ""
  73. CUSTOM2COMMAND = ""
  74.  
  75. #Store current weather in a variable?
  76. BCL_USE_VARIABLE = false
  77. BCL_CLIMATE_VARIABLE = 1
  78.  
  79. #Have weather play in battle?
  80. AC_BATTLE_WEATHER = false
  81.  
  82. module Climate
  83.   def self.init
  84.     @current_weather = -1
  85.     @still = false
  86.     @duration = MAX_DURATION / 4
  87.     @need_refresh = false
  88.     update
  89.   end
  90.   def self.update
  91.     return if !SceneManager.scene.is_a?(Scene_Map)
  92.     return if @still
  93.     change_weather if @duration < 0
  94.     @duration -= 1
  95.     update_weather if @need_refresh
  96.   end
  97.   def self.change_weather
  98.     arrayseed = []
  99.     SUN.times { arrayseed.push(0) }
  100.     RAIN.times { arrayseed.push(1) }
  101.     STORM.times { arrayseed.push(2) }
  102.     CUSTOM1.times { arrayseed.push(3) }
  103.     CUSTOM2.times { arrayseed.push(4) }
  104.     new_weather = arrayseed[rand(arrayseed.size-1)]
  105.     sun if new_weather == 0
  106.     rain if new_weather == 1
  107.     storm if new_weather == 2
  108.     custom1 if new_weather == 3
  109.     custom2 if new_weather == 4
  110.     $game_variables[BCL_CLIMATE_VARIABLE] = @current_weather if BCL_USE_VARIABLE
  111.     @duration = MAX_DURATION * ((rand(40)+80)/100)
  112.     @duration = @duration.to_i
  113.     @need_refresh = true
  114.   end
  115.   def self.update_weather
  116.     @need_refresh = false
  117.     clear if no_weather_map
  118.     play_weather_sound if indoor_map
  119.     return if no_weather_map
  120.     sun if @current_weather == 0
  121.     rain if @current_weather == 1
  122.     storm if @current_weather == 2
  123.     custom1 if @current_weather == 3
  124.     custom2 if @current_weather == 4
  125.   end
  126.   def self.clear
  127.     $game_map.map.bgs.play
  128.     eval(CLEARCOMMAND)
  129.   end
  130.   def self.sun
  131.     @current_weather = 0
  132.     play_weather_sound
  133.     eval(SUNCOMMAND)
  134.   end
  135.   def self.rain
  136.     snow = snowy_map
  137.     @current_weather = 1
  138.     play_weather_sound
  139.     eval(RAINCOMMAND) unless snow
  140.     eval(SNOWCOMMAND) if snow
  141.   end
  142.   def self.storm
  143.     @current_weather = 2
  144.     snow = snowy_map
  145.     play_weather_sound
  146.     eval(STORMCOMMAND) unless snow
  147.     eval(BLIZZCOMMAND) if snow
  148.   end
  149.   def self.custom1
  150.     @current_weather = 3
  151.     play_weather_sound
  152.     eval(CUSTOM1COMMAND)
  153.   end
  154.   def self.custom2
  155.     @current_weather = 4
  156.     play_weather_sound
  157.     eval(CUSTOM2COMMAND)
  158.   end
  159.   def self.bgs_sound(name, volume, pitch)
  160.     @audio = RPG::BGS.new(name, volume, pitch)
  161.     @audio.play
  162.   end
  163.   def self.play_weather_sound
  164.     return unless USE_SOUND
  165.     indoor = indoor_map
  166.     snowy = snowy_map
  167.     weather = @current_weather
  168.     weather += 10 if snowy and @current_weather == 1
  169.     weather += 20 if snowy and @current_weather == 2
  170.     case weather
  171.     when 0
  172.       Audio.bgs_stop
  173.     when 1
  174.       bgs_sound(RAIN_BGS[0],RAIN_BGS[1],RAIN_BGS[2]) unless indoor
  175.       bgs_sound(IRAIN_BGS[0],IRAIN_BGS[1],IRAIN_BGS[2]) if indoor
  176.     when 2
  177.       bgs_sound(STORM_BGS[0],STORM_BGS[1],STORM_BGS[2]) unless indoor
  178.       bgs_sound(ISTORM_BGS[0],ISTORM_BGS[1],ISTORM_BGS[2]) if indoor
  179.     when 3
  180.       bgs_sound(CUSTOM1_BGS[0],CUSTOM1_BGS[1],CUSTOM1_BGS[2]) unless indoor
  181.       bgs_sound(ICUSTOM1_BGS[0],ICUSTOM1_BGS[1],ICUSTOM1_BGS[2]) if indoor
  182.     when 4
  183.       bgs_sound(CUSTOM2_BGS[0],CUSTOM2_BGS[1],CUSTOM2_BGS[2]) unless indoor
  184.       bgs_sound(ICUSTOM2_BGS[0],ICUSTOM2_BGS[1],ICUSTOM2_BGS[2]) if indoor
  185.     when 11
  186.       bgs_sound(SNOW_BGS[0],SNOW_BGS[1],SNOW_BGS[2]) unless indoor
  187.       bgs_sound(ISNOW_BGS[0],ISNOW_BGS[1],ISNOW_BGS[2]) if indoor
  188.     when 22
  189.       bgs_sound(BLIZZ_BGS[0],BLIZZ_BGS[1],BLIZZ_BGS[2]) unless indoor
  190.       bgs_sound(IBLIZZ_BGS[0],IBLIZZ_BGS[1],IBLIZZ_BGS[2]) if indoor
  191.     end
  192.   end
  193.   def self.no_weather_map
  194.     return true if NOWEATHERMAPS.include?($game_map.map_id)
  195.     return true if INDOORSOUNDMAPS.include?($game_map.map_id)
  196.     return false
  197.   end
  198.   def self.indoor_map
  199.     INDOORSOUNDMAPS.include?($game_map.map_id)
  200.   end
  201.   def self.snowy_map
  202.     SNOWYMAPS.include?($game_map.map_id)
  203.   end
  204.   def self.need_refresh
  205.     @need_refresh = true
  206.     update
  207.   end
  208.   def self.still(set)
  209.     @still = set
  210.   end
  211.   def self.weather
  212.     return @current_weather
  213.   end
  214. end
  215.  
  216. class Scene_Battle
  217.   alias basic_weather_start create_spriteset
  218.   alias basic_weather_update update_basic
  219.   alias basic_weather_dispose terminate
  220.   def create_spriteset
  221.     basic_weather_start
  222.     @weather = Spriteset_Weather.new(@spriteset.viewport3) if AC_BATTLE_WEATHER
  223.   end
  224.   def update_basic
  225.     basic_weather_update
  226.     update_weather unless @weather.nil?
  227.   end
  228.   def update_weather
  229.     @weather.type = $game_map.screen.weather_type
  230.     @weather.power = $game_map.screen.weather_power
  231.     @weather.ox = $game_map.display_x * 32
  232.     @weather.oy = $game_map.display_y * 32
  233.     @weather.update
  234.   end
  235.   def terminate
  236.     basic_weather_dispose
  237.     @weather.dispose unless @weather.nil?
  238.   end
  239. end
  240.  
  241. class Spriteset_Battle
  242.  
  243.   attr_accessor   :viewport3
  244.  
  245. end
  246.  
  247. class Game_Map
  248.   attr_accessor   :map
  249. end
  250.  
  251. class Scene_Map
  252.   alias climate_update update
  253.   alias climate_post_transfer post_transfer
  254.   def update
  255.     climate_update
  256.     Climate::update
  257.   end
  258.   def post_start
  259.     Climate::need_refresh
  260.     super
  261.   end
  262.   def post_transfer
  263.     Climate::need_refresh
  264.     climate_post_transfer
  265.   end
  266. end
  267.  
  268. Climate::init
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×