RMRK is retiring.
Registration is disabled. The site will remain online, but eventually become a read-only archive. More information.

RMRK.net has nothing to do with Blockchains, Cryptocurrency or NFTs. We have been around since the early 2000s, but there is a new group using the RMRK name that deals with those things. We have nothing to do with them.
NFTs are a scam, and if somebody is trying to persuade you to buy or invest in crypto/blockchain/NFT content, please turn them down and save your money. See this video for more information.
Record Target Variable 1.0

0 Members and 1 Guest are viewing this topic.

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Most Mature Member2012 Favorite Staff Member2012 Best RPG Maker User (Scripting)2012 Best MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Use of Avatar and Signature Space2011 Best RPG Maker User (Scripting)2011 Most Mature Member2011 Favourite Staff Member2011 Best Veteran2010 Most Mature Member2010 Favourite Staff Member
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


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


  • modern algebra

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.
« Last Edit: February 11, 2010, 09:49:12 PM by Modern Algebra »

********
Resource Artist
Rep:
Level 94
\\\\\
Project of the Month winner for June 2009
:O Now I can properly event a sweet ass Steal Skill, amongst other awesome things! Thanks MA! :D

***
Rep:
Level 82
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 :-)

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Most Mature Member2012 Favorite Staff Member2012 Best RPG Maker User (Scripting)2012 Best MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Use of Avatar and Signature Space2011 Best RPG Maker User (Scripting)2011 Most Mature Member2011 Favourite Staff Member2011 Best Veteran2010 Most Mature Member2010 Favourite Staff Member
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.
« Last Edit: April 18, 2010, 08:47:58 PM by modern algebra »

**
Rep:
Level 81
?????????????
;D ;D ;D MODERN ALGEBRA... YOU ARE THE BEST... ;D ;D ;D
遠い銀河からのスーパー戦士。
本は、セバスチャンです。
これは強力で、手に負えない。
彼の物理レベルのスキルは驚嘆です。[/b]