Trying to end battle when MP is full - how to set MP at 0 automatically?

Yeah so as I said in the title lol. I'm trying to make an "emotional" damage bar, where you gotta convince or hype up your enemies enough to defeat them. Enemies can do it too, and I'm trying to make it so you need to be hyped up enough (e.g. have enough MP) to use powerful skills, but not so much you pass out. This is why I'm trying to do it with MP instead of TP.

I'm testing my idea with this plugin by Moogle, and I changed the script so in theory you'd die at your max MP instead of at 0:

Code:
Moogle_X.DieZeroMp.Game_BattlerBase_refresh =
        Game_BattlerBase.prototype.refresh;
Game_BattlerBase.prototype.refresh = function() {
        Moogle_X.DieZeroMp.Game_BattlerBase_refresh.call(this);
        if (this._mp === this._mmp && this.canDieAtZeroMp()) {
                this.addState(this.deathStateId());
        }
};

The problem is that for some reason, it simply doesn't work lol. The plugin runs when using other variables (like current MP or HP) so I dunno why it doesn't run when actor/enemy reaches max MP. Should I just use another plugin or maybe there's some way to do it just with reg. eventing? I'm very new to JS lol, so sorry if it turns out I'm doing something dumb 😛. Thanks for any possible help!!
this._mp === this._mmp
did you try this.mp and this.mmp? ._mp is a property for current mp and would be equivalent in most circumstances, but _mmp should be undefined
I see how you cud theoretically fake this wid eventing😅 Just set up yo troop events so that at battle start, erryone's MP is zero. Then check MP at every turn end, and if the MP is zero, eliminate whoever the poor sap is? The caveat is, it wud only activate at turn end, but maybe you cud roll wid it

EDIT: I mean, eliminate the poor sap when MP is full 👋
did you try this.mp and this.mmp? ._mp is a property for current mp and would be equivalent in most circumstances, but _mmp should be undefined
I haven't, actually. I knew mmp meant max mp (at least in formula syntax) so I thought it'd work in JS too. Didn't know the underscore in the function was important.
I see how you cud theoretically fake this wid eventing😅 Just set up yo troop events so that at battle start, erryone's MP is zero. Then check MP at every turn end, and if the MP is zero, eliminate whoever the poor sap is? The caveat is, it wud only activate at turn end, but maybe you cud roll wid it

EDIT: I mean, eliminate the poor sap when MP is full 👋
Ooooh, that sounds like the easiest option. I'll deffo try it, thx!!

@Oroworo , please avoid double posting, as it is against the forum rules. You can use the "Edit" function on your posts to add additional information you've forgotten or respond to multiple people. You can review our forum rules here. Thank you.



I haven't, actually. I knew mmp meant max mp (at least in formula syntax) so I thought it'd work in JS too. Didn't know the underscore in the function was important.
the formula *is* javascript and anything that'd work in js works in a formula.

its just that battler.mp is really a function that returns battler._mp, which is a property representing the current mp. battler.mmp is a function that returns the battler's max mp, which is its own function. there is no ._mmp property
Double-post notice: @Oroworo


the formula *is* javascript and anything that'd work in js works in a formula.

its just that battler.mp is really a function that returns battler._mp, which is a property representing the current mp. battler.mmp is a function that returns the battler's max mp, which is its own function. there is no ._mmp property
I finally got it to work!! 😀😀

If anyone's curious, here's the modified script:

Code:
Moogle_X.DieZeroMp.Game_BattlerBase_refresh =
        Game_BattlerBase.prototype.refresh;
Game_BattlerBase.prototype.refresh = function() {
        Moogle_X.DieZeroMp.Game_BattlerBase_refresh.call(this);
        if (this._mp === this.mmp && this.canDieAtZeroMp() && $gameParty.inBattle() &&  $gameTroop.turnCount() > 0) {
                this.addState(this.deathStateId());

I added those checks so that KO can only occur in battle. I'll probably have to mod it later if I want overworld damage or something, but honestly I'm pretty proud of what I did, even if it's just a line of code. Thanks for the help!!

Original thread: https://forums.rpgmakerweb.com/threads/trying-to-end-battle-when-mp-is-full-how-to-set-mp-at-0-automatically.182007/