Changing Substitute Conditions

Hi everyone,

I want to change the function of the Substitute special flag in RPGMaker MV. Here's my thinking on how I can get it to behave more like a typical Guard skill - that is to say, when the Guard skill is used by Actor A on Actor B, Actor A will substitute for Actor B's damage if Actor B were to receive Physical-elemental damage as a result of the enemy's attack.

From my research, this is pretty difficult to achieve.

My thinking here, is that the "Guard" skill cast by Actor A on Actor B, applies GuardStateA on Actor A and GuardState B on Actor B - both states last the same amount of time in terms of turn duration.

GuardStateA (on Actor A) enables the Substitute Special Flag for the duration of the state.

GuardStateB is an empty state that I want to use as one of the conditions under which Substitute will activate.

This would then require me to change the conditions of the Substitute Special Flag in RPGMaker MV to something like:

if attack is physical AND if target has GuardStateB applied.

I know that the conditions of Substitute can be changed, but I don't know how I would write this out (I'm not proficient in coding).

I would also like this to be in a separate plugin, I think.
To take a punt at answering my own question, would something like this work?


Code:
BattleManager.checkSubstitute = function(target) {
    return target.isStateAffected(x) && !this._action.isPhysical();
};

The thing is... I've been looking into Yanfly's Taunt plugin as well, as I will be wanting to use "Taunt" type skills in the near future. Will this affect how the default Substitute mechanic works, therefore overwriting anything I change in rpg_managers.js ?
I... really apologize for the triple post, but I thought this could be useful trying to emulate the same kind of move.

The methodology that I described in my first post worked, I just got the code wrong in the second post.

If anyone wants to create a Guard skill, it's possible by using the steps I outlined above and then changing this piece of code in rpg_manger.js:

Code:
BattleManager.checkSubstitute = function(target) {
    return target.isDying() && !this._action.isCertainHit();
};

to:

Code:
BattleManager.checkSubstitute = function(target) {
    return target.isStateAffected(x) && this._action.isPhysical();
};

Where x is the number of the GuardStateB state you apply on the particular actor you want Actor A to defend.

If you don't want this to be for physical hits, be sure to remove:

Code:
&& this._action.isPhysical()
and replace it with any criteria you like.

EDIT: I thought I would also add this in so I don't mislead anyone in my second post:

YEP's Taunt plugin doesn't seem to affect the Substitute Special Flag. I looked at the .js file and couldn't find any instance of "substitute" in the plugin file.

If anyone else think's there's anything else in this thread that could lead to stumbling blocks, please point it out!
Hey, I don't know if I can reply to old posts, but I wanted to say, you totally saved my behind. I've been looking for this for ages.

I've tried implementing functions to switch targets in the action sequence, I've tried downloading substitute-altering plug-ins, I've tried asking online, but I couldn't find this piece of information. I just tried using it in my project, and it works exactly like I wanted it to.

I don't know how longer I would have needed to go insane if I didn't find this post. So just know, your research made someone else's day a lot better. Thank you, and stay toasty.

Original thread: https://forums.rpgmakerweb.com/threads/changing-substitute-conditions.122877/