Record Target Variable
Version: 1.0
Author: modern algebra
Date: August 24, 2009
Version History
- <Version 1.0> 08.24.2009 - Original Release
Description
This script allows you to save the ID of an actor or enemy targetted by a skill or item to a designated variable. It is perfect for use in Common Events that are called by using items or weapons, as you can add additional effects that effect the specific target through the common event.
Note that it only works for targetted items and skills - if the scope has multiple targets, than it will not update the value.
Features
- Records the actor or enemy targetted by a skill, thus allowing you to design a common event that targets only the actor or enemy targetted by the skill
- Allows you to use a switch to record whether the target is an actor or enemy.
- Allows you to use a switch to record whether or not the target was hit by the item or skill
Instructions
Please see the header for instructions
Script
#==============================================================================
# Record Target Variable
# Version: 1.0
# Author: modern algebra (rmrk.net)
# Date: August 24, 2009
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# Description:
#
# This script allows you to save the ID of an actor or enemy targetted by a
# skill or item to a designated variable. It is perfect for use in
# Common Events that are called by using items or weapons, as you can add
# additional effects that effect the target through the common event.
#
# Note that it only works for targetted items and skills - if the scope has
# multiple targets, than it will not update the values.
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# Instructions:
#
# Place this script above Main and below Materials.
#
# To choose which variables to use for this script, go down to lines 41 & 43
# and alter the values of SELECTED_ACTOR_VARIABLE & SELECTED_ENEMY_VARIABLE.
# Note that when selecting an actor, it saves the ID of the actor, but when
# selecting an enemy, it returns the INDEX of the enemy in the troop. This
# follows the lead of event commands in how actors are selected. There are
# also two switches you can set at lines 46 & 49; TARGET_CLASS_SWITCH_ID
# records whether the user of the skill is an actor or an enemy, while
# NOHIT_SWITCH_ID records whether the target was hit by the item or skill.
#
# Using the script is fairly easy. Simply have the item or skill call a
# common event, and in that comment you can use the values of the variables
# and switches to determine the effect.
#==============================================================================
#==============================================================================
# ** Global Constants
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# new constants - RTV_SELECTED_ACTOR_VARIABLE, RTV_SELECTED_ENEMY_VARIABLE
#==============================================================================
# The ID of the variable to which the selected actor ID will be saved.
RTV_SELECTED_ACTOR_VARIABLE = 21
# The ID of the variable to which the selected enemy INDEX will be saved.
RTV_SELECTED_ENEMY_VARIABLE = 22
# The ID of a switch which tells if the target of a skill is an actor or an enemy
# ON => Enemy is target; OFF => Actor is target
RTV_TARGET_CLASS_SWITCH_ID = 23
# The ID of a switch which records whether or not the skill or item hit its
# target. ON => Target missed; OFF => Target hit
RTV_NOHIT_SWITCH_ID = 24
#==============================================================================
# ** Game_Battler
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# Summary of Changes:
# aliased method - item_effect, skill_effect
#==============================================================================
class Game_Battler
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Item Effect
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
alias modnalgb_st_efctitm_actrvar_0bg3 item_effect
def item_effect (user, item, *args)
# Run Original Method
modnalgb_st_efctitm_actrvar_0bg3 (user, item, *args)
rtv_set_target_to_variable (item)
end
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Skill Effect
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
alias algabramod_skleffect_rtv_3jc2 skill_effect
def skill_effect (user, skill, *args)
# Run Original Method
algabramod_skleffect_rtv_3jc2 (user, skill, *args)
rtv_set_target_to_variable (skill)
end
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Set Target to Variable
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def rtv_set_target_to_variable (item)
if item.for_one?
if self.actor?
$game_variables[RTV_SELECTED_ACTOR_VARIABLE] = self.id
$game_switches[RTV_TARGET_CLASS_SWITCH_ID] = true
else
$game_variables[RTV_SELECTED_ENEMY_VARIABLE] = self.index
$game_switches[RTV_TARGET_CLASS_SWITCH_ID] = false
end
$game_switches[RTV_NOHIT_SWITCH_ID] = @missed || @evaded
end
end
end
Credit
Support
Please report any bugs in this topic.
Known Compatibility Issues
No currently identified compatibility issues
This script by
modern algebra is licensed under a
Creative Commons Attribution-Non-Commercial-Share Alike 2.5 Canada License.