MV Triggering a skill when cancel is pressed

Hi All,

I'm trying to add a feature to my games battle system and I'm not quite sure where to find what I need. I am currently using Yanfly's ATB and what I am trying to achieve is a simple skip players turn function. And I would like to trigger it with the "cancel" button.

My thought was to basically make a command that triggered a specific skill id. And have that command be triggered by a "cancel" input while on the actors turn. So instead of choosing attack, defend, item, etc. they could press the cancel button and the actors turn would be skipped. I hope that is making sense so far.

What I think I need to know is what functions would I look at in order to place some sort of (if 'cancel' is triggered do skill "skill id") code. Or if someone has a more reasonable way of achieving this.

As always any help would be greatly appreciated.
so you also want to disable "escape battle"?
so you also want to disable "escape battle"?
That's already disabled in my game, sorry I should have mentioned that. This would just be on the player turn.
I think you need to modify this function for it
JavaScript:
Window_PartyCommand.prototype.makeCommandList = function() {
    this.addCommand(TextManager.fight,  'fight');
    this.addCommand(TextManager.escape, 'escape', BattleManager.canEscape());
};

// to

Window_PartyCommand.prototype.makeCommandList = function() {
    if (Input.isTriggered("cancel")) {
       console.log("Guard is being triggered")
    }
};

I need to see how it is done, as it is on skill ID 2, I don't know how to
get the id to use it, maybe with $dataSkills[2] but I don't know exactly
as I don't mess with the battle scene (except for the message by then).
but it should be around this.

if the above fired correctly, than we just need a way to convert it to trigger the skill.
I don't think this is working. If I just put the log command in, it posts, but not if i try to do it from a cancel input. I think this is because that function just builds the list, it doesn't actively check for the player input. But I could be wrong, my knowledge is mediocre at best
I think you need to modify this function for it
JavaScript:
Window_PartyCommand.prototype.makeCommandList = function() {
    this.addCommand(TextManager.fight,  'fight');
    this.addCommand(TextManager.escape, 'escape', BattleManager.canEscape());
};

// to

Window_PartyCommand.prototype.makeCommandList = function() {
    if (Input.isTriggered("cancel")) {
       console.log("Guard is being triggered")
    }
};

I need to see how it is done, as it is on skill ID 2, I don't know how to
get the id to use it, maybe with $dataSkills[2] but I don't know exactly
as I don't mess with the battle scene (except for the message by then).
but it should be around this.

if the above fired correctly, than we just need a way to convert it to trigger the skill.
give me a moment to test something, as I think it can be differently.
it will be an untested version as kind of busy to test around.

maybe try something like this as plugin for a test run, as the first command
window isn't guard/escape.
JavaScript:
let BattleManager_startInput = BattleManager.startInput;
BattleManager.startInput = function() {
    BattleManager_startInput.call(this);
        let p1 = $gameParty.members()[0];
        let p2 = $gameParty.members()[1];
        let p3 = $gameParty.members()[2];
        let p4 = $gameParty.members()[3];
        let any = p1 || p2 || p3 || p4;
        if (Input.isTriggered("cancel")) {
            if (any) {
                any.forceAction(2, 0);
                this.forceAction(any);
            }
        }
};

I know it isn't clean code at this point, but it could work (or not).
if it work, I try to clean up the code later for you 🙂
give me a moment to test something, as I think it can be differently.
it will be an untested version as kind of busy to test around.

maybe try something like this as plugin for a test run, as the first command
window isn't guard/escape.
JavaScript:
let BattleManager_startInput = BattleManager.startInput;
BattleManager.startInput = function() {
    BattleManager_startInput.call(this);
        let p1 = $gameParty.members()[0];
        let p2 = $gameParty.members()[1];
        let p3 = $gameParty.members()[2];
        let p4 = $gameParty.members()[3];
        let any = p1 || p2 || p3 || p4;
        if (Input.isTriggered("cancel")) {
            if (any) {
                any.forceAction(2, 0);
                this.forceAction(any);
            }
        }
};

I know it isn't clean code at this point, but it could work (or not).
if it work, I try to clean up the code later for you 🙂
Sadly, no luck. I also tried it on a fresh game, just in case there were plugin conflicts. Regardless, I appreciate all of your help.
can't help further without testing, so wait if someone with more
knowledge regarding battle/command window has more insight
for helping you.

as I'm out of idea's out of my head for this 🙂
can't help further without testing, so wait if someone with more
knowledge regarding battle/command window has more insight
for helping you.

as I'm out of idea's out of my head for this 🙂
No worries, I super appreciate you trying some things
i can look in a sec, but a quick note about the idea:
a cancel input on the actor command window is how you end up on the party command window. changing it to use the battler's guard wont leave a way to escape without adding one elsewhere

EDIT:
Save this as a .js file and add it to your project as a plugin
Code:
(function () {
    var CACW = Scene_Battle.prototype.createActorCommandWindow;
    Scene_Battle.prototype.createActorCommandWindow = function() {
    CACW.call(this);
    this._actorCommandWindow.setHandler('cancel', this.commandGuard.bind(this));
  };
})();
i can look in a sec, but a quick note about the idea:
a cancel input on the actor command window is how you end up on the party command window. changing it to use the battler's guard wont leave a way to escape without adding one elsewhere
Right now, my game doesn't use the party command window. And escape was added to the actor commands. If we can get the basic function of "hitting cancel on the actor command triggers a specific skill" working I should be able to integrate it into my game.
If we can get the basic function of "hitting cancel on the actor command triggers a specific skill" working I should be able to integrate it into my game.
i did edit it in a few min ago, but you were probably responding. refresh the page to see it
i did edit it in a few min ago, but you were probably responding. refresh the page to see it
That works! Thank you so much!!!

Original thread: https://forums.rpgmakerweb.com/threads/triggering-a-skill-when-cancel-is-pressed.175838/