Referencing the current battle target in a common event?

I'm using Yanfly's action sequences to perform common events in battles to do some heavy scripting, but there's one issue I keep running into...


I'm currently "faking it" when it comes to determining which enemy is targeted: I have the action sequences inflict an invisible state called "targeted" to the enemy, then I remove the state at the end of the attack via action sequences. I then use a conditional in the common event that says "If enemy #__ is affected by targeted", etc.


This DOES allow me to specify which target will be affected by the common event (and the skill that initiated it), but it requires being somewhat sloppy in that I'll need to include the aforementioned conditional 8 times to cover all the bases.


Is there an easier way to simply tell the game (even in a script command) that the effect will happen to the current target of the ability, rather than need to use the conditional 8 times?


Thanks in advance!
I have no idea how yanfly's action sequences works, however this code:


BattleManager._action._targetIndex


Will return, in a common event called by a skill, the index of the target of the current action. Only for single target spells. Indexes start at 0 for the first enemy/actor in the troop/party. (It will return -1 for group cast spells.)


Give it a try. There is no guarantee it will work with yanfly's plugins, but it sure does in my vanilla project.
I have no idea how yanfly's action sequences works, however this code:



BattleManager._action._targetIndex


Will return, in a common event called by a skill, the index of the target of the current action. Only for single target spells. Indexes start at 0 for the first enemy/actor in the troop/party. (It will return -1 for group cast spells.)


Give it a try. There is no guarantee it will work with yanfly's plugins, but it sure does in my vanilla project.



That does indeed work, thank you!


My next question would be what the script call is for playing an animation on the enemy index that corresponds to that variable...
For a comprehensive list of script call equivalents of event commands, please check this google doc:


https://docs.google.com/spreadsheets/d/1-Oa0cRGpjC8L5JO8vdMwOaYMKO75dtfKDOetnvh7OHs/edit?pref=2&pli=1#gid=0


Following that you should use:


$gameTroop.members()[enemyIndex].startAnimation(animationId, bool, delayN);
//set bool to true if you want the animation mirrored
//set delay to how much you want the animation to be delayed by (in frames)
//you can omit bool and delayN
//example:
$gameTroop.members()[0].startAnimation(1);
//will play animation 1 on the first enemy in the current group


Again, this is for a vanilla project, no guarantees it will work with yanfly's plugin.
For a comprehensive list of script call equivalents of event commands, please check this google doc:


https://docs.google.com/spreadsheets/d/1-Oa0cRGpjC8L5JO8vdMwOaYMKO75dtfKDOetnvh7OHs/edit?pref=2&pli=1#gid=0


Following that you should use:



$gameTroop.members()[enemyIndex].startAnimation(animationId, bool, delayN);
//set bool to true if you want the animation mirrored
//set delay to how much you want the animation to be delayed by (in frames)
//you can omit bool and delayN
//example:
$gameTroop.members()[0].startAnimation(1);
//will play animation 1 on the first enemy in the current group


Again, this is for a vanilla project, no guarantees it will work with yanfly's plugin.



Perfect.


And no worries on Yanfly: Yanfly is only telling it where to begin the common event in this case. The rest is all vanilla. 🙂
For a comprehensive list of script call equivalents of event commands, please check this google doc:


https://docs.google.com/spreadsheets/d/1-Oa0cRGpjC8L5JO8vdMwOaYMKO75dtfKDOetnvh7OHs/edit?pref=2&pli=1#gid=0


Following that you should use:



$gameTroop.members()[enemyIndex].startAnimation(animationId, bool, delayN);
//set bool to true if you want the animation mirrored
//set delay to how much you want the animation to be delayed by (in frames)
//you can omit bool and delayN
//example:
$gameTroop.members()[0].startAnimation(1);
//will play animation 1 on the first enemy in the current group


Again, this is for a vanilla project, no guarantees it will work with yanfly's plugin.



Ack, one more thing: can I replace the enemy index number with a variable, and if so, how would I do that?


Thanks again. 🙂
I'm going to sound like a broken record and direct you to the google doc again 🙂  .


I don't grasp exactly what you mean, is it putting the index in a variable and then displaying the anim on the number stored in that variable?


If it is:


$gameVariables.setValue(your_variable_id,value) // this will set the variable to value
//so with the first script call you can store the index in it.
$gameVariables.value(your_variable_id) //this will return the value inside the variable

//example:
$gameVariables.setValue(1,BattleManager._action._targetIndex) // variable 1 now contains the index of target enemy/actor
$gameTroop.members()[$gameVariables.value(1)].startAnimation(1); //this will play the animation on the actor/enemy index contained in variable 1


Should work.
I'm going to sound like a broken record and direct you to the google doc again 🙂  .


I don't grasp exactly what you mean, is it putting the index in a variable and then displaying the anim on the number stored in that variable?


If it is:



$gameVariables.setValue(your_variable_id,value) // this will set the variable to value
//so with the first script call you can store the index in it.
$gameVariables.value(your_variable_id) //this will return the value inside the variable

//example:
$gameVariables.setValue(1,BattleManager._action._targetIndex) // variable 1 now contains the index of target enemy/actor
$gameTroop.members()[$gameVariables.value(1)].startAnimation(1); //this will play the animation on the actor/enemy index contained in variable 1


Should work.





Yup, you got it in one. 🙂 (sorry, I'm still more than a bit inept when it comes to javascript...)


Thanks again so much!
...And I can also just replace $gameVariables.value(1) with BattleManager._action._targetIndex and it works just fine for specifying which enemy is targeted.


Though, I'll likely use both commands at a future time so I needed to learn all of this anyway. 🙂

Original thread: https://forums.rpgmakerweb.com/threads/referencing-the-current-battle-target-in-a-common-event.64068/