The RPG Maker Resource Kit

RMRK RPG Maker Creation => VX Ace => VXA Scripts Database => Topic started by: TDS on February 19, 2012, 11:28:02 PM

Title: Item Target Effects
Post by: TDS on February 19, 2012, 11:28:02 PM
Item Target Effects
Version: 1.0
Author: TDS
Date: February 19, 2012

Version History



Description


This script allows you to add effects such as "Recover HP" or "Run common event" for specific actors or enemies when using skills or items on them.

Features


Instructions

Just put the script on the materials area of the script editor and follow the instructions on the script.

Script


Code: [Select]
#==============================================================================
# ** TDS Item Target Effects
#    Ver: 1.0
#------------------------------------------------------------------------------
#  * Description:
#  This script allows you to set specific effects for selected targets.
#------------------------------------------------------------------------------
#  * Features:
#  Allows you to set on use effects for specific enemies or actors for skills
#  and items.
#------------------------------------------------------------------------------
#  * Instructions:
#  To add a on use effect to a skill or item add this to it's notebox:
#
#  ACTOR_X_EFFECT: code data_id value1 value2
#  ENEMY_X_EFFECT: (Same as above, but for enemies)
#
#  X: is the ID of the target (ACTOR_1_EFFECT)

#  code : the code effect ID. For example 11 is recover HP.
#  (The list can be found on the Game_BattlerBase and Game_Battler constants list)
#
#  data_id : the id used by the effect if applicable (For skills, states, common events)
#
#  value1: value in % percent for the effect. (Can be positive or negative)

#  value2: solid value for effect. (Can be positive or negative)
#
#  Example:
#
#  ACTOR_1_EFFECT: 11 0 0 500
#
#  This example would restore 500 extra HP when the item/skill is used on them.
#------------------------------------------------------------------------------
#  * Notes:
#  None.
#------------------------------------------------------------------------------
# WARNING:
#
# Do not release, distribute or change my work without my expressed written
# consent, doing so violates the terms of use of this work.
#
# If you really want to share my work please just post a link to the original
# site.
#
# * Not Knowing English or understanding these terms will not excuse you in any
#   way from the consequenses.
#==============================================================================


#==============================================================================
# ** Game_Battler
#------------------------------------------------------------------------------
#  This class deals with battlers. It's used as a superclass of the Game_Actor
# and Game_Enemy classes.
#==============================================================================

class Game_Battler < Game_BattlerBase
  #--------------------------------------------------------------------------
  # * Alias Listings
  #-------------------------------------------------------------------------- 
  alias tds_target_item_effects_game_battler_item_apply            item_apply 
  #--------------------------------------------------------------------------
  # * Apply Item Effect
  #--------------------------------------------------------------------------
  def item_apply(user, item)
    # Run Original Method
    tds_target_item_effects_game_battler_item_apply(user, item)
    # If Item was successfully used
    if @result.hit?
      # Make Target Effects Array
      effects = []
      # Get Regexp Header
      header = self.actor? ? "ACTOR" : "ENEMY"
      # Get ID
      id =  self.actor? ? self.id : self.enemy_id
      # Go Through Items Notes and Match Text
      item.note.scan(/#{header}_#{id}_EFFECT: (?'code'[0-9]+) (?'data_id'[0-9]+) (?'value1'[-0-9]+) (?'value2'[-0-9]+)/) {|t|
        # Get Match Information
        m = Regexp.last_match
        # Add Effect to Target Effects Array
        effects << RPG::UsableItem::Effect.new(m[:code].to_i, m[:data_id].to_i, m[:value1].to_i, m[:value2].to_i)
      }
      # Apply Actor Effects
      effects.each {|effect| item_effect_apply(user, item, effect)}
    end
  end
end

Credit



Thanks


Support


On this topic.

Known Compatibility Issues

None that I know of so far.


Author's Notes


With this script I decided to try something different in the regular expression by using the naming feature rather than $1 $2 etc. Also just in case anyone misses it in the instructions you can find the effect code list on the "Game_BattlerBase" and "Game_Battler" scripts.

Restrictions

Only for use in non-commercial games.
Title: Re: Item Target Effects
Post by: modern algebra on February 20, 2012, 11:13:28 PM
Nice little script there TDS :)