MV When any actor's HP drops to x%, actor with the ID y immediately acts (STB)

Hey everyone, I'm trying to make a passive ability for one of my characters, but I'm not sure where to even put the code for it.

I'm using Yanfly's Standard Turn Battle plugin.

When any actor in the party has their HP lowered to 30% of max HP, actor with the ID of 1 will immediately act, no matter if it has already acted on that turn or not. This can only happen 1 time per battle.

This is the effect that I'm looking for and I'm pretty sure it's possible because I did a similar thing in a previous post, but that won't work for this case because I can't put this in a skill's note section like I did there.

My coding knowledge is next to none, so after a bit of research I tried to put some things in troops battle event pages but the effect either doesn't work, crashes the game, only funcions after everyone has acted on that turn, etc.
There's also the problem that by default you can't make it so battle events trigger after certain actors or enemies act.

My latest attempt (in a script command in a battle event):

const actors = $gameParty.battleMembers();
const targetActor = actors.find(actor => actor.hp / actor.mhp <= 0.3);

if (targetActor && !$gameSwitches.value(1)) {
$gameTemp.reserveCommonEvent(7);
BattleManager.forceAction($gameActors.actor(2));
BattleManager.inputtingAction().setTarget(target);
$gameSwitches.setValue(1, true);
BattleManager.processTurn();
}

I'm thinking about trying to do this with states instead but im not sure how or with what plugins yet, can someone help me or at least point me in the right direction?
Have you tried doing this with troop events?
I do something similar.

On turn 0, if a switch is on, I add a state to an actor

On troop event (span: Battle) when actor HP <= 30%
Conditional branch: If actor has state then force action.
Remove state


Edit: And then you can use a base troop plugin so these troop events happen for all troops without you having to copy/paste these troop event pages
Have you tried doing this with troop events?
I do something similar.

On turn 0, if a switch is on, I add a state to an actor

On troop event (span: Battle) when actor HP <= 30%
Conditional branch: If actor has state then force action.
Remove state


Edit: And then you can use a base troop plugin so these troop events happen for all troops without you having to copy/paste these troop event pages
Using troop battle event with a switch to give actor with the ID of 1 a certain state could be a start

But for the "when actor HP <= 30%" part i will need to make a different troop event page for every actor in the party, no?

Also what plugin do you recommend for the troop events playing in every battle?
Yes, you would need a troop event page for each actor when his/her HP <= 30%

For base troop plugin, I go with YEP
Yes, you would need a troop event page for each actor when his/her HP <= 30%

For base troop plugin, I go with YEP
Ok, everything is working except the actual code that makes the actor act immediately.

I'm calling a common event when a character is at 30% or less hp and switch that checks if the ability has already been triggered is OFF, and in in the common event I'm calling the code using a script command and using other unrelated commands like setting that switch to ON.

-----

This is what I have in the script command, nothing happens:

BattleManager.forceAction($gameActors.actor(2));
BattleManager.inputtingAction().setTarget(target);
BattleManager.processTurn();

What should I put here?
Hmm I've looked at a few things around the forums and this... http://yanfly.moe/2017/08/16/discontinued-battle-plugins-for-atb-ctb-and-stb/ (middle of the first paragraph)

and it would seem that forced actions don't work in the STB. Dunno if there's a way around it either since it's hardcoded within the plugin it seems. Or I could be wrong in how I'm reading this since there's an update mentioning fixing something involving Forced Actions.
Ah, that would suck if forced action don't work.

I was going to suggest why use common event at all? Instead, you could try putting the force action command directly in the troop event that's being triggered.
I do know with other battle systems how to basically give yourself a free turn on command based on whatever code you use to trigger it, but I dunno if that's possible with the STB. I'd say put the force action in the troops thing like @TESTOSTERONE mentioned, but that's just forcing an action and not giving you a direct fresh turn where you can do whatever. Unless you're ok with the actors forcing a specific skill instead.
Hmm I've looked at a few things around the forums and this... http://yanfly.moe/2017/08/16/discontinued-battle-plugins-for-atb-ctb-and-stb/ (middle of the first paragraph)

and it would seem that forced actions don't work in the STB. Dunno if there's a way around it either since it's hardcoded within the plugin it seems. Or I could be wrong in how I'm reading this since there's an update mentioning fixing something involving Forced Actions.
I know it's possible to force a turn with STB, I managed to get that effect with a skill and a state in a previous post, in fact this only worked on STB and not DTB:

And @TESTOSTERONE I chose to use a common event just to organize myself better, I tested the code directly both in the common event and directly in the troop event and it makes no difference.

Now I just need to figure out the code I need for the desired effect, right now what the code is doing is skipping the turn of actor ID 1 enterely and immediately sending him to the next turn.
good to know I was wrong in how I read that then in this instance then. makes me wonder why Yanfly would mention forced actions then if they still actually work. unfortunately, I don't quite know why the code isn't working tho outside of I don't know the STB turn structure as well compared to say the ATB or OTB.
I don't think the code you have up there is related to what you want to accomplish.

Force Action is to force a battler to perform a specific, predetermined action.

In order for the BattleManager.forceAction() method to do something, you must first queue a forced action onto the battler with Game_Battler.forceAction(). However, this entire thing isn't what you said you want to do - you don't have a specific thing you want to make the actor do, you want them to get an extra turn.

That's nothing to do with Force Action. I would try:
Code:
BattleManager._subject=$gameActors.actor(2);
BattleManager.startSTBInput();
I don't think the code you have up there is related to what you want to accomplish.

Force Action is to force a battler to perform a specific, predetermined action.

In order for the BattleManager.forceAction() method to do something, you must first queue a forced action onto the battler with Game_Battler.forceAction(). However, this entire thing isn't what you said you want to do - you don't have a specific thing you want to make the actor do, you want them to get an extra turn.

That's nothing to do with Force Action. I would try:
Code:
BattleManager._subject=$gameActors.actor(2);
BattleManager.startSTBInput();
ITS DONE!

Tysm, the code you said here softlocked the game but by adding one command at the end it works perfectly

-----

Final result:

BattleManager._subject=$gameActors.actor(2);
BattleManager.startSTBInput();
BattleManager.processTurn();

-----

Again, this code is in a script call in a troop event page, with the settings conditions: of "Actor x HP <= y%" and span: "battle"

Original thread: https://forums.rpgmakerweb.com/threads/when-any-actors-hp-drops-to-x-actor-with-the-id-y-immediately-acts-stb.158963/