"%1 was defeated" being overwritten?

@Trihan Because when it is not there, the actor dies on screen and then immediately gets up again and continues fighting with zero HP. At least, that's what happens if I simply remove the b.hide();
As this is an 'eject' skill, I don't want to use "apply death state 100%" as the actor is not killed, just removed from the battle.
@caethyril What happened was that at the end of the battle I just returned straight to the map with no defeat message at all.
Looks like that's because $gameParty.isAllDead() (in your damage formula) returns false for an empty battle party, e.g. if everyone's escaped. (Also, b.die() technically doesn't add the death state; b.addState(1) is more standard.)

A couple of potential workarounds:
Spoiler: idea 1
Try this damage formula instead?

b.addState(1); if ($gameParty.isAllDead()) BattleManager.processDefeat(); b.hide(); 0
I.e. only hide after launching the defeat sequence.
Spoiler: idea 2
Try setting the skill's Damage Type to None (i.e. no damage formula) and putting these in the skill's Effects list:
  • Add State: State #1, 100%
  • Special Effect: Escape
  • Common Event: Check All Dead
Then in the common event have something like this:

◆If:Script:$gameParty.battleMembers().length === 0 || $gameParty.isAllDead() ◆Script:BattleManager.processDefeat(); ◆ :End
I.e. "if there are 0 non-hidden party members, or they're all dead, then process defeat".
@caethyril In both instances I go straight back to the map. With the first suggestion I can tell, because of something from my "battle end" common event, the game thinks that I have, in fact defeated the enemies.
@caethyril In both instances I go straight back to the map. With the first suggestion I can tell, because of something from my "battle end" common event, the game thinks that I have, in fact defeated the enemies.
Have you tried forcing an action on the target with a skill that has the "escape" effect instead?
@Trihan That also just takes me straight back to the map.
Changing the party name should never have any effect on the battle end handling. The behaviour you state is the expected outcome: the "individual party members flee" sequence, basically Abort Battle. However, I don't know why you're only seeing that after adding my little override.

In case it's some kind of weird plugin conflict, here's a slightly different approach (see attached file):
Spoiler: full plugin code
JavaScript:
/*:
 * @target MZ
 * @plugindesc Improves battle result controls when using Escape on actors.
 * @url https://forums.rpgmakerweb.com/index.php?threads/149507/
 * @help Use one of these script calls to make the next escape a defeat:
 *    BattleManager._escapeType = 'defeat';
 *    BattleManager._escapeType = 'lose';
 * 
 * Use one of these script calls to make the next escape a victory:
 *    BattleManager._escapeType = 'victory';
 *    BattleManager._escapeType = 'win';
 * 
 * Note that this value will NOT be included in save data.
 * Also, it will be reset at the end of the battle.
 * It is designed to be used mid-battle to affect the outcome of that battle.
 * 
 * This plugin also makes the party name include hidden/escaped members.
 * 
 * Terms of use:
 *    Free to use and/or modify for any purpose, no credit required.
 */

// Change response when party members escape individually
;void (alias => {
    BattleManager.processPartyEscape = function() {
        switch (String(this._escapeType).toLowerCase()) {
            case 'victory': case 'win':
                this.processVictory();
                break;
            case 'defeat': case 'lose':
                this.processDefeat();
                break;
            default:
                alias.apply(this, arguments);
                break;
        }
    };
})(BattleManager.processPartyEscape);

// Always reset value, for consistent load/save behaviour
void (alias => {
    BattleManager.endBattle = function(result) {
        alias.apply(this, arguments);
        // reset escape type
        delete this._escapeType;
    };
})(BattleManager.endBattle);

// Make party name include escaped members (for win/lose msgs)
Game_Party.prototype.name = function() {
    // replaced: battleMembers -> allBattleMembers
    const members = this.allBattleMembers();
    const numBattleMembers = members.length;
    if (numBattleMembers === 0) {
        return "";
    } else if (numBattleMembers === 1) {
        return members[0].name();
    } else {
        return TextManager.partyName.format(members[0].name());
    }
};
Apart from (a slightly updated version of) the fix I mentioned earlier for the party name, this adds some script calls, namely:
  • BattleManager._escapeType = 'win'; and
  • BattleManager._escapeType = 'lose';
These convert an "individual party members escaped" result for the current battle into a standard victory or defeat result, respectively.

With this, you could change your skill's damage formula to:

b.addState(1); if ($gameParty.isAllDead()) BattleManager._escapeType = 'lose'; b.hide(); 0
I did some quick tests and this seems to work for me...but then so did my earlier suggestion. 😴

If you're still having problems, see if the problems disappear when you turn off your other plugins. If so, share screenshot(s) of your Plugin Manager and maybe someone will have some ideas as to what's going on.
@caethyril I am delighted to report that everything went well with the new code and script calls. I tested it with everyone ejected and then only one or two ejected with the last one finished off by a traditional attack. In all cases the battle ended with the correct message and a satisfying Game Over screen. (and how often can Game Overs be greeted with such delight?)

Thank you very much for all your time and effort. I am deeply grateful.

Original thread: https://forums.rpgmakerweb.com/threads/1-was-defeated-being-overwritten.149507/