Advertisement
TroyZ

TroyZ - Individual Substitute Rate

Jul 8th, 2013
438
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 4.62 KB | None | 0 0
  1. # ==============================================================================
  2. # ▼▼▼▼▼▼                TroyZ - Individual Substitute Rate                ▼▼▼▼▼▼
  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. # 8 July 2013 : Version 1.0 released
  14. # ------------------------------------------------------------------------------
  15. # How this work :
  16. # Defaultly, the substitute cover will work when others allies' HP are below 25%
  17. # of their MaxHP. This script allows you to set the substitute rate individually.
  18. # ------------------------------------------------------------------------------
  19. # How to use :
  20. # Place it between material and main. Use this notetags inside actors and
  21. # enemies :
  22. #
  23. # <substitute rate: x>
  24. #
  25. # Actors and enemies that have this notetag will be covered when their HP is
  26. # below x percent of their MaxHP. For example, an actor has this notetag :
  27. #
  28. # <substitute rate: 50>
  29. #
  30. # This actor will be covered when this actor's HP is below 50% of it's MaxHP.
  31. # Remember, substitute cover will ONLY be work when at least there is one allied
  32. # battler has the substitute special flag.
  33. # ------------------------------------------------------------------------------
  34. # Compatibility issues :
  35. # None yet. If you found some, let me know, and bug fixes will come out soon.
  36. # ------------------------------------------------------------------------------
  37. # Who to credit :
  38. # - Allah swt. : For the chance of living that he has given to me.
  39. # - Nabi Muhammad saw. : As a leader and messenger and prophet of Muslim.
  40. #                        I'm proud to be your follower. :)
  41. # - Agung Prasetyo(TroyZ) : Thats me, of course, the ones that made this script. :P
  42. # ------------------------------------------------------------------------------
  43. # License :
  44. # - Free Game : Just credit those names above.
  45. # - Commercial Game : Same as free game's license.
  46. # ------------------------------------------------------------------------------
  47. $imported = {} if $imported.nil?
  48. $imported[:TroyZ_IndividualSubstituteRate] = true
  49. # ------------------------------------------------------------------------------
  50. # There is nothing to config beyond this line
  51. # ------------------------------------------------------------------------------
  52. module AGUNG
  53.   module SUBSTITUTE
  54.     SUBSTITUTE_RATE_DEFAULT = 25 # the default substitute rate
  55.   end
  56.  
  57.   module NOTETAGS_SUBSTITUTE
  58.     SUBSTITUTE_RATE = /<(?:SUBSTITUTE RATE|substitute rate):[ ]*(\d+)>/i    
  59.   end
  60. end
  61. # ------------------------------------------------------------------------------
  62. # You shall not pass
  63. # ------------------------------------------------------------------------------
  64. module DataManager
  65.   class << self
  66.     alias agung_load_substitute_rate_dbase_x    load_database
  67.   end
  68.  
  69.   def self.load_database
  70.     agung_load_substitute_rate_dbase_x
  71.     agung_load_notetags_substitute_rate_x
  72.   end
  73.  
  74.   def self.agung_load_notetags_substitute_rate_x
  75.     [$data_actors,$data_enemies].each do |object|
  76.       object.each do |obj|
  77.         next unless obj
  78.         obj.agung_load_notetags_substitute_rate_x
  79.       end
  80.     end
  81.   end
  82. end
  83.  
  84. class RPG::Actor < RPG::BaseItem
  85.  
  86.   include AGUNG::SUBSTITUTE
  87.   include AGUNG::NOTETAGS_SUBSTITUTE
  88.  
  89.   attr_accessor :subs_rate  
  90.  
  91.   def agung_load_notetags_substitute_rate_x
  92.     @subs_rate = SUBSTITUTE_RATE_DEFAULT.to_f / 100
  93.     self.note.split(/[\r\n]+/).each { |baris|
  94.       case baris
  95.       when SUBSTITUTE_RATE
  96.         @subs_rate = $1.to_f / 100
  97.       end
  98.     }
  99.   end  
  100. end
  101.  
  102. class RPG::Enemy < RPG::BaseItem
  103.  
  104.   include AGUNG::SUBSTITUTE
  105.   include AGUNG::NOTETAGS_SUBSTITUTE
  106.  
  107.   attr_accessor :subs_rate  
  108.  
  109.   def agung_load_notetags_substitute_rate_x
  110.     @subs_rate = SUBSTITUTE_RATE_DEFAULT.to_f / 100
  111.     self.note.split(/[\r\n]+/).each { |baris|
  112.       case baris
  113.       when SUBSTITUTE_RATE
  114.         @subs_rate = $1.to_f / 100
  115.       end
  116.     }
  117.   end  
  118. end
  119.  
  120. class Game_Actor < Game_Battler
  121.   def subs_rate
  122.     $data_actors[id].subs_rate
  123.   end  
  124. end
  125.  
  126. class Game_Enemy < Game_Battler
  127.   def subs_rate
  128.     $data_enemies[@enemy_id].subs_rate
  129.   end  
  130. end
  131.  
  132. class Scene_Battle < Scene_Base
  133.   def check_substitute(target, item)
  134.     target.hp <= target.mhp * target.subs_rate && (!item || !item.certain?)
  135.   end
  136. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement