CyberForte

DoW Encounter Rate

Oct 10th, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 4.67 KB | None | 0 0
  1. #==============================================================================
  2. #    Update Encounter Percentage
  3. #    Version: 1.0
  4. #    Author: modern algebra (rmrk.net)
  5. #    Date: April 29, 2010
  6. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  7. #  Description:
  8. #
  9. #    This script allows you to dynamically alter the rate at which encounters
  10. #   happen. It is useful particularly for making items or skills that can
  11. #   reduce or increase the rate of encounters. What this script does is allow
  12. #   you to specify a variable to control encounter rate, so you can use events
  13. #   and common events to change the percentage of the default at which
  14. #   encounters occur.
  15. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  16. #  Instructions:
  17. #
  18. #    Paste this script into its own slot in the Script Editor (F11) above Main
  19. #   but below Materials.
  20. #
  21. #    To set up which variable you want to control Encounter Rate, go to line 38
  22. #   and set UEP_CONTROL_VARIABLE_ID to the ID of the variable you want.
  23. #
  24. #    The in-game value of the variable that you set will be the modified
  25. #   percentage of encounters.
  26. #    EX: If that variable is set to 100, then the encounter rate will not
  27. #   change at all. If it's set to 50, then encounters will occur half as
  28. #   frequently. If it's set to 200, then encounters will occur twice as
  29. #   frequently. As a default measure, when that variable is set to 0, then it
  30. #   will not alter encounter rate in any way. If you set the variable to
  31. #   anything below 0 then no encounters will occur at all.
  32. #==============================================================================
  33.  
  34. #\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
  35. #  EDITABLE REGION
  36. #||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  37. # The ID of the variable that controls how the encounter rate is updated
  38. UEP_CONTROL_VARIABLE_ID = 20
  39. #||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  40. #  END EDITABLE REGION
  41. #//////////////////////////////////////////////////////////////////////////////
  42. #==============================================================================
  43. # ** Game Variables
  44. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  45. #  Summary of Changes:
  46. #    aliased method - []=
  47. #==============================================================================
  48.  
  49. class Game_Variables
  50.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  51.   # * Set Variable
  52.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  53.   alias malg_upep_setvar_7uj1 []= unless $@
  54.   def []= (var_id, *args)
  55.     old_val = self[var_id]
  56.     malg_upep_setvar_7uj1 (var_id, *args)
  57.     # Scale Encounter percentage if this is the control variable
  58.     if var_id == UEP_CONTROL_VARIABLE_ID && old_val != self[var_id]
  59.       $game_player.calc_encounter_percent (old_val)
  60.     end
  61.   end
  62. end
  63.  
  64. #==============================================================================
  65. # ** Game Player
  66. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  67. #  Summary of Changes:
  68. #    aliased method - update_encounter, make_encounter_count
  69. #    new method - calc_enc_percent
  70. #==============================================================================
  71.  
  72. class Game_Player
  73.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  74.   # * Make Encounter Count
  75.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  76.   alias modern_ueper_mkencnt_5fv1 make_encounter_count unless $@
  77.   def make_encounter_count (*args)
  78.     modern_ueper_mkencnt_5fv1 (*args)
  79.     calc_encounter_percent
  80.   end
  81.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  82.   # * Update Encounter
  83.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  84.   alias malg_uep_updenc_6yj2 update_encounter unless $@
  85.   def update_encounter (*args)
  86.     variable = $game_variables[UEP_CONTROL_VARIABLE_ID]
  87.     return if variable.nil? || variable < 0
  88.     malg_uep_updenc_6yj2 (*args) # Run Original Method
  89.   end
  90.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  91.   # * Calculate Encounter Percentage
  92.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  93.   def calc_encounter_percent (old_mod = 100)
  94.     variable = $game_variables[UEP_CONTROL_VARIABLE_ID]
  95.     return if variable.nil? || variable < 0 || old_mod < 0
  96.     old_mod = 100 if old_mod == 0
  97.     variable = 100 if variable == 0
  98.     @encounter_count = (@encounter_count*(old_mod.to_f / variable.to_f)).to_i
  99.   end
  100. end
Add Comment
Please, Sign In to add comment