Wavescripts

Wave's Heal After Encounter

Oct 12th, 2014
169
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ############################################
  2. #                                          #
  3. #       HEAL AFTER ENCOUNTER SCRIPT        #
  4. #                                          #
  5. #       v1.0 for RPG Maker VX Ace          #
  6. #                                          #
  7. # Created by Jason "Wavelength" Commander  #
  8. #                                          #
  9. ############################################
  10.  
  11. # No matter how badly he's injured — be it from gunshot, blade, burning, acid,
  12. #   you name it — an action-adventure hero never ends up with permanent scars...
  13. #                                                 ~ TVTropes, "Hollywood Healing"
  14.  
  15.  
  16. ############################################
  17. #                                          #
  18. #           ABOUT THIS SCRIPT              #
  19. #                                          #
  20. ############################################
  21.  
  22. # This script will automatically heal the party after each encounter.
  23. #     This is not normally possible without a lot of messy eventing.
  24.  
  25. # Options are included in the script that you can use to control
  26. #     how much HP and MP to restore after battle, whether to automatically
  27. #     revive KO'ed characters, and whether the party needs to win the battle
  28. #     in order to trigger the healing.
  29.  
  30. # This script is compatible with most other scripts.
  31. #     Use caution with other scripts that affect HP or MP directly
  32. #     after battle or modify how the "Death state" is interpreted.
  33. #     However, it is fully compatible with my own "Level-Up Healing" script.
  34.  
  35.  
  36. ############################################
  37. #                                          #
  38. #              TERMS OF USE                #
  39. #                                          #
  40. ############################################
  41.  
  42. # Free to use for non-commercial projects - just credit me
  43.  
  44. # Unlike most of my other scripts, you may also freely use this
  45. #     script in commercial projects - just credit me.
  46.  
  47. # You may freely share or modify this script, but you cannot
  48. #     sell it (even if modified) without my written permission
  49.  
  50. # Please preserve the header (with version #) and terms of use;
  51. #     besides that, feel free to remove any commenting you please
  52.  
  53. # A full explanation of the Terms of Use can be found at my website
  54. #     wavescripts.wordpress.com.
  55.  
  56.  
  57. ############################################
  58. #                                          #
  59. #         HOW TO USE THIS SCRIPT           #
  60. #                                          #
  61. ############################################
  62.  
  63. # This script should be placed in the "Materials" section
  64. #     of the script editor.  In general, this script should
  65. #     be placed below other scripts that modify Game_Battler
  66. #     or Game_BattlerBase.
  67.  
  68.  
  69. ############################################
  70. #                                          #
  71. #       HEAL AFTER ENCOUNTER SETUP         #
  72. #                                          #
  73. ############################################
  74.  
  75. # All of the following options can be left alone if desired, or you can
  76. #      modify them to better customize the script to your game.
  77.  
  78. module Enc_Heal
  79.  
  80.   # Heal Modes represent how the amount or HP or MP healed will be calculated.
  81.   #     0: No HP (MP) will be healed.
  82.   #     1: Amount of HP (MP) healed is a fixed amount.
  83.   #     2: Amount of HP (MP) healed is a percentage of MISSING HP (MP).
  84.   #     3: Amount of HP (MP) healed is a percentage of MAXIMUM HP (MP).
  85.   #     4: Amount of HP (MP) healed is determined by a formula.
  86.  
  87.   HP_Heal_Mode = 3
  88.   MP_Heal_Mode = 3
  89.  
  90.   # Heal Amounts are the amount/percentage of HP or MP healed when battle ends.
  91.   #     NOTE: If a Heal Mode is 4, enter a formula string instead of a number.
  92.   #     Use the keyword "me" to reference an actor's parameters (for example,
  93.   #     HP_Healing = "me.luk * 2" will restore health to each actor equal
  94.   #     to twice their Luck).
  95.  
  96.   HP_Healing = 10
  97.   MP_Healing = 20
  98.  
  99.   # Choose whether or not to remove the "Death state" at the end of battle.
  100.   #     (If KO is not removed, the KO'ed battler will not receive healing.)
  101.  
  102.   Remove_KO = true
  103.  
  104.   # Choose whether or not to run "End of Battle Healing" only for a victory, or
  105.   #     for any outcome whatsoever (victory/escape/abort/defeat).  If "true", HP
  106.   #     and MP will only be restored upon victory.  Note that Game Overs will
  107.   #     still occur if the party is wiped out in a battle that doesn't have the
  108.   #     "Continue even when Loser" option set.
  109.  
  110.   Only_On_Win = true
  111.  
  112. end
  113.  
  114. ############################################
  115. #                                          #
  116. #               ICKY CODE!                 #
  117. #                                          #
  118. ############################################
  119.  
  120. # Everything from here on represents the inner workings of the script.
  121. #       Please don't alter anything from here on unless you are an
  122. #       advanced scripter yourself (in which case, have at it!)  
  123.  
  124.  
  125. class Game_Party < Game_Unit
  126.  
  127.   # The modification to this class is to allow broader access to whether the
  128.   #   party won their last battle, necessary for the "Only On Win" option.
  129.  
  130.   #--------------------------------------------------------------------------
  131.   # * Public Instance Variables
  132.   #--------------------------------------------------------------------------
  133.   attr_accessor   :won_battle         # whether the party won their last battle
  134.  
  135.   #--------------------------------------------------------------------------
  136.   # * Object Initialization
  137.   #--------------------------------------------------------------------------
  138.   alias :init_with_result :initialize
  139.   def initialize
  140.     init_with_result
  141.     @won_battle = false
  142.   end
  143.  
  144. end
  145.  
  146. module BattleManager
  147.  
  148.   class << self
  149.  
  150.     #--------------------------------------------------------------------------
  151.     # * End Battle
  152.     #     result : Result (0: Win 1: Escape 2: Lose)
  153.     #       This alias method stores whether you won your last battle, then
  154.     #       does the normal "Battle End" processing.
  155.     #--------------------------------------------------------------------------
  156.     alias :battle_end_store_result :battle_end
  157.     def battle_end(result)
  158.       if result == 0
  159.         $game_party.won_battle = true
  160.       else
  161.         $game_party.won_battle = false
  162.       end
  163.       battle_end_store_result(result)
  164.     end
  165.    
  166.   end
  167.  
  168. end
  169.  
  170. class Game_Battler < Game_BattlerBase
  171.  
  172.   #--------------------------------------------------------------------------
  173.   # * Processing at End of Battle
  174.   #     This alias method does the normal "On Battle End" processing for
  175.   #     a party member, then restores HP and MP (and removes KO) if appropriate.
  176.   #--------------------------------------------------------------------------
  177.   alias :on_battle_end_heal :on_battle_end
  178.   def on_battle_end
  179.     # First, do the normal "On Battle End" processing
  180.     on_battle_end_heal
  181.     # Then, if either the party won the last battle, or gets to heal regardless,
  182.     #   start the "End of Battle Heal" process on the character.
  183.     if (($game_party.won_battle) or (!Enc_Heal::Only_On_Win))
  184.       # If the Remove KO option is on, remove it.
  185.       if Enc_Heal::Remove_KO
  186.         remove_state(death_state_id)
  187.       end
  188.       # If the character is not KO'ed...
  189.       unless self.state?(death_state_id)
  190.         # Then heal the character's HP based on HP Heal Mode and HP Healing...
  191.         case Enc_Heal::HP_Heal_Mode
  192.         when 1
  193.           # Increase character's HP by the amount specified in HP_Healing
  194.           @hp += Enc_Heal::HP_Healing
  195.           # If character now has more HP than their max HP, set it to their max.
  196.           #   If they have less than 1 HP, set it to 1.
  197.           @hp = [[@hp, mhp].min, 1].max
  198.         when 2
  199.           @hp += (((Enc_Heal::HP_Healing * (mhp - @hp)) / 100.0) + 0.5).to_i
  200.           @hp = [[@hp, mhp].min, 1].max
  201.         when 3
  202.           @hp += (((Enc_Heal::HP_Healing * mhp) / 100.0) + 0.5).to_i
  203.           @hp = [[@hp, mhp].min, 1].max
  204.         when 4
  205.           me = self
  206.           @hp += (Kernel.eval(Enc_Heal::HP_Healing) rescue 0)
  207.           @hp = [[@hp, mhp].min, 1].max
  208.         else
  209.         end
  210.         # And also do the same for the character's MP.
  211.         case Enc_Heal::MP_Heal_Mode
  212.         when 1
  213.           @mp += Enc_Heal::MP_Healing
  214.           @mp = [[@mp, mmp].min, 0].max
  215.         when 2
  216.           @mp += (((Enc_Heal::MP_Healing * (mmp - @mp)) / 100.0) + 0.5).to_i
  217.           @mp = [[@mp, mmp].min, 0].max
  218.         when 3
  219.           @mp += (((Enc_Heal::MP_Healing * mmp) / 100.0) + 0.5).to_i
  220.           @mp = [[@mp, mmp].min, 0].max
  221.         when 4
  222.           me = self
  223.           @mp += (Kernel.eval(Enc_Heal::MP_Healing) rescue 0)
  224.           @mp = [[@mp, mmp].min, 0].max
  225.         else
  226.         end
  227.       end
  228.     end
  229.   end
  230.  
  231. end
RAW Paste Data