HOW TO DETECT IF AN ENEMY IS TARGETTED? [VXA]

Posts

Pages: 1
Hi!

I'd like to make a troop where one enemy will activate a 'substitute' state when the certain VIP enemy os targetted by the player. I would've just had substitue active all the time, but there are three enemies, and I want them to substitute only when the VIP is attacked, and not when the other non-VIP is. I hope I made sense there...

Is this possible? I'd rather have script calls over script edits though, if it can be done.

Thank you!
If this is just for one boss fight I would do this via battle events. The easiest way is to check whether or not the VIP's HP are below 100%.

You can check the last target of an actor in a script, but I haven't gotten it to work yet and I don't have the time now, sorry. I'm pretty new to the RGSS.
Asgar, I want the non-vip to go and use 'substitute' only when the Vip is targetted. If I do it via battle events (like I first did), the non-vip will substitute After the VIP is attacked. I want him to do it Before.

Something like this:
*Player-"I will attack you, VIP!"
*screams* *rushes to VIP*
*Non-VIP stepps in between them and takes the blow instead*
NV: "DENIEEEED!!!"
Yeah. Like this.

But thanks anyway :)
So basically, once your character executes the attack, the non-vip reacts?

Some clarifications:

Does this also happen when using AoE or random targeting, or a confused ally attacks the vip?

I assume you want the substitute only be active during this one attack?

Now that I think about it, it might be easier to make a custom substitute state that just works with one ally.

I'll look into it.

EDIT: And done.
I'm positive this can be done more elegantly/sensibly, but this hacked-together version should be alright if you just need it for a single battle.

First insert a new page called Game_BattlerBase in the script section between Materials and (Insert Here). Copy the following script into the page.

#==============================================================================
# ** Game_BattlerBase
#------------------------------------------------------------------------------
#  This base class handles battlers. It mainly contains methods for calculating
# parameters. It is used as a super class of the Game_Battler class.
#==============================================================================

class Game_BattlerBase
  attr_accessor :vip        # vip to protect
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  alias initialize_default initialize
  def initialize
    initialize_default
    @vip = nil
  end
  #--------------------------------------------------------------------------
  # * Determine if Substitute
  #--------------------------------------------------------------------------
  def substitute?
    (special_flag(FLAG_ID_SUBSTITUTE) || @vip ) && movable?
  end
end

Then add another page called Scene_Battle and copy this into it:

#==============================================================================
# ** Scene_Battle
#------------------------------------------------------------------------------
#  This class performs battle screen processing.
#==============================================================================

class Scene_Battle < Scene_Base
  #--------------------------------------------------------------------------
  # * Apply Substitute
  #--------------------------------------------------------------------------
  def apply_substitute(target, item)
    if check_substitute(target, item)
      substitute = target.friends_unit.substitute_battler
      if substitute && target != substitute && (substitute.vip == target || !substitute.vip)
        @log_window.display_substitute(substitute, target)
        return substitute      
      end
    end
    target
  end
end

You just have to add this in a script call at battle start:

$game_troop.members[a].vip = $game_troop.members[b]

a is the index of the substitute and b is the index of the vip. The index just conforms to the order in which the enemies were added afaik, starting with 0.

Note that the substitute only works if the vip has less than 25% health, like with the normal substitute. (The tooltip in the database is apparently wrong, in case you don't know that)

Also, this is hacked together and not well-tested, just a quick solution. It worked as intended for me in a vacuum, but if you have other enemies with a normal substitute something might get wonky or there might be problems with other scripts that override the BattlerBase or Scene-Battle classes.
Thank you Asgar!
This'll be useful indeed.
I'll report back here if I find any game-breaking bugs.
Pages: 1