Advertisement
TroyZ

TroyZ - Crisis HP Warning

Nov 28th, 2013
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 6.14 KB | None | 0 0
  1. # ==============================================================================
  2. # ▼▼▼▼▼▼                    TroyZ - Crisis HP Warning                     ▼▼▼▼▼▼
  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. # 28 November 2013 : Version 1.0 released
  14. # ------------------------------------------------------------------------------
  15. # How this work :
  16. # This script allows you to create warnings on the map when the actors'
  17. # HP are below specified percentage of their max HP.
  18. # ------------------------------------------------------------------------------
  19. # How to use :
  20. # Place it between material and main. Use this notetags inside actors :
  21. #
  22. # <hp warn rate: x>
  23. #
  24. # Actors that have this notetag will show the warn on the map when their HP is
  25. # below x percent of their MaxHP. For example, an actor has this notetag :
  26. #
  27. # <hp warn rate: 50>
  28. #
  29. # This actor will show the warn on the map when this actor's HP is below 50% of
  30. # it's MaxHP. You can alter the warn with the following script calls :
  31. #
  32. # hp_warn_flash_color(color), when the color is the new color object.
  33. # hp_warn_duration_flash_color(duration), when the duration is the new duration
  34. #                                         (in frames).
  35. # hp_warn_duration(duration), when the duration is the new duration (in frames).
  36. # ------------------------------------------------------------------------------
  37. # Compatibility issues :
  38. # None yet. If you found some, let me know, and bug fixes will come out soon.
  39. # ------------------------------------------------------------------------------
  40. # Who to credit :
  41. # - Allah swt. : For the chance of living that he has given to me.
  42. # - Nabi Muhammad saw. : As a leader and messenger and prophet of Muslim.
  43. #                        I'm proud to be your follower. :)
  44. # - Agung Prasetyo(TroyZ) : Thats me, of course, the ones that made this script. :P
  45. # ------------------------------------------------------------------------------
  46. # License :
  47. # - Free Game : Just credit those names above.
  48. # - Commercial Game : Same as free game's license.
  49. # ------------------------------------------------------------------------------
  50. $imported = {} if $imported.nil?
  51. $imported[:TroyZ_CrisisHPWarning] = true
  52. # ------------------------------------------------------------------------------
  53. # Configuration of script starts here
  54. # ------------------------------------------------------------------------------
  55. module AGUNG
  56.   module CRI_HP_WARN
  57.     SWITCH_FLASH_WARN = 20 # when this switch is ON, the flash effect of hp warn
  58.                            # is active
  59.     FLASH_WARN_COLOR = Color.new(255,0,0,128) # the color when flash effect of
  60.                                               # hp warn is used
  61.     DURATION_FLASH_WARN_COLOR = 20 # duration of flash effect
  62.     DURATION_WARN = 60 # how long the warn shows (in frames)
  63.     WARN_SE = "Audio/SE/Absorb1" # the SE of warn
  64.     CRI_HP_WARN_DEFAULT = 25 # the default rate with actors that don't have
  65.                              # notetag of hp warn
  66.   end
  67.  
  68.   module NOTETAGS_CRI_HP_WARN
  69.     CRI_HP_WARN = /<(?:HP WARN RATE|hp warn rate):[ ]*(\d+)>/i
  70.   end  
  71. end
  72. # ------------------------------------------------------------------------------
  73. # End of Configuration
  74. # ------------------------------------------------------------------------------
  75.  
  76. # ------------------------------------------------------------------------------
  77. # You shall not pass
  78. # ------------------------------------------------------------------------------
  79. module DataManager
  80.   class << self
  81.     alias agung_load_cri_hp_warn_dbase_x    load_database
  82.   end
  83.  
  84.   def self.load_database
  85.     agung_load_cri_hp_warn_dbase_x
  86.     agung_load_notetags_cri_hp_warn_x
  87.   end
  88.  
  89.   def self.agung_load_notetags_cri_hp_warn_x
  90.     [$data_actors].each do |actors|
  91.       actors.each do |obj|
  92.         next unless obj
  93.         obj.agung_load_notetags_cri_hp_warn_x
  94.       end
  95.     end
  96.   end
  97. end
  98.  
  99. class RPG::Actor < RPG::BaseItem  
  100.   include AGUNG::CRI_HP_WARN
  101.   include AGUNG::NOTETAGS_CRI_HP_WARN
  102.  
  103.   attr_accessor :hp_warn_rate  
  104.  
  105.   def agung_load_notetags_cri_hp_warn_x
  106.     @hp_warn_rate = CRI_HP_WARN_DEFAULT.to_f / 100
  107.     self.note.split(/[\r\n]+/).each { |baris|
  108.       case baris
  109.       when CRI_HP_WARN
  110.         @hp_warn_rate = $1.to_f / 100
  111.       end
  112.     }
  113.   end  
  114. end
  115.  
  116. class Game_System
  117.   attr_accessor :flash_warn_color
  118.   attr_accessor :duration_flash_warn_color
  119.   attr_accessor :duration_warn
  120.  
  121.   alias agung_hp_warn_init_x    initialize
  122.   def initialize
  123.     agung_hp_warn_init_x    
  124.     @flash_warn_color = AGUNG::CRI_HP_WARN::FLASH_WARN_COLOR
  125.     @duration_flash_warn_color = AGUNG::CRI_HP_WARN::DURATION_FLASH_WARN_COLOR
  126.     @duration_warn = AGUNG::CRI_HP_WARN::DURATION_WARN
  127.   end
  128. end
  129.  
  130. class Game_Interpreter  
  131.   def hp_warn_flash_color(color)
  132.     $game_system.flash_warn_color = color
  133.   end  
  134.  
  135.   def hp_warn_duration_flash_color(duration)
  136.     $game_system.duration_flash_warn_color = duration
  137.   end
  138.  
  139.   def hp_warn_duration(duration)
  140.     $game_system.duration_warn = duration
  141.   end
  142. end
  143.  
  144. class Game_Actor < Game_Battler
  145.   def hp_warn_rate
  146.     $data_actors[id].hp_warn_rate
  147.   end  
  148. end
  149.  
  150. class Game_Screen
  151.   def hp_warn_flash
  152.     start_flash($game_system.flash_warn_color, $game_system.duration_flash_warn_color)
  153.   end
  154. end
  155.  
  156. class Scene_Map < Scene_Base
  157.   include AGUNG::CRI_HP_WARN
  158.  
  159.   alias agung_update_map_x  update
  160.   def update
  161.     agung_update_map_x
  162.     x_play_crisis_sound_x if Graphics.frame_count % $game_system.duration_warn == 0
  163.   end
  164.  
  165.   def x_play_crisis_sound_x
  166.     $game_party.members.each do |actor|
  167.       if actor.hp <= actor.mhp * actor.hp_warn_rate
  168.         $game_map.screen.hp_warn_flash if $game_switches[SWITCH_FLASH_WARN]
  169.         Audio.se_play(WARN_SE)
  170.       end
  171.     end
  172.   end  
  173. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement