Galv’s Substitute Functionality V.1.3

Demo – Version 1.3 >

#------------------------------------------------------------------------------#
#  Galv's Cover (Substitute) Functionality
#------------------------------------------------------------------------------#
#  For: RPGMAKER VX ACE
#  Version 1.3
#  Requested by Leyla
#------------------------------------------------------------------------------#
#  2013-03-12 - Version 1.3 - added notetag to remove cover state after used
#  2013-02-17 - Version 1.2 - added option to change when cover takes effect
#  2013-02-17 - Version 1.1 - fixed a crash with attacking
#  2013-02-15 - Version 1.0 - release
#------------------------------------------------------------------------------#
#  Some extra options for the substitute feature, allowing you to specify actors
#  who cannot be covered and states that can only cover certain actors. Can also
#  make actors/enemies unable to be covered by others.
#------------------------------------------------------------------------------#
#  Notetag STATES, ACTORS or ENEMIES with:
#------------------------------------------------------------------------------#
#
#  <uncoverable>        # This actor/enemy can never be covered for.
#
#  <cover: x,x,x>       # A state, actor or enemy with this notetag AND the
#                       # substitute feature will only cover (substitute) for
#                       # friendly actors/enemies with ids listed in x's.
#
#  EXAMPLE:
#  <cover: 3,5,12,14,29>  # Only those actor ID's can be covered.
#
#  NOTE:
#  If an actor has the substitute feature or state with substitute feature and
#  does not have the <cover: x> tag on either the actor or the state then they
#  will be able to cover anybody without restriction. If the cover tag is on
#  either the actor or the state, it will use that restriction.
#
#------------------------------------------------------------------------------#
#  Notetag STATES ONLY with:
#------------------------------------------------------------------------------#
#
#  <cover_once>       # When a battler has a STATE with the substitute feature
#                     # adding this tag will mean they can only substitute once
#                     # before the state is removed.
#
#------------------------------------------------------------------------------#
#------------------------------------------------------------------------------#
#  SCRIPT CALL:
#------------------------------------------------------------------------------#
#
#  $game_actors[x].uncoverable = true/false  # change if actor can be covered
#
#------------------------------------------------------------------------------#
 
($imported ||= {})["Galv_Sub_Functions"] = true
module Galv_Sub
 
#------------------------------------------------------------------------------#
#  SETUP OPTIONS
#------------------------------------------------------------------------------#
 
  SUB_HP_PERCENT = 30      # Percent of max hp a battler has remaining before
                           # anyone will cover them using a skill. default 25.
                           # Make this 0 to use default (and to potentially work
                           # with another script that modifies this).
 
#------------------------------------------------------------------------------#
#  END SETUP OPTIONS
#------------------------------------------------------------------------------#
 
end
 
class Scene_Battle < Scene_Base
  alias galv_cant_sub_scene_battle_apply_substitute apply_substitute
  def apply_substitute(target, item)
    target.actor? ? id = target.id : id = target.enemy_id
    target.friends_unit.get_sub_target(id)
    galv_cant_sub_scene_battle_apply_substitute(target, item)
  end
 
  alias galv_cant_sub_scene_battle_check_substitute check_substitute
  def check_substitute(target, item)
    return false if cannot_sub(target)
    if Galv_Sub::SUB_HP_PERCENT > 0
      return target.hp <= target.mhp * (Galv_Sub::SUB_HP_PERCENT.to_f / 100) &&
      (!item || !item.certain?)
    end
    galv_cant_sub_scene_battle_check_substitute(target, item)
  end
 
  def cannot_sub(target)
    return true if target.uncoverable
    target.states.each {|s|
      return true if s.uncoverable
    }
    return false
  end
end # Scene_Battle < Scene_Base
 
class Window_BattleLog < Window_Selectable
  alias galv_cant_sub_window_bl_display_substitute display_substitute
  def display_substitute(substitute, target)
    galv_cant_sub_window_bl_display_substitute(substitute, target)
    substitute.states.each {|s|
      s.features.find {|sub|
        return substitute.remove_state(s.id) if sub.code == 62 &&
          sub.data_id == 2 && s.cover_once
      }
    }
  end
end # Window_BattleLog < Window_Selectable
 
class Game_Unit
 
  def get_sub_target(target_id)
    @subtarget = target_id
  end
 
#------------------------------------------------------------------------------#
#  OVERWRITE
#------------------------------------------------------------------------------#
  def substitute_battler
    members.find {|member|
      target_only = []
      member.cover.each {|id| target_only << id }
      member.states.each {|s|
        s.cover.each {|id| target_only << id}
      }
      member.substitute? if target_only.include?(@subtarget) || target_only.empty?
    }
  end
end # Game_Unit
 
class Game_Actor < Game_Battler
  attr_accessor   :uncoverable
  attr_accessor   :cover
 
  alias galv_cant_sub_actor_setup setup
  def setup(actor_id)
    @uncoverable = $data_actors[actor_id].uncoverable
    @cover = $data_actors[actor_id].cover
    galv_cant_sub_actor_setup(actor_id)
  end
end # Game_Actor < Game_Battler
 
class Game_Enemy < Game_Battler
  attr_accessor   :uncoverable
  attr_accessor   :cover
 
  alias galv_cant_sub_enemy_initialize initialize
  def initialize(index, enemy_id)
    galv_cant_sub_enemy_initialize(index, enemy_id)
    @uncoverable = $data_enemies[enemy_id].uncoverable
    @cover = $data_enemies[enemy_id].cover
  end
end # Game_Enemy < Game_Battler
 
module Galv_Substitute
  def uncoverable
    if @uncoverable.nil?
      if @note =~ /<uncoverable>/i
        @uncoverable = true
      else
        @uncoverable = false
      end
    end
    @uncoverable
  end
  def cover
    if @cover.nil?
      if @note =~ /<cover:[ ](.*)>/i
        @cover = $1.to_s.split(",").map {|i| i.to_i}
      else
        @cover = []
      end
    end
    @cover
  end
end # Galv_Substitute
 
class RPG::Actor
  include Galv_Substitute
end
class RPG::Enemy
  include Galv_Substitute
end
class RPG::State
  include Galv_Substitute
 
  def cover_once
    if @cover_once.nil?
      if @note =~ /<cover_once>/i
        @cover_once = true
      else
        @cover_once = false
      end
    end
    @cover_once
  end
end

2 thoughts on “Galv’s Substitute Functionality V.1.3

  1. Marcos Luna says:

    Sorry to bother you Galv,the demo is giving me a error in the line 44 when i use the attack command.
    Excuse me for my bad English and Thanks for this excelent script,it makes me remenber the Final Fantasy 9 passive skill “My Hero”
    Here is a screenshot of the error:

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s