Forcing to Ignore wait for action in battle

Soulrender

Jack Of All Trades
Veteran
Joined
Jan 12, 2019
Messages
838
Reaction score
467
First Language
Poland
Primarily Uses
RMMV
I added to Scene_Battle button that suposed to run common event showing choices for player whetter he want's to abort battle or not and everything is fine, except one detail, Common Event is executed AFTER selecting one of battle commands (Attack, Guards, skills etc).

How to force to run Common event regardless of action input, like on Scene_Map?
 

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
2,072
Reaction score
1,493
First Language
EN
Primarily Uses
RMMZ
You could try saving this as a .js file and importing it as a plugin:
JavaScript:
BattleManager.updateEvent = function() {
  if (this.isActionForced()) {
    this.processForcedAction();
    return true;
  } else {
    return this.updateEventMain() || this.checkAbort();
  }
};
This is an override for the default BattleManager.updateEvent method without any battle phase checks (cf paragraph & spoiler below). Slight warning: this might cause undesired effects...I'm not entirely sure why events are restricted to run only in certain phases. :kaoswt:

Technical explanation: the flow of battle is directed by the BattleManager, which only considers event updates in specific phases of battle, namely "start", "turn", and "turnEnd". Player input is considered during the "input" phase: what you're seeing is the event getting queued until the phase changes from "input" to "turn".

Supporting core script excerpts (rpg_managers.js) plus some comments:
JavaScript:
BattleManager.update = function() {
    if (!this.isBusy() && !this.updateEvent()) {  // update event
        switch (this._phase) {
        case 'start':
            this.startInput();
            break;
        case 'turn':
            this.updateTurn();
            break;
        case 'action':
            this.updateAction();
            break;
        case 'turnEnd':
            this.updateTurnEnd();
            break;
        case 'battleEnd':
            this.updateBattleEnd();
            break;
        }
    }
};

BattleManager.updateEvent = function() {
    switch (this._phase) {  // only start, turn, turnEnd phases
        case 'start':
        case 'turn':
        case 'turnEnd':
            if (this.isActionForced()) {
                this.processForcedAction();
                return true;
            } else {
                return this.updateEventMain();  // main event update stuff here
            }
    }
    return this.checkAbort();
};

BattleManager.updateEventMain = function() {
    $gameTroop.updateInterpreter();  // update event interpreter
    $gameParty.requestMotionRefresh();
    if ($gameTroop.isEventRunning() || this.checkBattleEnd()) {
        return true;
    }
    $gameTroop.setupBattleEvent();
    if ($gameTroop.isEventRunning() || SceneManager.isSceneChanging()) {
        return true;
    }
    return false;
};
 

Soulrender

Jack Of All Trades
Veteran
Joined
Jan 12, 2019
Messages
838
Reaction score
467
First Language
Poland
Primarily Uses
RMMV
@caethyril thank you for claryfing some things, but that update does not work. Even though I have installed HIME_CommonEventQueue plugin, but your code is placed at the bottom of plugin manager, so it's overriding default BM methods
 

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
2,072
Reaction score
1,493
First Language
EN
Primarily Uses
RMMZ
I should've known the battle system wouldn't give up so easily. :kaosigh:

I did a bit of looking through the code and it seems the battle scene only updates the manager under specific conditions. It looks like events are limited to certain phases because of input window restrictions? Seeing the way it's set up, I feel like it may be less challenging to add a new window to the scene and code it like that. :kaoswt2:

...it's late here right now, so I'm going to bed. :kaoslp:
 

Soulrender

Jack Of All Trades
Veteran
Joined
Jan 12, 2019
Messages
838
Reaction score
467
First Language
Poland
Primarily Uses
RMMV
@caethyril - I also did notice that... Let me rephrase question then, because of Scene_Battle design (HUD, game resolution etc) I had to remove Escape command from Window_Command and I need a button allowing a player to do with single click. I used for that @Aloe Guvner plugin VirtualButtons, wich allows to run common event or custom JS code. So for test run in my JS class I wrote this:
Code:
Soulrender.prototype.askForEscape = function(){

    var mainOptions = ["Abort Battle", "Continue"];
    $gameMessage.setChoicePositionType(1);
    $gameMessage.setChoiceBackground(0);
    $gameMessage.setChoices(mainOptions, 0);
    $gameMessage.setChoiceCallback(function(responseIndex)
    {
        switch (responseIndex){
        
            case 0:{
                BattleManager.processAbort();
            }
            
            case 1:{
                //BattleManager.startInput();
                /***********************/
            }                        
        }
    });
}
And that code is executed right away, but the other problem is at "case 1:" what to put there so the battle commands will apear again and battle won't be suspended in "limbo" :]
(Game_Interpreter.prototype.setWaitMode('message') don't work)
 

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
2,072
Reaction score
1,493
First Language
EN
Primarily Uses
RMMZ
Oh, neat! I think you just need to reopen the command window. I tried this sort of thing and it seemed to work OK:
JavaScript:
Soulrender.prototype.askForEscape = function() {
    var mainOptions = ["Abort Battle", "Continue"];
    var sc = SceneManager._scene, W;
    ['_partyCommandWindow', '_actorCommandWindow'].some(function(w) {
        if (sc[w] && !sc[w].isClosed()) return W = sc[w], true;
        return false;
    });
    $gameMessage.setChoicePositionType(1);
    $gameMessage.setChoiceBackground(0);
    $gameMessage.setChoices(mainOptions, 0);
    $gameMessage.setChoiceCallback(function(responseIndex) {
        switch (responseIndex) {
            case 0:
                BattleManager.processAbort();
                break;
            case 1:
                if (W) W.open();
                break;
        }
    });
};
I.e. get the current command window beforehand, then reopen it if "Continue" is chosen. The scene automatically reopens the status window (see spoiler below), but doesn't bother to track the command windows (I assume that's because choices normally can't display when those are open). :kaophew:
JavaScript:
Scene_Battle.prototype.updateStatusWindow = function() {
    if ($gameMessage.isBusy()) {
        this._statusWindow.close();
        this._partyCommandWindow.close();
        this._actorCommandWindow.close();
    } else if (this.isActive() && !this._messageWindow.isClosing()) {
        this._statusWindow.open();
    }
};
 

Soulrender

Jack Of All Trades
Veteran
Joined
Jan 12, 2019
Messages
838
Reaction score
467
First Language
Poland
Primarily Uses
RMMV
@caethyril Yes!! That works perfectly as I wanted. As a token of my graditute, please accept this girl with
beer :)
Screenshot_1.png
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

SF_Monster6 added!

Wonder when the next theme contest is coming?
Long time no see. I'm aiming a vertical slice / tech demo for my game featuring a series of boss battles this month. I hope I could get some testers.
So which forum do I use if I want to showcase graphics? I've been using AML forum, but I'm not sure it's correct.

Forum statistics

Threads
105,781
Messages
1,016,455
Members
137,481
Latest member
Tippiexd
Top