The RPG Maker Resource Kit

RMRK RPG Maker Creation => VX => VX Scripts Database => Topic started by: modern algebra on August 24, 2009, 03:25:44 AM

Title: Record Target Variable 1.0
Post by: modern algebra on August 24, 2009, 03:25:44 AM
Record Target Variable
Version: 1.0
Author: modern algebra
Date: August 24, 2009

Version History



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


Instructions

Please see the header for instructions

Script


Code: [Select]
#==============================================================================
#    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


Creative Commons License
This script by modern algebra is licensed under a Creative Commons Attribution-Non-Commercial-Share Alike 2.5 Canada License.
Title: Re: Record Target Variable 1.0
Post by: Grafikal on August 24, 2009, 05:26:08 AM
:O Now I can properly event a sweet ass Steal Skill, amongst other awesome things! Thanks MA! :D
Title: Re: Record Target Variable 1.0
Post by: ShortStar on April 18, 2010, 08:36:21 PM
Sorry to necropost, but I am having a problem. I set up the script, using all the default variables and switches. I set an item to work for one ally, and I set up a common event. Then in the game, I pick the item, and when I try to pick an ally, it refuses to let me pick one.

It did not work... until I had it do something more, so I have the item recover 1 HP and it now works :-)
Title: Re: Record Target Variable 1.0
Post by: modern algebra on April 18, 2010, 08:43:23 PM
That's just an issue with items that run common events in general. Recovering 1HP won't work if the party member is at full health I don't think. A better way, in my opinion, is just to set a parameter change (MaxHP or whatever) and set it to 0. That way, absolutely nothing happens but the item will register as having had an effect.

Another way to achieve the same effect, roughly, is to make a state and have the item apply the state, then the common event removes the state - it's also another way of determining who target is if you don't want to use this script.
Title: Re: Record Target Variable 1.0
Post by: ?????? on April 19, 2010, 02:16:36 PM
;D ;D ;D MODERN ALGEBRA... YOU ARE THE BEST... ;D ;D ;D