MV End the users current turn with a script call

For some context I have a mechanic which applies a "doom" state to an actor which ticks down in real time and kills the actor when it hits zero.
I want to be able to end the actors turn if this happens while a player is selecting an action.
Its important to note that this code is not being called as part of the event loop, its running as part of a sprite update for the timer display.

Here are some of the things that I've tried, all of which softlock the game:

`SceneManager._scene.onSelectAction()`

`SceneManager._scene.selectNextCommand()`

`BattleManager.selectNextCommand()`


With a skill at id 8 which does nothing and targets user (also tried with it setting tp so it wasnt completely empty)
```
let actor = BattleManager.actor();
actor.forceAction(8, 0);
BattleManager.forceAction(actor);
$gameTroop._interpreter.setWaitMode('action');
BattleManager._phase = 'action';
```

With YEP_BattleEngineCore:
```
let actor = BattleManager.actor();
BattleManager._phase = 'action';
BattleManager.queueForceAction(actor, 8, actor);
BattleManager._phase = 'action';
```

Everything I've tried results in the game hanging in the action phase and not starting the enemies turn. If anyone has encountered this same problem and has an implementation I would love to hear it.
The turn based battles of the RMs have a selection phase and an execution phase that are visible to the player, but there is a step between that, and I think that is where your problems come from.

In the selection phase the actions for both actors and enemies are determined.
but before they can be executed, they need to be sorted.
each action gets a number that is basically battler.agi plus skill.speed plus a random percentage, and then everything gets sorted from highest number to lowest.
and after that the actions get executed in whatever battlesystem or sequence you have in the next phase.

This means that you cannot execute a force action or anything else during selection phase - to do that you would have to have the equivalent to VXAce Yanfly script "instant action" - I don't know if that was ever ported to MV.

And if you try to remove the actor in the selection phase that probably crashes the sorting depending on how that is done (I never checked the MV code for details). So if you try that you have to have something in the action list for the battler that does nothing or suicides him.


Personally I guess you either have to modify the selection code a lot, or abandon the idea of real-time death during selection. Either way I hope the info above helps you a bit.
Well to be honest I was really hoping someone had an implementation already, I thought maybe "end the players turn" would be a pretty common need but maybe not.

Thank you for your response though, I was unaware of the selection phase, its likely that the YEP CTB plugin we're using changes how that works quite a bit.

If I get it working I'll post in this thread so that anyone else looking for the same thing has a code snippet to use.
Turns out I was closer than I thought.
The following code works:
JavaScript:
Scene_Battle.prototype.passTurn = function() {
    this.forceSkillOnCurrentActor(8);
};

Scene_Battle.prototype.forceSkillOnCurrentActor = function(skillId) {
    let action = BattleManager.inputtingAction();
    action.setSkill(skillId);
    BattleManager.actor().setLastBattleSkill($dataSkills[skillId]);
    this._actorCommandWindow.active = false;
    this.onSelectAction();
};

Where skill 8 is an empty skill set up like this:
1663558476665.png


There are probably other ways you could do this but the important thing that I was missing is setting the actorCommandWindow to inactive ie `this._actorCommandWindow.active = false;`

This is because updateBattleProcess will only run as long as no input windows are active, and even though onSelectAction hides the window it for some reason doesnt set it to inactive (could be one of my plugins who knows)

Anyway I tested this on a default project and it works as long as you're on the actor select window and not the party select window, hopefully thats helpful to someone.

Original thread: https://forums.rpgmakerweb.com/threads/end-the-users-current-turn-with-a-script-call.151378/