Forcing to Ignore wait for action in battle

Soulrender

Jack Of All Trades
Veteran
Joined
Jan 12, 2019
Messages
836
Reaction score
466
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,059
Reaction score
1,483
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
836
Reaction score
466
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,059
Reaction score
1,483
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
836
Reaction score
466
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,059
Reaction score
1,483
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
836
Reaction score
466
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 Profile Posts

Yet another gaming question, i'm currently playing Last of Us 2 and want to get another game to play next but can't decide between Ghost of Tsushima, Miles Morales & Jedi Fallen Order. After the latest mandalorian i AM on a star wars kick, but i also LOVED the last spiderman game that prequels Miles Morales. Ghost of Tsushima is the bottom of my list but i heard it was AWESOME. Just want a good story & fun gameplay.
I checked out Genshin Impact gameplay out of curiosity. I can't believe it's available as a mobile game too. Smooth animation, great music, and stellar sound effects (the ambient sounds are pretty detailed).

I'm flabbergasted to see games have becoming more and more advanced. Maybe also because I'm oblivious to current trend for a long time, it almost feel like I'm being sent into distant future. xD
xDRAGOONx wrote on WaywardMartian's profile.
Your artwork is amazing!!!
:ewat:
Stream will be live shortly with a session of the Interactive Text Adventure! Feel free to drop by!
I should finish the cat video I'm editing and finish the indesign stuff. So far only 1 is done and 4 to go

Forum statistics

Threads
105,665
Messages
1,015,384
Members
137,341
Latest member
jasapembuatanwebsite
Top