Apologies. This took me a few minutes to work out, but I'm necroposting for the sake of hopefully helping others because Google always points searchers of this topic here.
When using this idea for monsters counter-attacking, I ran into problems. The solution I had (using Visustella Battle Core and Auto Skill Triggers) was to modify the Damage Algorithm to store the index of the user in a game variable.
Auto Skill Triggers selects a random target among the valid ones. This set up makes it a guaranteed counter attack against the attacker (barring some janky logic error). I also think that using the Visustella ABS System might mess with some of the above, which is why I was struggling to get it properly working.
The game I'm working on has no player counter attacks, so I
JavaScript:
if (user.isActor())
{$gameVariables.setValue(1, user.index());}
Then, modifying it to fit Neo Soul Gamer's code above (NSG's code was genius)...
JavaScript:
// Set skill as a counter attack
<Auto Trigger: Attack Target>
<JS Targets>
// Clears all targets
targets = [];
// Get the index of the last actor to attack as stored in damage algorithm
let eIndex = $gameVariables.value(1);
// Adds the actor that acted last to the pool of available targets
targets.push($gameParty.members()[eIndex])
</JS Targets>
Monster counter attacks the correct attacker every time now.