States : Auto-Life

States : Auto-Life
Version: 3.5
By: Kain Nobel

Introduction

This is a script which allows you to provide an Auto-Life effect to certain states. If a battler is inflicted with one of these auto-life states, when they die they'll imediately be brought back to life with a designated direct/percent of HP and/or SP restored. Also, this applies to both actors and enemies, so your baddies can inflict autolife states on each other as well ;)

Features

  • Make states which have an autolife effect
  • When battler dies, their HP (and possibly SP) can be restored
  • Can set what kind of HP/SP is restored (direct/percent) when battler is revived with state
  • The battle won't end if your last person dies with an autolife state
  • Can set the font name and size and text for autolife damage pop
  • Can set the main and background color of autolife damage pop

Script

States : Auto Life Spoiler
  1. #===============================================================================
  2. # ** States : Auto-Life
  3. #===============================================================================
  4.  
  5. #-------------------------------------------------------------------------------
  6. # * SDK Log
  7. #-------------------------------------------------------------------------------
  8. if Object.const_defined?(:SDK)
  9.   SDK.log('States.Auto-Life', 'Kain Nobel ©', 3.5, '2009.06.17')
  10. end
  11.  
  12. #===============================================================================
  13. # ** RPG::State::AutoRevive
  14. #===============================================================================
  15.  
  16. module RPG::State::AutoRevive
  17.   #-----------------------------------------------------------------------------
  18.   # * State IDs
  19.   #-----------------------------------------------------------------------------
  20.   State_IDs     = [17, 18]
  21.   #-----------------------------------------------------------------------------
  22.   # * Damage String displayed during Auto-Revive animation
  23.   #-----------------------------------------------------------------------------
  24.   DisplayText   = "Auto-Revive!"
  25.   #-----------------------------------------------------------------------------
  26.   # * Font Name for damage display
  27.   #-----------------------------------------------------------------------------
  28.   Font_Name     = "Arial Black"
  29.   #-----------------------------------------------------------------------------
  30.   # * Font Size for damage display
  31.   #-----------------------------------------------------------------------------
  32.   Font_Size     = 40
  33.   #-----------------------------------------------------------------------------
  34.   # * Color for text background
  35.   #-----------------------------------------------------------------------------
  36.   Color_Back    = Color.new(255, 255, 0)
  37.   #-----------------------------------------------------------------------------
  38.   # * Color for text face
  39.   #-----------------------------------------------------------------------------
  40.   Color_Main    = Color.new(255,255,255)
  41.   #-----------------------------------------------------------------------------
  42.   # * Animation
  43.   #-----------------------------------------------------------------------------
  44.   Animation_ID  = 26
  45.   #-----------------------------------------------------------------------------
  46.   # * HP Percent Recovered from Auto-Revive state
  47.   #-----------------------------------------------------------------------------
  48.   HP_Percent    = {
  49.   }
  50.   #-----------------------------------------------------------------------------
  51.   # * HP Directly Recovered from Auto-Revive state
  52.   #-----------------------------------------------------------------------------
  53.   HP_Direct     = {
  54.   }
  55.   #-----------------------------------------------------------------------------
  56.   # * SP Percent Recovered from Auto-Revive state
  57.   #-----------------------------------------------------------------------------
  58.   SP_Percent    = {
  59.   }
  60.   #-----------------------------------------------------------------------------
  61.   # * SP Directly Recovered from Auto-Revive state
  62.   #-----------------------------------------------------------------------------
  63.   SP_Direct     = {
  64.   }
  65.   #-----------------------------------------------------------------------------
  66.   # * Default Settings
  67.   #-----------------------------------------------------------------------------
  68.   HP_Percent.default  = 0
  69.   SP_Percent.default  = 0
  70.   HP_Direct.default   = 420
  71.   SP_Percent.default  = 0
  72. end
  73.  
  74. #===============================================================================
  75. # ** RPG::State
  76. #===============================================================================
  77.  
  78. class RPG::State
  79.   #-----------------------------------------------------------------------------
  80.   # * Autolife ?
  81.   #-----------------------------------------------------------------------------
  82.   def autolife?
  83.     AutoRevive::State_IDs.include?(id)
  84.   end
  85.   #-----------------------------------------------------------------------------
  86.   # * Autolife HP
  87.   #-----------------------------------------------------------------------------
  88.   def autolife_hp(max)
  89.     value = 0
  90.     if AutoRevive::HP_Percent[id].is_a?(Numeric)
  91.       if AutoRevive::HP_Percent[id] > 0
  92.         value = max * (AutoRevive::HP_Percent[id] / 100.0)
  93.       end
  94.     end
  95.     if AutoRevive::HP_Direct[id].is_a?(Numeric)
  96.       value += AutoRevive::HP_Direct[id]
  97.     end
  98.     Integer([value, 1].max)
  99.   end
  100.   #-----------------------------------------------------------------------------
  101.   # * Autolife SP
  102.   #-----------------------------------------------------------------------------
  103.   def autolife_sp(max)
  104.     value = 0
  105.     if AutoRevive::SP_Percent[id].is_a?(Numeric)
  106.       if AutoRevive::SP_Percent[id] > 0
  107.         value = max * (AutoRevive::SP_Percent[id] / 100.0)
  108.       end
  109.     end
  110.     if AutoRevive::SP_Direct[id].is_a?(Numeric)
  111.       value += AutoRevive::SP_Direct[id]
  112.     end
  113.     Integer(value)
  114.   end
  115. end
  116.  
  117.    
  118. #===============================================================================
  119. # ** RPG::Sprite
  120. #===============================================================================
  121.  
  122. class RPG::Sprite
  123.   #-----------------------------------------------------------------------------
  124.   # * Alias Listing
  125.   #-----------------------------------------------------------------------------
  126.   alias_method :autolife_rpgsprite_damage,      :damage
  127.   #-----------------------------------------------------------------------------
  128.   # * Damage
  129.   #-----------------------------------------------------------------------------
  130.   def damage(value, critical)
  131.     if value != RPG::State::AutoRevive::DisplayText
  132.       autolife_rpgsprite_damage(value, critical)
  133.       return
  134.     end
  135.     dispose_damage
  136.     bitmap = Bitmap.new(160, 48)
  137.     bitmap.font.name = RPG::State::AutoRevive::Font_Name
  138.     bitmap.font.size = RPG::State::AutoRevive::Font_Size
  139.     bitmap.font.color = RPG::State::AutoRevive::Color_Back
  140.     bitmap.draw_text(-1, 12-1, 160, 36, value, 1)
  141.     bitmap.draw_text(-1, 12+1, 160, 36, value, 1)
  142.     bitmap.draw_text(1, 12-1, 160, 36, value, 1)
  143.     bitmap.draw_text(1, 12+1, 160, 36, value, 1)
  144.     bitmap.font.color = RPG::State::AutoRevive::Color_Main
  145.     bitmap.font.size = RPG::State::AutoRevive::Font_Size * 0.9
  146.     bitmap.draw_text(0, 12, 160, 36, value, 1)
  147.     @_damage_sprite = ::Sprite.new(self.viewport)
  148.     @_damage_sprite.bitmap = bitmap
  149.     @_damage_sprite.ox = 80
  150.     @_damage_sprite.oy = 0
  151.     @_damage_sprite.x = self.x
  152.     @_damage_sprite.y = self.y - self.oy / 2
  153.     @_damage_sprite.z = 10000
  154.     @_damage_duration = 40
  155.   end
  156. end
  157.  
  158. #===============================================================================
  159. # ** Game_Battler
  160. #===============================================================================
  161.  
  162. class Game_Battler
  163.   #-----------------------------------------------------------------------------
  164.   # * Autolife Effect
  165.   #-----------------------------------------------------------------------------
  166.   def autolife_effect
  167.     return unless self.autolife_dead?
  168.     @states.each do |state_id|
  169.       state = $data_states[state_id]
  170.       next unless state.is_a?(RPG::State)
  171.       next unless (state.zero_hp || state.autolife?)
  172.       if state.autolife?
  173.         self.hp += state.autolife_hp(maxhp)
  174.         self.sp += state.autolife_sp(maxsp)
  175.       end
  176.       remove_state(state.id, true)
  177.     end
  178.     self.animation_id = RPG::State::AutoRevive::Animation_ID
  179.     self.damage       = RPG::State::AutoRevive::DisplayText
  180.     self.damage_pop   = true
  181.   end
  182.   #-----------------------------------------------------------------------------
  183.   # * Autolife State ?
  184.   #-----------------------------------------------------------------------------
  185.   def autolife_state?
  186.     @states.each {|i| return true if $data_states[i].autolife?}
  187.     false
  188.   end
  189.   #-----------------------------------------------------------------------------
  190.   # * Autolife Dead ?
  191.   #-----------------------------------------------------------------------------
  192.   def autolife_dead?
  193.     self.dead? && self.autolife_state?
  194.   end
  195. end
  196.  
  197. #===============================================================================
  198. # ** Game_Party
  199. #===============================================================================
  200.  
  201. class Game_Party
  202.   #-----------------------------------------------------------------------------
  203.   # * Alias Listing
  204.   #-----------------------------------------------------------------------------
  205.   alias_method :autolife_gmparty_alldead?, :all_dead?
  206.   #-----------------------------------------------------------------------------
  207.   # * All Dead ?
  208.   #-----------------------------------------------------------------------------
  209.   def all_dead?
  210.     @actors.each {|a| return false if a.autolife_state?}
  211.     autolife_gmparty_alldead?
  212.   end
  213.   #-----------------------------------------------------------------------------
  214.   # * Autolife Effect
  215.   #-----------------------------------------------------------------------------
  216.   def autolife_effect
  217.     @actors.each {|a| if a.autolife_dead? ; a.autolife_effect ; end}
  218.   end
  219. end
  220.  
  221. #===============================================================================
  222. # ** Game_Troop
  223. #===============================================================================
  224.  
  225. class Game_Troop
  226.   #-----------------------------------------------------------------------------
  227.   # * Autolife Effect
  228.   #-----------------------------------------------------------------------------
  229.   def autolife_effect
  230.     @enemies.each {|e| if e.autolife_dead? ; e.autolife_effect ; end}
  231.   end
  232. end
  233.  
  234. #===============================================================================
  235. # ** Scene_Battle
  236. #===============================================================================
  237.  
  238. class Scene_Battle < SDK::Scene_Base
  239.   #-----------------------------------------------------------------------------
  240.   # * Alias Methods
  241.   #-----------------------------------------------------------------------------
  242.   alias_method :autolife_snbattle_judge, :judge
  243.   #-----------------------------------------------------------------------------
  244.   # * Judge
  245.   #-----------------------------------------------------------------------------
  246.   def judge
  247.     if judging_autolife?
  248.       $game_troop.autolife_effect
  249.       $game_party.autolife_effect
  250.       @status_window.refresh
  251.     end
  252.     autolife_snbattle_judge
  253.   end
  254.   #-----------------------------------------------------------------------------
  255.   # * Judging Autolife ?
  256.   #-----------------------------------------------------------------------------
  257.   def judging_autolife?
  258.     $game_party.actors.each  {|a| return true if a.autolife_dead?}
  259.     $game_troop.enemies.each {|e| return true if e.autolife_dead?}
  260.     false
  261.   end
  262. end
