MV Getting index of selected target

Hi everyone!

Currently, I'm trying to create a script inside a common event that will be called in battle.

The script inside the common event needs to identify the currently selected target by the actor, as the common event is called using the Skill after it is selected on a target by the player.

For instance, the player has chosen for Actor 1 to use "Sneeze". They have then selected their enemy target (it is a single target skill) and confirmed. When the skill is executed, it calls a common event with the script inside.

I want this script, with everything it does, to reference the selected enemy by storing that index number in a variable.

I expect the line to be something like:

$gameTroop.members()[this._gameTroop.membersId] - but I know that is unsightly, garbled and wrong.
Terribly sorry - I believe I've found the answer in my searching.

The call I need appears to be:

" BattleManager._action._targetIndex".

EDIT: This isn't... entirely accurate.

So it appears that the code I listed above only returns the index after the action has completed, which is no use if I am to run a script during the action.

I did some more searching, and found another code, so I implemented into the script like so:

Code:
var target = $gameActors.actor(actorId)._actions[actionIndex]._targetIndex;

But I couldn't get this to work either. It doesn't seem that whatever state I attempt to apply to the target is applying. Perhaps I am going about this the wrong way?

Original thread: https://forums.rpgmakerweb.com/threads/getting-index-of-selected-target.129619/