document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. //=============================================================================
  2. // AutoLife.js
  3. //=============================================================================
  4.  
  5. /*:
  6.  * @plugindesc Allows one or more states to automatically revive a dead player.
  7.  * @author whitesphere
  8.  *
  9.  * @param Default Revive Formula
  10.  * @desc If set, determines how much HP is granted upon the character\'s revival.
  11.  * Otherwise, defaults to 20% of the character\'s MHP.
  12.  * @default a.mhp / 4
  13.  *
  14.  * @param Revive Animation ID
  15.  * @desc The animation which is used when a character is auto-revived.
  16.  * @default 49
  17.  *
  18.  * @help The formula is evaluated the same way the Damage formula is. The parameter "a"
  19.  * represents the Actor.  When the character dies, if s/he has an Auto-Life
  20.  * state active.  The formula\'s result becomes the character\'s HP.
  21.  * All states and buffs are lost, since the character technically did die.
  22.  *
  23.  * ============================================================================
  24.  * Notetags
  25.  * ============================================================================
  26.  *
  27.  *
  28.  * State specific Notetag:
  29.  *  <autolife>
  30.  *  Defines this State as an auto-life state
  31.  *
  32.  * <autolife_formula: (formula)>
  33.  *  Defines this State as an auto-life state, using the specified formula to calculate
  34.  *  the amount of HP granted on character death.
  35.  *
  36.  * <autolife_animation: (id)>
  37.  * Defines this state as an auto-life state and uses the specified animation ID  
  38.  * if this auto-life state is used.
  39.  *
  40.  * <autolife_add_states: (id 1, id 2, ... id n)>
  41.  * If the auto-life state is used, all of the states in the comma-separated list are
  42.  * added.  Allows a character to get stronger after death, or be weaker when revived.
  43.  */
  44. (function() {
  45.  
  46. WS_AutoLife = {};
  47.  
  48. WS_AutoLife.Parameters = PluginManager.parameters(\'AutoLife\');
  49. WS_AutoLife.Param = {};
  50.  
  51. //=============================================================================
  52. // The plug-in parameters
  53. //=============================================================================
  54. WS_AutoLife.Param.formula = WS_AutoLife.Parameters[\'Default Revive Formula\'];
  55. WS_AutoLife.Param.animationID = parseInt(WS_AutoLife.Parameters[\'Revive Animation ID\']);
  56.  
  57. //=============================================================================
  58. // Handle the auto-life states
  59. //=============================================================================
  60. Auto_Life = function() {
  61. }
  62.  
  63. //=============================================================================
  64. // Returns a state ID for the first auto-life found in the battler
  65. // or null if none is found.
  66. //=============================================================================
  67. Auto_Life.prototype.getAutoLifeState = function(battler) {
  68.         state_list=battler.states();
  69.         for (lifeIndex=0; lifeIndex<state_list.length; lifeIndex++) {
  70.             current_state=state_list[lifeIndex];
  71.             meta=current_state.meta;
  72.             if (!meta)
  73.             {
  74.                 continue;
  75.             }
  76.             if (meta.autolife || meta.autolife_formula || meta.autolife_animation) {
  77.                 return current_state;
  78.             }
  79.         }
  80.         return null;
  81. }
  82.  
  83.  
  84. //=============================================================================
  85. // Applies the given auto-life state to a battler.  This:
  86. // 1. Removes all buffs and states
  87. // 2. Removes all auto-life states
  88. // 3. Sets the HP to the result of the auto-life formula
  89. // This call assumes the battler\'s HP is set to 0.
  90. //=============================================================================
  91. Auto_Life.prototype.applyAutoLife = function(battler, state_obj) {
  92.     meta=state_obj.meta;
  93.     if (!meta || (!meta.autolife
  94.         && !meta.autolife_formula && !meta.autolife_animation)) {
  95.         return;
  96.     }
  97.     battler.clearStates();
  98.     battler.clearBuffs();
  99.     hp_to_add=1;
  100.     autolife_function=WS_AutoLife.Param.formula;
  101.     if (meta.autolife_formula && meta.autolife_formula != "")
  102.         autolife_function=meta.autolife_formula;
  103.     try
  104.     {
  105.         var a=battler;
  106.         hp_to_add=Math.round(eval(autolife_function));
  107.     }
  108.     catch (e) {
  109.     }
  110.     if (hp_to_add < 1)
  111.         hp_to_add=1;
  112.     if (!state_obj.meta.autolife_animation)
  113.         animation_id=WS_AutoLife.Param.animationID;
  114.     else
  115.         animation_id=parseInt(state_obj.meta.autolife_animation);
  116.     if (animation_id)
  117.         battler.startAnimation(animation_id, false, 120);
  118.     battler.eraseState(battler.deathStateId());
  119.     battler._hp=hp_to_add;
  120.     if (state_obj.meta.autolife_add_states) {
  121.         state_list=state_obj.meta.autolife_add_states.split(",");
  122.         for (state_index=0; state_index<state_list.length; state_index++) {
  123.             battler.addState(parseInt(state_list[state_index]));
  124.         }
  125.     }
  126. }
  127.  
  128. //=============================================================================
  129. // Game_Battler
  130. //=============================================================================
  131.  
  132.  
  133. var WS_AL_GB_die=Game_BattlerBase.prototype.die;
  134. //=============================================================================
  135. // See if the damage would make the battler Dead.  If so,
  136. // see if we have any Auto Life states.
  137. //=============================================================================
  138.  Game_BattlerBase.prototype.die = function() {
  139.    
  140.     if (!this._autoLife) {
  141.         this._autoLife=new Auto_Life();
  142.     }
  143.     /* Auto life state will trigger here if there is one */
  144.     state_id=this._autoLife.getAutoLifeState(this);
  145.     if (state_id !== null) {
  146.         this._autoLife.applyAutoLife(this, state_id);
  147.         return;
  148.     }
  149.     WS_AL_GB_die.call(this, arguments);
  150. }
  151.  
  152.  
  153. })();
  154. //=============================================================================
  155. // End of File
  156. //=============================================================================
');