Game Over when reaching 0 MP

I want to make it so that in a game Im working on if the main character ever uses all their mp then a message plays and the player is sent to the game over screen. I use to have this set up in a previous project of mine that I made in VXAce that I lost, which my current project is a remake of.

I thought it would be as simple as setting a variable to being the actors MP and then checking it with a common parallel event. If MP is equal to zero then the event triggers. Clearly I was wrong somewhere. Could someone walk me through how to do this? Is there a plugin I could use instead? Checked around but didn't find anything.
Do you want this to happen on the map, in a battle, or both? And it is only for the first actor in the party?

On the map is easy to do exactly as you described by creating a common event which continuously checks the actor's MP and sends the player to the Game Over screen if it is zero.
Note that the switch needs to be "ON" for this common event to be active.

Spoiler: On Map Parallel Event
55170-b574868a673b255f4550feff003e2f31.jpg

The battle is not as easy, I tried for a bit and there are some limitations from the editor:
  • Common Events don't extend into battles
  • Something like below has to be created for every "troop" where this check should happen
    • As far as I can tell, you can only check at the end of each turn but I haven't looked too much into it

Spoiler: In Battle Event
55171-3dfde49b00aa7c3abc8285299df9c0dc.jpg

If you need it to happen immediately during battle or would rather have a script/plugin for convenience sake, I could give it a try.
https://github.com/MoogleX/MV_Plugins/blob/master/Moogle_X_DieAtZeroMp.js

^ This may be of some help.
Thank you both for the quick replies! There is only one actor in my project, not sure if I will be adding more at any point, but always good to have the option open. The intent is for being at 0 mp to kill you both on the map and in battle. Ive tried out Moogles script and it does work rather well. Going to try to use the event method to since it allows me to sneak in a custom message when a MP related death occurs. Going to see what feels best and If I need death to be instant in combat or if its ok to happen at the end of a turn. I had forgotten to turn the switch on in my own experiments, just shows that its easy to stare oneself blind at something and miss the obvious.
I figured you may have forgotten the switch which is why I specifically mentioned it 🙂
I've made the same mistake myself several times and it's frustrating.

If you decide you want it to happen immediately in battle, you can insert the following lines of code in the MoogleX plugin at line 131.

Spoiler: Code Snippet to insert
Code:
            if ($gameSwitches.value(23)) {
                $gameMessage.setFaceImage('Actor1', 0); //img/faces file name and index of face (optional)
                $gameMessage.setBackground(1); // 0=window, 1=dim, 2=transparent (optional, default=0)
                $gameMessage.setPositionType(0); // 0=top, 1=middle, 2=bottom (optional, default=2)
                $gameMessage.add("Harold: I died because I have no MP left");
                $gameMessage.add("... now the game is over");
                $gameSwitches.setValue(23, false);
            }

Here is that snippet of code in context with the stuff around it to make sure you paste it correctly.

Spoiler: Context around Code Snippet
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 === 0 && this.canDieAtZeroMp()) {
            this.addState(this.deathStateId());
            if ($gameSwitches.value(23)) {
                $gameMessage.setFaceImage('Actor1', 0); //img/faces file name and index of face (optional)
                $gameMessage.setBackground(0); // 0=window, 1=dim, 2=transparent (optional, default=0)
                $gameMessage.setPositionType(2); // 0=top, 1=middle, 2=bottom (optional, default=2)
                $gameMessage.add("Harold: I died because I have no MP left");
                $gameMessage.add("... now the game is over");
                $gameSwitches.setValue(23, false);
            }
        }
    };

Things to note:
  • Replace the 23 with the ID# of a free switch
    • On your starting map, have an Autorun event that turns that switch to "ON"
    • Without the switch, the message gets shown when you start the game. I guess the actors get initialized with 0mp which triggers the plugin. So you need the switch to avoid that.
  • Any of the lines where I put a comment that says optional, you can take those out if you want and it'll use the default values

Disclaimer: I am pretty new to coding, so I'm sure there is a better way to do it, if anyone else wants to improve it then feel free. I did test this on both battle and map and it works.

Original thread: https://forums.rpgmakerweb.com/threads/game-over-when-reaching-0-mp.87490/