Battle end when a party member loses

Hi everyone,

I'm new to the forums, so I hope I've placed this thread in the right place. I am trying to make a game for the RPG birthday event, but I've run into a problem. I am wanting to make it that, if any of your party members lose in battle, it ends the game (game over).

Any ideas as to what I should do? I've tried a few things but none of them have worked.
Quite simple, really.
You just need to make a battle event in the troop trees with the condition set to Actor HP = 0. Make one tab for each character. Also set it to Moment so that it happens instantly.
It'll look something like this:
8e6183065b0c2ade26ce6e76a7af1799.png
If you need this for every battle, you can use a plugin.
Here's one I wrote just now (haven't tested it):

Code:
(function() {
BattleManager.checkBattleEnd = function() {
    if (this._phase) {
        if (this.checkAbort()) {
            return true;
        } else if ($gameParty.deadMembers().length) {
            this.processDefeat();
            return true;
        } else if ($gameTroop.isAllDead()) {
            this.processVictory();
            return true;
        }
    }
    return false;
};
})();

If any member dies in any battle, the battle is lost.
Normally, this means a game over, unless the battle was started through an event and you chose "can lose".
@The Mighty Palm Thanks for the quick reply. I am using side view battle and when I do that, it doesn't do the normal battle loss like when your whole party loses (character that lost falls over, collapse SE sound plays and defeat ME plays). I wanted it to look the same as when you lose normally.
@Nolonar Thanks for that. How do I save it as a plugin? (Sorry, I'm new to this)
In your project folder there should be a "js" folder. Inside it, there's a "plugins" folder.
You can create a ".js" file and put the code inside. The simplest way is to make a copy of an existing ".js" file, open the copy with Notepad (or Notepad++) and replace its content with the code (don't forget to save and rename your file).

In RMMV you need to open the plugin manager (it's the button with the jigsaw icon).
The plugin manager should have a couple of basic plugins listed. If you click below the last plugin, the empty row should be highlighted.
Just double click that empty line to open the plugin selection window.

There is a selectbox under "Name:" where you'll select the plugin (do you still remember the file's name?)
Make sure "Status:" is "ON".
@Nolonar Thanks. It worked! (Yay!)

Original thread: https://forums.rpgmakerweb.com/threads/battle-end-when-a-party-member-loses.91836/