Expand to see the code.


Instructions

Place Above Main and Below SDK (only if using), this script DOES NOT require SDK but will log if SDK is present.

FAQ

Coming soon if any confusion arrives.

Compatibility

Compatible with or without SDK, might or might not work with certain CBS/ABS systems depending on how they're coded.

This script aliases the following methods... Spoiler
Game_Party.all_dead?
Scene_Battle.judge


Terms and Conditions

Another "Free to use in commercial and non-commercial games" script, but please don't forget to credit yours truely :thumb:
Holy shit this sounds like a good script, Kain. I've just got a couple of questions;

If Auto-life is present on an ally/enemy, if they die, and are revived... if they die AGAIN, will they come back, does this ressurection state last forever, until the state has been taken off by another skill ?

The second question... can this state be "unbuffed" in the same way as the others can ?

Thanks :thumb:
Is there a way to make this only work on a specified state if a certain items is present? For example, if you have a Phoenix Down and Knockout is inflicted, it revives the hero, but if you DON'T have a Phoenix Down, you die?

Also, line 28 is giving me massive issues. When I write 25 after the '{' (because I want 25% HP to be restored) it keeps getting a syntax error. When I don't pu8t anything, it comes up with an error saying "Line 238: TypeError occured. Undefined superclass 'Scene_Base'" I'm not using the SDK.

Original thread: https://www.hbgames.org/forums/viewtopic.php?t=66674