Advertisement
TroyZ

TroyZ - States Hit Count Removal 1.0

Jun 17th, 2013
426
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 5.21 KB | None | 0 0
  1. # ==============================================================================
  2. # ▼▼▼▼▼▼                TroyZ - States Hit Count Removal                  ▼▼▼▼▼▼
  3. # ==============================================================================
  4. # Script by : Agung Prasetyo(TroyZ)
  5. # Contact me by : - Email agung.endisnear.xyz@gmail.com
  6. #                 - Forum RPGMakerID, username TroyZ
  7. #                 - Handphone 085756289121
  8. # Engine : VXAce
  9. # Level : Easy
  10. # Version : 1.0
  11. # ------------------------------------------------------------------------------
  12. # Change Logs :
  13. # 18 June 2013 : Version 1.0 released
  14. # ------------------------------------------------------------------------------
  15. # How this work :
  16. # This script will give you an ability to create states that removed at a
  17. # certain hit count and certain probability.
  18. # ------------------------------------------------------------------------------
  19. # How to use :
  20. # Place it between material and main. Use this notetags inside states :
  21. #
  22. # <remove by hit: x>
  23. # <remove by hit chance: y>
  24. #
  25. # The states that have this notetags will be removed when the affected battler
  26. # suffers the x total hits at y% probability. You don't have to write the percent
  27. # sign at y, just put the number actually. For example, a state have this notetags :
  28. #
  29. # <remove by hit: 3>
  30. # <remove by hit chance: 50>
  31. #
  32. # The state will be removed when the affected battler suffers 3 hits from enemies.
  33. # When the battler get 3 hits from enemies, the state will be removed at 50% chance.
  34. # ------------------------------------------------------------------------------
  35. # Compatibility issues :
  36. # None yet. If you found some, let me know, and bug fixes will come out soon.
  37. # ------------------------------------------------------------------------------
  38. # Who to credit :
  39. # - Allah swt. : For the chance of living that he has given to me.
  40. # - Nabi Muhammad saw. : As a leader and messenger and prophet of Muslim.
  41. #                        I'm proud to be your follower. :)
  42. # - Agung Prasetyo(TroyZ) : Thats me, of course, the ones that made this script. :P
  43. # ------------------------------------------------------------------------------
  44. # License :
  45. # - Free Game : Just credit those names above.
  46. # - Commercial Game : Same as free game's license.
  47. # ------------------------------------------------------------------------------
  48. $imported = {} if $imported.nil?
  49. $imported[:TroyZ_StatesHitCountRemoval] = true
  50. # ------------------------------------------------------------------------------
  51. # There is nothing to config beyond this line
  52. # ------------------------------------------------------------------------------
  53. module AGUNG
  54.   module HIT_COUNT
  55.     HIT_COUNT_DEFAULT = 0
  56.     HIT_COUNT_REMOVE_CHANCE_DEFAULT = 0
  57.   end
  58.  
  59.   module NOTETAGS_HIT_COUNT
  60.     HIT_COUNT = /<(?:REMOVE BY HIT|remove by hit):[ ]*(\d+)>/i
  61.     HIT_COUNT_REMOVE_CHANCE = /<(?:REMOVE BY HIT CHANCE|remove by hit chance):[ ]*(\d+)>/i
  62.   end
  63. end
  64.  
  65. module DataManager
  66.   class << self
  67.     alias agung_load_states_hit_count_removal_dbase_x    load_database
  68.   end
  69.  
  70.   def self.load_database
  71.     agung_load_states_hit_count_removal_dbase_x
  72.     agung_load_notetags_hit_count_removal_x
  73.   end
  74.  
  75.   def self.agung_load_notetags_hit_count_removal_x
  76.     [$data_states].each do |states|
  77.       states.each do |obj|
  78.         next unless obj
  79.         obj.agung_load_notetags_hit_count_removal_x
  80.       end
  81.     end
  82.   end
  83. end
  84.  
  85. class RPG::State < RPG::BaseItem
  86.  
  87.   include AGUNG::HIT_COUNT
  88.   include AGUNG::NOTETAGS_HIT_COUNT
  89.  
  90.   attr_accessor :hit_count
  91.   attr_accessor :chance_by_hit_count
  92.  
  93.   def agung_load_notetags_hit_count_removal_x
  94.     @hit_count = HIT_COUNT_DEFAULT
  95.     @chance_by_hit_count = HIT_COUNT_REMOVE_CHANCE_DEFAULT
  96.     self.note.split(/[\r\n]+/).each { |baris|
  97.       case baris
  98.       when HIT_COUNT
  99.         @hit_count = $1.to_i
  100.       when HIT_COUNT_REMOVE_CHANCE
  101.         @chance_by_hit_count = $1.to_i
  102.       end
  103.     }
  104.   end  
  105. end
  106.  
  107. class Game_BattlerBase
  108.   alias agung_clear_states_x    clear_states
  109.   def clear_states
  110.     agung_clear_states_x
  111.     @state_hit_count = {}
  112.   end
  113.  
  114.   alias agung_erase_state_x   erase_state
  115.   def erase_state(state_id)
  116.     agung_erase_state_x(state_id)
  117.     @state_hit_count.delete(state_id)
  118.   end
  119. end
  120.  
  121. class Game_Battler < Game_BattlerBase
  122.   alias agung_reset_state_counts_x    reset_state_counts
  123.   def reset_state_counts(state_id)
  124.     agung_reset_state_counts_x(state_id)
  125.     @state_hit_count[state_id] = $data_states[state_id].hit_count
  126.   end
  127.  
  128.   def update_states_hit_count
  129.     states.each do |state|
  130.       @state_hit_count[state.id] -= 1 if @state_hit_count[state.id] > 0
  131.     end
  132.   end
  133.  
  134.   def remove_states_by_hit_count
  135.     states.each do |state|
  136.       if @state_hit_count[state.id] == 0 && rand(100) < state.chance_by_hit_count
  137.         remove_state(state.id)
  138.       end
  139.     end
  140.   end
  141.  
  142.   alias agung_on_damage_x   on_damage
  143.   def on_damage(value)    
  144.     agung_on_damage_x(value)
  145.     update_states_hit_count
  146.     remove_states_by_hit_count
  147.   end
  148. end
  149. # ------------------------------------------------------------------------------
  150. # END OF SCRIPT
  151. # ------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement