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 : Critical Condition

States : Critical Condition
Version: 3.5
By: Kain Nobel

Introduction

With this system, you can control states that should be added or removed automatically when an actor or enemy reaches 1/4 HP. A basic example would be; when [Battler]'s HP is critical, give [Battler] this [State].

To put it in more lamens terms, lets say Basil has reached HP critical (his health is yellow instead of white), you can set the script to automatically give him something like "Str+" state, or something else like "Fatiqued" state. It us up to your imagination what kind of states you want to give actors or enemies when they're in critical condition, and you can specify multiple status ailments to add or remove if you'd like.

Another thing to note, states added through critical condition are handled special from states added through otherwise normal means. In other words, if [Battler] gets [State] through HP critical and not normal means, the state won't be removable until his HP is back to normal again since it was added under this circumstance. The only exception to this is if state is supposed to be removed when battle ends (and you've set RemoveStatesBattle true).

Lastly, yes this does comply with stats that are supposed to be removed after X turns and all that jazz, but the states will still remain until after HP is back to normal again. Basically, only when HP is critical will these states be un-removable, otherwise if your HP isn't critical they're now removable by thier natural means.

Features

  • You can set states to add to battlers when their HP is critical
  • You can also set states to remove when HP is critical
  • "Critical condition" states can't be removed while HP is still critical

Script

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

# ** States : Critical Condition

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

 

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

# * SDK Log

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

if Object.const_defined?(:SDK)

  SDK.log('States.CriticalCondition', 'Kain Nobel ©', 3.5, '2009.09.09')

end

 

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

# ** CriticalConditionStates

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

 

module CriticalConditionStates

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

  # * IDs of states to add to actor when their HP is critical

  #     {actor_id => state_id, ...}                   # Add single state

  #     {actor_id => [state_id, ...], ...}            # Add list of states

  #     {actor_id => -state_id, ...}                  # Remove single state

  #     {actor_id => [-state_id, ...], ...}           # Remove list of states

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

  Actor = {

  1 => 1,

  2 => [1, -2]

  }

  Actor.default = []

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

  # * IDs of states to add to enemy when their HP is critical

  #     {actor_id => state_id, ...}                   # Add single state

  #     {actor_id => [state_id, ...], ...}            # Add list of states

  #     {actor_id => -state_id, ...}                  # Remove single state

  #     {actor_id => [-state_id, ...], ...}           # Remove list of states

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

  Enemy = {

  }

  Enemy.default = []

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

  # * Allow removal of states that are supposed to be removed when battle ends?

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

  RemoveStatesBattle = true

end

 

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

# ** Game_Battler

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

 

class Game_Battler

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

  # * Public Instance Variables

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

  attr_accessor :critical_states_plus   # When HP critical these states added

  attr_accessor :critical_states_minus  # When HP critical these states removed

  attr_reader   :critical_states_array  # States added through HP critical

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

  # * Alias Listings

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

  alias_method :criticalstates_gmbattler_initialize,  :initialize

  alias_method :criticalstates_gmbattler_hpset,       :hp=

  alias_method :criticalstates_gmbattler_addstate,    :add_state

  alias_method :criticalstates_gmbattler_remstate,    :remove_state

  alias_method :criticalstates_gmbattler_remstbtl,    :remove_states_battle

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

  # * Object Initialization

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

  def initialize(*args)

    # The usual

    criticalstates_gmbattler_initialize(*args)

    # Get states to add when HP critical

    @critical_states_plus   = self.get_critical_states_plus

    # Get states to remove when HP critical

    @critical_states_minus  = self.get_critical_states_minus

    # Get reserve array for critical states

    @critical_states_array  = Array.new

    # Default critical state modding flag to false

    @modding_critical_state = false

  end

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

  # * HP = (HP)

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

  def hp=(hp)

    # Get HP before changes

    last_hp = self.hp

    # Set HP as usual

    criticalstates_gmbattler_hpset(hp)    

    # Set flag to notify that states activity is HP critical related

    @modding_critical_state = true

    # If HP is less than 1/4 and wasn't already less than 1/4

    if (self.hp <= self.maxhp / 4) && (last_hp > self.maxhp / 4)

      # Remove all critical states that are to be removed

      self.critical_states_minus.each {|state_id| self.remove_state(state_id)}

      # Add all critical states that are to be added

      self.critical_states_plus.each {|state_id| self.add_state(state_id)}

    # Else if HP more than critical HP

    else

      # For each state to be added due to being critical

      @critical_states_plus.each do |state_id|

        # Delete state from critical states array

        @critical_states_array.delete(state_id)

        # Skip state if waiting for automatic removal

        next if @states_turn[state_id] > 0

        # Remove state

        self.remove_state(state_id)

      end

    end

    # Default critical state activity flag back to false

    @modding_critical_state = false

  end

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

  # * Add State

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

  def add_state(state_id)

    # If state added because HP critical

    if @modding_critical_state

      # Unless critical states array already includes this state

      unless @critical_states_array.include?(state_id)

        # Add this state to the array

        @critical_states_array << state_id

      end

    # Else if adding state normally

    else

      # Delete this state from critical state array

      @critical_states_array.delete(state_id)

    end

    # The usual

    criticalstates_gmbattler_addstate(state_id)

  end

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

  # * Remove State

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

  def remove_state(state_id)

    # If state was removed because HP critical

    if @modding_critical_state

      # Delete this state from critical states array

      @critical_states_array.delete(state_id)

    end

    # End method and disallow removal of state if added through HP critical

    return if @critical_states_array.include?(state_id)

    # The usual

    criticalstates_gmbattler_remstate(state_id)

  end

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

  # * Get Critical States Plus

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

  def get_critical_states_plus(const)

    # Create empty array

    arr = Array.new

    # If setting for battler is a positive integer

    if const[id].is_a?(Integer) && const[id] > 0

      # Add state ID to array

      arr << const[id]

    # Else if setting is an array of state IDs

    elsif const[id].is_a?(Array)

      # Add each positive state ID to plus array

      const[id].each {|state_id| arr << state_id if state_id > 0}

    end

    # Return all state IDs to be added

    arr

  end

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

  # * Get Critical States Minus

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

  def get_critical_states_minus(const)

    # Create empty array

    arr = Array.new

    # If setting for battler is a negative integer

    if const[id].is_a?(Integer) && const[id] < 0

      # Convert state ID to positive number, add to array

      arr << -const[id]

    # Else if setting is an array of state IDs

    elsif const[id].is_a?(Array)

      # For each negative state ID, conver to positive add to array

      const[id].each {|state_id| arr << -state_id if state_id < 0}

    end

    # Return all state IDs to be removed

    arr

  end

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

  # * Remove States Battle

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

  def remove_states_battle

    # Set flag to true to allow natural end-of-battle state removal

    @modding_critical_state = true

    # The usual

    criticalstates_gmbattler_remstbtl

    # Default critical state activity flag back to false

    @modding_critical_state = false

  # This method is only alias defined if RemoveStatesBattle flag is true

  end if CriticalConditionStates::RemoveStatesBattle

end

 

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

# ** Game_Actor

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

 

class Game_Actor < Game_Battler

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

  # * Get Critical States Plus

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

  def get_critical_states_plus

    # Super call with proper constant

    super(CriticalConditionStates::Actor)

  end

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

  # * Get Critical States Minus

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

  def get_critical_states_minus

    # Super call with proper constant

    super(CriticalConditionStates::Actor)

  end

end

 

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

# ** Game_Enemy

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

 

class Game_Enemy < Game_Battler

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

  # * Get Critical States Plus

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

  def get_critical_states_plus

    # Super call with proper constant

    super(CriticalConditionStates::Enemy)

  end

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

  # * Get Critical States Minus

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

  def get_critical_states_minus

    # Super call with proper constant

    super(CriticalConditionStates::Enemy)

  end

end

 

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

# ** Scene_Battle

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

 

class Scene_Battle

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

  # * Alias Listings

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

  alias_method :criticalstates_snbattle_update, :update

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

  # * Update

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

  def update

    # The usual

    criticalstates_snbattle_update

    # unless critical condition states have already been triggered

    unless @_critical_condition_states_triggered

      # For each actor, set its HP to its HP just to trigger critical states

      $game_party.actors.each  {|a| a.hp = a.hp}

      # For each enemy, set its HP to its HP just to trigger critical states

      $game_troop.enemies.each {|e| e.hp = e.hp}

      # Set flag to prevent repeat of this process

      @_critical_condition_states_triggered = true

    end

  end

end

Instructions

Place Above Main (Below SDK if Using)

FAQ

Example syntax is already shown in the setup section of the script, but for the sanity of those that might be confused by this feel free to read the following if you're confused. Please note that all the examples are generic examples from the XP/VX default databases. Also, please note that the settings for Actor and Enemy follow the same exact concept.

If you get too confused, please feel free to ask questions and I'll help you out the best I can.

With this example, [Aluxes] will gain [Poison] when his HP reaches 1/4

Code:
Actors = {

1 => 3

}

 

# 1 is Aluxes' database ID

# 3 is State's database ID
With this example, [Aluxes] will lose [Stunned] when his HP reaches 1/4

Code:
Actor = {

1 => -2

}

# 1 is Aluxes' database ID

# 2 is State's database ID

# With the value being -2, that means to remove this state
I advise you to read the first two FAQ spoilers, since this is the same thing only you're putting the states into an array instead of pointing to a single state ID. Anyways...

With this example, [Aluxes] will gain [Poison] and lose [Stunned] when his HP reaches 1/4

Code:
Actor = {

1 => [3, -2]

}

 

# 1 is Aluxes' database ID

# 3 means add Poison

# -2 means remove Stunned

Compatibility

Should be compatible with anything, works with or without SDK; didn't test VX but I believe it should work too, thats why I'm putting an XP/VX tag on it. I don't have VX on this machine though, so if you have any problems with the VX version let me know and I'll port it over to my other computer and fix it up.

Game_Battler.initialize
Game_Battler.hp=
Game_Battler.add_state
Game_Battler.remove_state
Game_Battler.remove_states_battle

Author's Notes

It took longer to comment the script and write this topic than to write the actual script itself, so I would like some questions, comments or bug reports if you happen to be checking it out, I'm pretty sure that I got it down pretty good though =P

Terms and Conditions

Another "Free to use in commercial and non-commercial games" thingy, please credit and stuff :thumb:
 
Fixed small bug with state turns, replace what you have with this version (you don't have to, its not a big deal). Basically, if actor's HP is modified and no longer critical it'll remove 'critical states' which are supposed to wait X turns.

Feedback 'n stuff would be nice =P
 
Wait this can be very useful for positive skills that kick in when your in a critical state. Wait would this be possible if an accessory of passive skill that would grant this state when your in critical condition.
 

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