[VX ACE]How to get skill user index and use "force skill" with that index

Context:
(Not that necessary, just skip to the problem)
I think that default "action patterns" function in the editor is, unreliable, at best.
I don't like many things about it, like only-one-condition rule or enemies picking action on start of the turn (so a guy whose leg I broke will use leg skill because leg was broken just now).
I also just don't... GET skill rating (I just don't, okay, I'm too dumb).

So, after I was told that I'd have to rewrite the whole engine to get rid of "leg skill with broken leg" incidents I did what, I, boy with no coding skills that does common eventing instead, does and made a common event.

And, it actually worked? Using eventing fixed all problems that I had with default pattern system.
So I playtested, made sure everything works as intended, made events for most enemies in the demo and then, finally having functional system, went on to do other stuff.

A bit later, while implementing something else, I realised that most systems that I made, while functionally and fairly flexible, were also confusing as hell to edit and ONLY fairly flexible. So I decided to rearrange things and do some more playtesting. After some time got to remaking enemy pattern system, and while playtesting, I've come to horrific, horrifying conclusion.

Normal battles were not fun at all.

Like yeah, I've got all that funky mechanics and unique encounters are mostly fun to put them to test, but all that means nothing when 90% are against enemies in very monotonous formations of like, 2 or 3 enemies, and all of them all designed to pose threat on their own, so there's not enough variability when it comes to combing them in troops.
So I decided to redesign how encounters work and make enemies more group friendly.

But that means that using "force action" function won't suffice, I just can't say "this foe will always be in index 2", there are too many formations for it to be possible. I could just brute force it and make some convoluted method with 8 events per enemy but, you know, it's not really a good solution.


Problem:
The ideal solution will look something like that:
1. Foe uses skill that runs common event
with notetags that set all the things necessary with Formula Effects;
2. One of notetags gets user's index and puts it in variable X;
3. Common event forces foe in index X to perform skill Y via script call

The problem is, I couldn't find a script calls for getting battler index or "Force action".
I won't be surprised if "get battler index" part is just not possible, so alternative methods are appreciated.
yes and no - if you understand what the index is and why it is used instead of other numbers it is rather easy to handle.

the engine can't analyse every skill ever created, and as a result it does not know the target group of a skill. It is much easier to use a double-referenced index than analysing this.

so if a skill is targeted at enemies, then the force action index is the index/array number of the enemy in the troop - first enemy, second enemy and so on.
But if the skill is targeted at the actors, then the force action index is the party index - first party member, second party member and so on.

you can determine the index only after you determine the target side - but then it is the index of the array that holds the enemies or the actors (the troop or the party)
I won't be surprised if "get battler index" part is just not possible
In that case, lemme surprise you.
Code:
$game_actors[n].index
This returns the actor index and returns nil when the actor is not in the party member, so make sure it is always in the party member.

Using script call for force action is straightforward (taken directly from Game_Interpreter)
Code:
battler = $game_troop.members[enemy_index]
battler.force_action(skill_id, target_index)
BattleManager.force_action(battler)
Fiber.yield while BattleManager.action_forced?
Replace skill_id and target_index in battler.force_action(skill_id, target_index).

For example
Code:
battler = $game_troop.members[1]
target_index = $game_actors[1].index
battler.force_action(10, target_index)
BattleManager.force_action(battler)
Fiber.yield while BattleManager.action_forced?
Whoa, that script call is exactly what I wanted, thank you!

But I think I mixed things up, again.
I don't want to get actor, but enemy index position.

What I want exactly to happen is,
foe uses skill that targets them, it gets their index and puts it in to XYZ variable.

The script call would look like this:

Ruby:
battler = [$game_variables[XYZ]]
battler.force_action(10, -2)
BattleManager.force_action(battler)
Fiber.yield while BattleManager.action_forced?

I already know about what Andar said, as I said, skill targets the user.

With Formula effects, its possible to run rather large script calls with skill BEFORE executing event, so all I need is just a script call for user's index.
it works both for actor and enemy. If I recall correctly, the damage formula is executed before the common event (I don't use a common event in skill). With that knowledge, you can use this
Code:
v[XYZ] = b.index; <damage formula>
Then the rest of the script call in the common event is like
Ruby:
battler = $game_troop.members[$game_variables[XYZ]]
battler.force_action(10, -2)
BattleManager.force_action(battler)
Fiber.yield while BattleManager.action_forced?
Holy moly it worked first time.
Thank you!

Original thread: https://forums.rpgmakerweb.com/threads/vx-ace-how-to-get-skill-user-index-and-use-force-skill-with-that-index.143028/