Im using Yanfly Buffs and States to create a set of states that lets battlers attack the same target in tandem with others based on which states they have in different situations. The states used by actors are the same as the ones used by enemies. While testing, i noticed that it works just as intended for actors but enemies attack at random. Each set of states is more or less written the same besides conditions and looks something like this:
State 1: (Has State Resist: State 3)
JavaScript:
<Custom Action Start Effect>
var action = user.currentAction();
if (action.isDamage() && action.isForOpponent()){
user._commandTarget=action._targetIndex;
for(var a=0;a < user.friendsUnit().aliveMembers().length;a++){
if(user.friendsUnit().aliveMembers()[a].isStateAffected(3)){
user.friendsUnit().aliveMembers()[a].addState(2);
}
}
}
</Custom Action Start Effect>
<Custom Remove Effect>
user._commandTarget=undefined;
</Custom Remove Effect>
State 2:
JavaScript:
<Custom Apply Effect>
BattleManager.queueForceAction(user, user._followerSkill || 137, origin._commandTarget);
user.removeState(2);
</Custom Apply Effect>
State 3: (has Resist State : State 1)
JavaScript:
Blank
This set of states makes it so that whenever a battler with state 1 makes an attack on an opponent, all allies with state 3 perform an attack on the original battler's target before the original battler makes their move, and then their move is used at the end. The user._commandTarget created whenever *actor* "X" with state 1 attacks a target returns what I want and in turn, it lets the actors with State 3 perform additional attacks on X's target before X's attack is made. However, when used by *enemy* "Y", the user._commandTarget created is -1, which makes the enemies with state 3 when Y attacks attack the party at random instead of being coordinated on the same target.
Does anyone know of a way to get the correct target index off of Y's action before it goes off so i can pass it to the other enemies and make them all attack the same target before Y's skill actually executes on that target?