Advertisement
Wavescripts

Wave's Encounter Rate Items

Aug 23rd, 2014
348
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 9.51 KB | None | 0 0
  1. ############################################
  2. #                                          #
  3. #       ENCOUNTER RATE ITEMS SCRIPT        #
  4. #                                          #
  5. #        v1.0 for RPG Maker VX Ace         #
  6. #                                          #
  7. # Created by Jason "Wavelength" Commander  #
  8. #                                          #
  9. ############################################
  10.  
  11. # "Stop it, Wave!  Why would the player want MORE random battles?"
  12. #                            ~ Eric, after fighting off yet another 'Slime * 2'
  13.  
  14.  
  15. ############################################
  16. #                                          #
  17. #           ABOUT THIS SCRIPT              #
  18. #                                          #
  19. ############################################
  20.  
  21. # This script allows you to create items that, when used, modify the Random
  22. #      Encounter Rate for a period of time, and even allows you to create
  23. #      items that *raise* the encounter rate.  The script also allows you
  24. #      to (optionally) assign Common Events to run when the effects of one
  25. #      of these items wears off.
  26.  
  27. # Note that only one Random Encounter Rate-changing item may be in effect
  28. #      at a time.  If the player uses a Random Encounter Rate-changing item
  29. #      while another one is already active, the newly-used item's effect
  30. #      will override the old item's effect.
  31.  
  32. # The Encounter Rate multiplier from items will stack with other Encounter
  33. #      Rate modifiers that RPG Maker VX Ace normally uses (such as lower
  34. #      encounter rates while in a Ship and higher encounter rates while on
  35. #      "bush" tiles).
  36.  
  37. # It is okay to designate items that have another effect (such as restoring
  38. #      HP) as a Random Encounter Rate-changing item.  HOWEVER, note that if
  39. #      a player uses such an item while in battle, the Encounter Rate
  40. #      multiplier will not take effect - so ideally, you want the player
  41. #      using these items outside of battle.
  42.  
  43. # This script should be placed in the "Materials" section of the script
  44. #      editor.  If you are using other scripts, it's generally better to
  45. #      place this script ABOVE those other scripts.
  46.  
  47. # This script is compatible with most other scripts, even most other
  48. #      scripts that affect random encounters.
  49.  
  50. # The current (1.0) version of this script uses Global Variables, which
  51. #      violates best practices for encapsulation.  If you can help me
  52. #      rewrite this script to use only local/class variables, you'd be
  53. #      awesome. :)
  54.  
  55.  
  56. ############################################
  57. #                                          #
  58. #              TERMS OF USE                #
  59. #                                          #
  60. ############################################
  61.  
  62. #  Free to use for non-commercial projects - just credit me
  63.  
  64. #  A license is required to use this script in commercial or
  65. #       semi-commercial projects.  Please visit my website
  66. #       wavescripts.wordpress.com for more info about obtaining
  67. #       a license for my scripts.
  68.  
  69. #  You may freely share or modify this script, but you cannot
  70. #       sell it (even if modified) without my written permission
  71.  
  72. #  Please preserve the header (with version #) and terms of use;
  73. #       besides that, feel free to remove any commenting you please
  74.  
  75. module Encounter_Items
  76.  
  77. # Group your Encounter Rate-changing items into Sets based on their effects.
  78. #      If multiple items have the same Encounter Rate multiplier, Duration,
  79. #      and Common Event, you can group them into the same Encounter Item Set.
  80. #
  81. #    * EI_Item_Set_X: The Item IDs of items in Encounter Item Set X.
  82. #                     Using an Item in this Set will change the
  83. #                     encounter rate based on this Set's properties.
  84. #                     Example:  EI_Item_Set_1 = [22, 19, 25]
  85. #
  86. #    * EI_Enc_Rate_X: The Encounter Rate multiplier that this set grants.
  87. #                     For example, 0.50 means half the encounters you'd
  88. #                     run into if you didn't use the item, and 6.00 means
  89. #                     six times the encounters.  Change this to your liking.
  90. #
  91. #    * EI_Duration_X: The duration (in STEPS) that the Encounter Rate
  92. #                     multiplier effect lasts after you use an item from
  93. #                     this set.  Change this to your liking.
  94. #
  95. #    * EI_Common_X:   The Common Event that will be played when an item's
  96. #                     encounter rate multiplier effect ENDS.  You may leave
  97. #                     this value as nil if you don't want a Common Event to
  98. #                     play, or you may replace nil with the ID of the Common
  99. #                     Event you want to run (e.g., "EI_Common_1 = 2")
  100. #                     (To have a Common Event play when the effect *begins*,
  101. #                     simply add that Common Event to the effects list for
  102. #                     the item in the database.)
  103.  
  104.   # Encounter Items Set 1  
  105.   EI_Item_Set_1 = []
  106.   EI_Enc_Rate_1 = 0.00
  107.   EI_Duration_1 = 60
  108.   EI_Common_1 = nil
  109.  
  110.   # Encounter Items Set 2  
  111.   EI_Item_Set_2 = []
  112.   EI_Enc_Rate_2 = 0.00
  113.   EI_Duration_2 = 180
  114.   EI_Common_2 = nil
  115.  
  116.   # Encounter Items Set 3  
  117.   EI_Item_Set_3 = []
  118.   EI_Enc_Rate_3 = 0.50
  119.   EI_Duration_3 = 60
  120.   EI_Common_3 = nil
  121.  
  122.   # Encounter Items Set 4  
  123.   EI_Item_Set_4 = []
  124.   EI_Enc_Rate_4 = 0.50
  125.   EI_Duration_4 = 180
  126.   EI_Common_4 = nil
  127.  
  128.   # Encounter Items Set 5  
  129.   EI_Item_Set_5 = []
  130.   EI_Enc_Rate_5 = 2.00
  131.   EI_Duration_5 = 60
  132.   EI_Common_5 = nil
  133.  
  134.   # Encounter Items Set 6  
  135.   EI_Item_Set_6 = []
  136.   EI_Enc_Rate_6 = 2.00
  137.   EI_Duration_6 = 180
  138.   EI_Common_6 = nil
  139.  
  140.   # Encounter Items Set 7  
  141.   EI_Item_Set_7 = []
  142.   EI_Enc_Rate_7 = 10.00
  143.   EI_Duration_7 = 20
  144.   EI_Common_7 = nil
  145.  
  146.   # Encounter Items Set 8  
  147.   EI_Item_Set_8 = []
  148.   EI_Enc_Rate_8 = 10.00
  149.   EI_Duration_8 = 60
  150.   EI_Common_8 = nil
  151.  
  152.  
  153. ############################################
  154. #                                          #
  155. #               ICKY CODE!                 #
  156. #                                          #
  157. ############################################
  158.  
  159. # Everything from here on represents the inner workings of the script.
  160. #       Please don't alter anything from here on unless you are an
  161. #       advanced scripter yourself (in which case, have at it!)    
  162.  
  163.   EI_Sets_Full = [EI_Item_Set_1, EI_Item_Set_2, EI_Item_Set_3, EI_Item_Set_4, EI_Item_Set_5, EI_Item_Set_6, EI_Item_Set_7, EI_Item_Set_8]
  164.   EI_Rates_Full = [EI_Enc_Rate_1, EI_Enc_Rate_2, EI_Enc_Rate_3, EI_Enc_Rate_4, EI_Enc_Rate_5, EI_Enc_Rate_6, EI_Enc_Rate_7, EI_Enc_Rate_8]
  165.   EI_Durs_Full = [EI_Duration_1, EI_Duration_2, EI_Duration_3, EI_Duration_4, EI_Duration_5, EI_Duration_6, EI_Duration_7, EI_Duration_8]
  166.   EI_Comms_Full = [EI_Common_1, EI_Common_2, EI_Common_3, EI_Common_4, EI_Common_5, EI_Common_6, EI_Common_7, EI_Common_8]
  167.  
  168. end
  169.  
  170.  
  171. class Game_Player < Game_Character
  172.  
  173.   #--------------------------------------------------------------------------
  174.   # * Get Encounter Progress Value - Enhanced to also process item-based
  175.   #                                  encounter rates
  176.   #--------------------------------------------------------------------------
  177.   alias :encounter_progress_with_items :encounter_progress_value
  178.   def encounter_progress_value
  179.     value = encounter_progress_with_items
  180.     if $enc_steps > 0
  181.       value *= $mod_enc_rate
  182.     else
  183.       $enc_steps = -1
  184.     end
  185.     value
  186.   end
  187.  
  188. end
  189.  
  190.  
  191. class Game_Party < Game_Unit
  192.  
  193.   #--------------------------------------------------------------------------
  194.   # * Public Instance Variables
  195.   #--------------------------------------------------------------------------
  196.   #attr_reader   :mod_enc_rate             # item-based modification to enc. rate
  197.   #attr_reader   :enc_steps                # remaining duration of item enc. rate
  198.  
  199.   #--------------------------------------------------------------------------
  200.   # * Object Initialization
  201.   #--------------------------------------------------------------------------
  202.   alias :init_with_enc_steps :initialize
  203.   def initialize
  204.     init_with_enc_steps
  205.     $enc_steps = 1
  206.     $mod_enc_rate = 1.00
  207.     $enc_item_end = 0
  208.   end
  209.  
  210.   #--------------------------------------------------------------------------
  211.   # * Increase Steps
  212.   #--------------------------------------------------------------------------
  213.   alias :inc_enc_steps :increase_steps
  214.   def increase_steps
  215.     inc_enc_steps
  216.     $enc_steps -= 1
  217.     if $enc_steps == 0
  218.       if ($enc_item_end != nil && $enc_item_end != 0)
  219.         $game_temp.reserve_common_event($enc_item_end)
  220.       end
  221.     end
  222.   end
  223.  
  224. end
  225.  
  226.  
  227. class Scene_Item < Scene_ItemBase
  228.  
  229.   #--------------------------------------------------------------------------
  230.   # * Use Item
  231.   #--------------------------------------------------------------------------
  232.   alias :use_enc_rate_item :use_item
  233.   def use_item
  234.     use_enc_rate_item
  235.     new_mod_enc_rate(item)
  236.   end
  237.  
  238.   #--------------------------------------------------------------------------
  239.   # This method finds the Encounter Rate and sets the remaining duration
  240.   #      when you use an Encounter Rate Item
  241.   #--------------------------------------------------------------------------
  242.   def new_mod_enc_rate(item)
  243.     for i in 0..(Encounter_Items::EI_Sets_Full.length - 1)
  244.       if Encounter_Items::EI_Sets_Full[i].include?(item.id)
  245.         $mod_enc_rate = Encounter_Items::EI_Rates_Full[i]
  246.         $enc_steps = Encounter_Items::EI_Durs_Full[i]
  247.         $enc_item_end = Encounter_Items::EI_Comms_Full[i]
  248.       end
  249.     end
  250.   end
  251.  
  252. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement