Advertisement
TroyZ

TroyZ - States Hit Count Removal 1.1

Oct 24th, 2013
424
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 6.26 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.1
  11. # ------------------------------------------------------------------------------
  12. # Change Logs :
  13. # 18 June 2013 : Version 1.0 released
  14. # 24 October 2013 : Bugfix version 1.1 released
  15. # ------------------------------------------------------------------------------
  16. # How this work :
  17. # This script will give you an ability to create states that removed at a
  18. # certain hit count and certain probability.
  19. # ------------------------------------------------------------------------------
  20. # How to use :
  21. # Place it between material and main. Use this notetags inside states :
  22. #
  23. # <remove by hit: x>
  24. # <remove by hit chance: y>
  25. #
  26. # The states that have this notetags will be removed when the affected battler
  27. # suffers the x total hits at y% probability. You don't have to write the percent
  28. # sign at y, just put the number actually. For example, a state have this notetags :
  29. #
  30. # <remove by hit: 3>
  31. # <remove by hit chance: 50>
  32. #
  33. # The state will be removed when the affected battler suffers 3 hits from enemies.
  34. # When the battler get 3 hits from enemies, the state will be removed at 50% chance.
  35. #
  36. # Bugfix :
  37. # I've made a slight change to the script so that it'll be compatible with YEA - Passive States.
  38. # In previous version, when a passive states are active on battler and the battler
  39. # get even a single hit from enemy, an error occured. This error occured because
  40. # the passive states didn't have any hit counter applied, and this script reduce
  41. # the counter itself. And also, passive states are not allowed to be removed
  42. # unless the battler dies. Version 1.1 has bugfix for this. In order for the
  43. # passive states to not be removed when the battler get hits, put this notetag
  44. # inside the passive states:
  45. #
  46. # <passive>
  47. #
  48. # The <passive> notetag will prevent it from getting removed by hit. Remember,
  49. # put the <passive> notetag ONLY inside the passive states.
  50. # ------------------------------------------------------------------------------
  51. # Compatibility issues :
  52. # - YEA - Passive States, the passive states getting removed even only by single hit.
  53. #   Version 1.1 has bugfix for this. Put this script below YEA - Passive States.
  54. # ------------------------------------------------------------------------------
  55. # Who to credit :
  56. # - Allah swt. : For the chance of living that he has given to me.
  57. # - Nabi Muhammad saw. : As a leader and messenger and prophet of Muslim.
  58. #                        I'm proud to be your follower. :)
  59. # - Agung Prasetyo(TroyZ) : Thats me, of course, the ones that made this script. :P
  60. # ------------------------------------------------------------------------------
  61. # License :
  62. # - Free Game : Just credit those names above.
  63. # - Commercial Game : Same as free game's license.
  64. # ------------------------------------------------------------------------------
  65. $imported = {} if $imported.nil?
  66. $imported[:TroyZ_StatesHitCountRemoval] = true
  67. # ------------------------------------------------------------------------------
  68. # There is nothing to config beyond this line
  69. # ------------------------------------------------------------------------------
  70. module AGUNG
  71.   module HIT_COUNT
  72.     HIT_COUNT_DEFAULT = 0
  73.     HIT_COUNT_REMOVE_CHANCE_DEFAULT = 0
  74.   end
  75.  
  76.   module NOTETAGS_HIT_COUNT
  77.     HIT_COUNT = /<(?:REMOVE BY HIT|remove by hit):[ ]*(\d+)>/i
  78.     HIT_COUNT_REMOVE_CHANCE = /<(?:REMOVE BY HIT CHANCE|remove by hit chance):[ ]*(\d+)>/i
  79.   end
  80. end
  81.  
  82. module DataManager
  83.   class << self
  84.     alias agung_load_states_hit_count_removal_dbase_x    load_database
  85.   end
  86.  
  87.   def self.load_database
  88.     agung_load_states_hit_count_removal_dbase_x
  89.     agung_load_notetags_hit_count_removal_x
  90.   end
  91.  
  92.   def self.agung_load_notetags_hit_count_removal_x
  93.     [$data_states].each do |states|
  94.       states.each do |obj|
  95.         next unless obj
  96.         obj.agung_load_notetags_hit_count_removal_x
  97.       end
  98.     end
  99.   end
  100. end
  101.  
  102. class RPG::State < RPG::BaseItem
  103.  
  104.   include AGUNG::HIT_COUNT
  105.   include AGUNG::NOTETAGS_HIT_COUNT
  106.  
  107.   attr_accessor :hit_count
  108.   attr_accessor :chance_by_hit_count
  109.  
  110.   def agung_load_notetags_hit_count_removal_x
  111.     @hit_count = HIT_COUNT_DEFAULT
  112.     @chance_by_hit_count = HIT_COUNT_REMOVE_CHANCE_DEFAULT
  113.     self.note.split(/[\r\n]+/).each { |baris|
  114.       case baris
  115.       when HIT_COUNT
  116.         @hit_count = $1.to_i
  117.       when HIT_COUNT_REMOVE_CHANCE
  118.         @chance_by_hit_count = $1.to_i
  119.       end
  120.     }
  121.   end  
  122.  
  123.   def passive_states?
  124.     self.note.include?("<passive>")
  125.   end  
  126. end
  127.  
  128. class Game_BattlerBase
  129.   alias agung_clear_states_x    clear_states
  130.   def clear_states
  131.     agung_clear_states_x
  132.     @state_hit_count = {}
  133.   end
  134.  
  135.   alias agung_erase_state_x   erase_state
  136.   def erase_state(state_id)
  137.     agung_erase_state_x(state_id)
  138.     @state_hit_count.delete(state_id)
  139.   end
  140. end
  141.  
  142. class Game_Battler < Game_BattlerBase
  143.   alias agung_reset_state_counts_x    reset_state_counts
  144.   def reset_state_counts(state_id)
  145.     agung_reset_state_counts_x(state_id)
  146.     @state_hit_count[state_id] = $data_states[state_id].hit_count
  147.   end
  148.  
  149.   def update_states_hit_count
  150.     states.each do |state|
  151.       if !state.passive_states?
  152.         if @state_hit_count[state.id] > 0
  153.           @state_hit_count[state.id] -= 1
  154.         end
  155.       end
  156.     end
  157.   end
  158.  
  159.   def remove_states_by_hit_count
  160.     states.each do |state|
  161.       if @state_hit_count[state.id] == 0 && rand(100) < state.chance_by_hit_count
  162.         remove_state(state.id)
  163.       end
  164.     end
  165.   end
  166.  
  167.   alias agung_on_damage_x   on_damage
  168.   def on_damage(value)    
  169.     agung_on_damage_x(value)
  170.     update_states_hit_count
  171.     remove_states_by_hit_count
  172.   end
  173. end
  174. # ------------------------------------------------------------------------------
  175. # END OF SCRIPT
  176. # ------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement