Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

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

Code:
#===============================================================================

# ** States : Auto-Life

#===============================================================================

 

#-------------------------------------------------------------------------------

# * SDK Log

#-------------------------------------------------------------------------------

if Object.const_defined?(:SDK)

  SDK.log('States.Auto-Life', 'Kain Nobel ©', 3.5, '2009.08.12')

end

 

#===============================================================================

# ** RPG::State::AutoRevive

#===============================================================================

 

module RPG::State::AutoRevive

  #-----------------------------------------------------------------------------

  # * State IDs

  #-----------------------------------------------------------------------------

  State_IDs     = []

  #-----------------------------------------------------------------------------

  # * Damage String displayed during Auto-Revive animation

  #-----------------------------------------------------------------------------

  DisplayText   = "Auto-Revive!"

  #-----------------------------------------------------------------------------

  # * Font Name for damage display

  #-----------------------------------------------------------------------------

  Font_Name     = "Arial Black"

  #-----------------------------------------------------------------------------

  # * Font Size for damage display

  #-----------------------------------------------------------------------------

  Font_Size     = 40

  #-----------------------------------------------------------------------------

  # * Color for text background

  #-----------------------------------------------------------------------------

  Color_Back    = Color.new(255, 255, 0)

  #-----------------------------------------------------------------------------

  # * Color for text face

  #-----------------------------------------------------------------------------

  Color_Main    = Color.new(255,255,255)

  #-----------------------------------------------------------------------------

  # * Animation

  #     state_id => animation_id

  #-----------------------------------------------------------------------------

  Animation_ID  = 26

  #-----------------------------------------------------------------------------

  # * HP Percent Recovered from Auto-Revive state

  #     state_id => value (Integer)

  #-----------------------------------------------------------------------------

  HP_Percent    = {

  }

  #-----------------------------------------------------------------------------

  # * HP Directly Recovered from Auto-Revive state

  #     state_id => value (Integer)

  #-----------------------------------------------------------------------------

  HP_Direct     = {

  }

  #-----------------------------------------------------------------------------

  # * SP Percent Recovered from Auto-Revive state

  #     state_id => value (Integer)

  #-----------------------------------------------------------------------------

  SP_Percent    = {

  }

  #-----------------------------------------------------------------------------

  # * SP Directly Recovered from Auto-Revive state

  #     state_id => value (Integer)

  #-----------------------------------------------------------------------------

  SP_Direct     = {

  }

  #-----------------------------------------------------------------------------

  # * Is this state auto-removed when battler is revived?

  #     state_id => true / false

  #-----------------------------------------------------------------------------

  AutoRemove    = {

  #17 => false

  }

  #-----------------------------------------------------------------------------

  # * Item to lose, if it applies to this state

  #     state_id => [item_id, quantity]

  #     state_id => item_id

  #-----------------------------------------------------------------------------

  LoseItem      = {

  }

  #-----------------------------------------------------------------------------

  # * Default Settings

  #-----------------------------------------------------------------------------

  HP_Percent.default  = 0

  SP_Percent.default  = 0

  HP_Direct.default   = 0

  SP_Percent.default  = 0

  AutoRemove.default  = true

  LoseItem.default    = 0

end

 

#===============================================================================

# ** RPG::State

#===============================================================================

 

class RPG::State

  #-----------------------------------------------------------------------------

  # * Autolife ?

  #-----------------------------------------------------------------------------

  def autolife?

    AutoRevive::State_IDs.include?(id)

  end

  #-----------------------------------------------------------------------------

  # * Autolife HP

  #-----------------------------------------------------------------------------

  def autolife_hp(max)

    value = 0

    if AutoRevive::HP_Percent[id].is_a?(Numeric)

      if AutoRevive::HP_Percent[id] > 0

        value = max * (AutoRevive::HP_Percent[id] / 100.0)

      end

    end

    if AutoRevive::HP_Direct[id].is_a?(Numeric)

      value += AutoRevive::HP_Direct[id]

    end

    Integer([value, 1].max)

  end

  #-----------------------------------------------------------------------------

  # * Autolife SP

  #-----------------------------------------------------------------------------

  def autolife_sp(max)

    value = 0

    if AutoRevive::SP_Percent[id].is_a?(Numeric)

      if AutoRevive::SP_Percent[id] > 0

        value = max * (AutoRevive::SP_Percent[id] / 100.0)

      end

    end

    if AutoRevive::SP_Direct[id].is_a?(Numeric)

      value += AutoRevive::SP_Direct[id]

    end

    Integer(value)

  end

  #-----------------------------------------------------------------------------

  # * Autolife Remove?

  #-----------------------------------------------------------------------------

  def autolife_remove?

    (autolife? && AutoRevive::AutoRemove[id])

  end

  #-----------------------------------------------------------------------------

  # * Autolife Item ID?

  #-----------------------------------------------------------------------------

  def autolife_item_id?

    item = AutoRevive::LoseItem[id]

    if item.is_a?(Array)

      item = item[0]

    end

    (item.is_a?(Integer) ? item : false)

  end

  #-----------------------------------------------------------------------------

  # * Autolife Item Quant?

  #-----------------------------------------------------------------------------

  def autolife_item_quant?

    return 0 unless autolife_item_id?

    quant = 0

    if AutoRevive::LoseItem[id].is_a?(Array)

      quant = AutoRevive::LoseItem[id][1]

    end

    (quant.is_a?(Integer) ? quant : 1)

  end

end

 

    

#===============================================================================

# ** RPG::Sprite

#===============================================================================

 

class RPG::Sprite

  #-----------------------------------------------------------------------------

  # * Alias Listing

  #-----------------------------------------------------------------------------

  alias_method :autolife_rpgsprite_damage,      :damage

  #-----------------------------------------------------------------------------

  # * Damage

  #-----------------------------------------------------------------------------

  def damage(value, critical)

    if value != RPG::State::AutoRevive::DisplayText

      autolife_rpgsprite_damage(value, critical)

      return

    end

    dispose_damage

    bitmap = Bitmap.new(160, 48)

    bitmap.font.name = RPG::State::AutoRevive::Font_Name

    bitmap.font.size = RPG::State::AutoRevive::Font_Size

    bitmap.font.color = RPG::State::AutoRevive::Color_Back

    bitmap.draw_text(-1, 12-1, 160, 36, value, 1)

    bitmap.draw_text(-1, 12+1, 160, 36, value, 1)

    bitmap.draw_text(1, 12-1, 160, 36, value, 1)

    bitmap.draw_text(1, 12+1, 160, 36, value, 1)

    bitmap.font.color = RPG::State::AutoRevive::Color_Main

    bitmap.font.size = RPG::State::AutoRevive::Font_Size * 0.9

    bitmap.draw_text(0, 12, 160, 36, value, 1)

    @_damage_sprite = ::Sprite.new(self.viewport) 

    @_damage_sprite.bitmap = bitmap 

    @_damage_sprite.ox = 80 

    @_damage_sprite.oy = 0 

    @_damage_sprite.x = self.x 

    @_damage_sprite.y = self.y - self.oy / 2 

    @_damage_sprite.z = 10000

    @_damage_duration = 40 

  end 

end

 

#===============================================================================

# ** Game_Battler

#===============================================================================

 

class Game_Battler

  #-----------------------------------------------------------------------------

  # * Autolife Effect

  #-----------------------------------------------------------------------------

  def autolife_effect

    return unless self.autolife_dead?

    @states.each do |state_id|

      state = $data_states[state_id]

      next unless state.is_a?(RPG::State)

      next unless (state.zero_hp || state.autolife?)

      if self.is_a?(Game_Actor)

        item, quant = state.autolife_item_id?, state.autolife_item_quant?

        if item && quant > 0

          next unless $game_party.item_number(item) >= quant

        end

        $game_party.lose_item(item, quant)

      end

      if state.autolife?

        self.hp += state.autolife_hp(maxhp)

        self.sp += state.autolife_sp(maxsp)

      end

      remove_state(state.id, true) if state.autolife_remove?

    end

    self.animation_id = RPG::State::AutoRevive::Animation_ID

    self.damage       = RPG::State::AutoRevive::DisplayText

    self.damage_pop   = true

  end

  #-----------------------------------------------------------------------------

  # * Autolife State ?

  #-----------------------------------------------------------------------------

  def autolife_state?

    @states.each {|i| return true if $data_states[i].autolife?}

    false

  end

  #-----------------------------------------------------------------------------

  # * Autolife Dead ?

  #-----------------------------------------------------------------------------

  def autolife_dead?

    self.dead? && self.autolife_state?

  end

end

 

#===============================================================================

# ** Game_Party

#===============================================================================

 

class Game_Party

  #-----------------------------------------------------------------------------

  # * Alias Listing

  #-----------------------------------------------------------------------------

  alias_method :autolife_gmparty_alldead?, :all_dead?

  #-----------------------------------------------------------------------------

  # * All Dead ?

  #-----------------------------------------------------------------------------

  def all_dead?

    @actors.each {|a| return false if a.autolife_state?}

    autolife_gmparty_alldead?

  end

  #-----------------------------------------------------------------------------

  # * Autolife Effect

  #-----------------------------------------------------------------------------

  def autolife_effect

    @actors.each {|a| if a.autolife_dead? ; a.autolife_effect ; end}

  end

end

 

#===============================================================================

# ** Game_Troop

#===============================================================================

 

class Game_Troop

  #-----------------------------------------------------------------------------

  # * Autolife Effect

  #-----------------------------------------------------------------------------

  def autolife_effect

    @enemies.each {|e| if e.autolife_dead? ; e.autolife_effect ; end}

  end

end

 

#===============================================================================

# ** Scene_Battle

#===============================================================================

 

class Scene_Battle < SDK::Scene_Base

  #-----------------------------------------------------------------------------

  # * Alias Methods

  #-----------------------------------------------------------------------------

  alias_method :autolife_snbattle_judge, :judge

  #-----------------------------------------------------------------------------

  # * Judge

  #-----------------------------------------------------------------------------

  def judge

    if judging_autolife?

      $game_troop.autolife_effect

      $game_party.autolife_effect

      @status_window.refresh

    end

    autolife_snbattle_judge

  end

  #-----------------------------------------------------------------------------

  # * Judging Autolife ?

  #-----------------------------------------------------------------------------

  def judging_autolife?

    $game_party.actors.each  {|a| return true if a.autolife_dead?}

    $game_troop.enemies.each {|e| return true if e.autolife_dead?}

    false

  end

end

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.

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:
 

Jason

Awesome Bro

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.
 
What if I have an armor with this state, will it still work? And if it does.. will the character who has the armor on be revived over and over again?

Great script.

-Krobelus


[Edit] I get the Line 238 error as well.
 
@Everybody : The line 238 error is a silly remnant of SDK coding that I forgot to remove, there is no harm in deleting the "< SDK::Scene_Base" from that line because its not important to this particular script.

@jbrist : "Reguard as HP 0" states and autolife states are all removed automatically when the battler dies, and is revived. I suppose I could put in a setting where certain states override this action, meaning they're permanent or must be removed by skills/items. Thanks for asking I'll have to add that feature to the script!

@MCsephiroth13 : Nah I didn't put anything like that in this version, but that would be another good feature! I'll try and find some time to add that into the script later this week.

@Krobelus : If an autolife state is assigned to your armor's auto-states then it'll be added when you equip that piece of armor. I'm pretty sure, if you die and come back with said auto-life state (from the armor) then it'll be removed after that, instead of it being permanent because of the armor but I haven't tested that. Sounds like the suggestion would work similiar to jbrist's so I'm gonna add that too!

EDIT : UPDATED! Nothing important has changed, just added a couple features! Enjoy :thumb:
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top