Is there a way to check which actor is being targeted?

I used Buffs & States Core (YEP) to create a state that changes a skill when given a certain state.
note tag for state: 223
<Custom Action Start Effect>
if (target.Actorid === 1) {
BattleManager.queueForceAction (target, 10, -2);
} else if (target.Actorid === 2) {
BattleManager.queueForceAction (target, 13, -2);
}
user.removeState (223);
</ Custom Action Start Effect>

But this doesn't work.
The problem is that I want to change the skill depending on who is the target when this is granted to the enemy.
For example:
If the enemy's attack target is actor ID [1], perform skill ID 10
If the enemy's attack target is actor ID [2], perform skill ID 13
I would like to be able to do this within the code of the <Custom Action Start Effect>.

I found a bit closer to this in YEP Tips & Tricks.
)

Here is the code to check if the current action is a friend.
if (action && action.isItem () && action.isForFriend ()) {

I want to confirm this by the target actor id
I changed the "action.isForFriend ()" part to "action.isActorid === 1", but nothing changed.
Please help if anyone knows how to do this!
Hi imcatman,

Have you checked if YEP_BattleAICore.js can help to do the job ? So far I've understood, you want to manipulate the enemy AI right ?

Best,
Lay.
hi
I don't want to use YEP_BattleAICore.
This is because there is no particular reason to control enemy AI in my game.
I just want to use Buffs & States Core to see which actor the enemy attack is targeting
In other words, I want to find out who the target actor of the enemy is attacking.
I want to do this within the code for the Custom Action Start Effect.
I used BattleManager._subject._lastTargetIndex; to check who the enemy is targeting on the console screen, but the number returned was -2. I couldn't know the exact actor id.
Try target.actorId() == x.
since I don't understand what you want I'm not sure I can help.

in the custom action start notetag the variables target and user both refer to the battler affected by the state.
You can get the target using user._lastTargetIndex.
Game_Battler also has a lastTargetIndex property...

when tried it the console returns the ID of the enemy I've targeted.

However, this is the game_troop ID (or game_party ID). So, you can't directly use actorId() here and see if it match.
@zaraku
I tried target.actorId () == 1. but it didn't work.

@Lay
Thx.
Changing to user._lastTargetIndex == 0. worked fine.
The enemy performed different skills depending on the actor's index. The code was as follows:

<Custom Action Start Effect>
if (user._lastTargetIndex == 0) {
BattleManager.queueForceAction (target, 10, -2);
}
</ Custom Action Start Effect>


But I want to know another way. Is there a way to reference this user._lastTargetIndex by actor id instead of index?
Probably something like user._lastTargetActorId.
Bump
bump !!
If you are savvy enough, you can look up the info yourself.

Try:

<Custom Action Start Effect>
Console.log(target);
if (user._lastTargetIndex == 0) {
BattleManager.queueForceAction (target, 10, -2);
}
</ Custom Action Start Effect>

If correct, the log should show you everything listed about the target including how they store the target's ID.

Then you can just alter your action start code to reflect that.
OK
I try first
I tried it, but got an error.
It seems to cause an error if Console.log (target); is included
png..png
I'm sorry.
You have to use lower case.
console.log(target);
I'm sorry.
You have to use lower case.
console.log(target);
I've looked into the usage in the console log and it was only _lastTargetIndex which showed the target info.

I'm sorry, I seem to have misunderstood.
I thought the code above was working fine, but all the enemies seem to use only the same skill.
In other words, it works fine until one of the enemies attacks the actor at index 0, but after attacking the index at 0, all enemies have the same skill. In other words, user_lastTargetIndex will not be reset once it gets 0, and the attack skill of the next enemy will use only the skill used for the index of 0.
After all, user_lastTargetIndex didn't seem to work well with action start.
Is there a way to reset the acquired index so that the enemy does not take over the skills of the next enemy after the enemy attacks index 0 once?
bump !

Original thread: https://forums.rpgmakerweb.com/threads/is-there-a-way-to-check-which-actor-is-being-targeted.121001/