Rewards for Enemy Escaping in MZ (and others?)

Quick question... Oddly something I have yet to try till tonight, and it's thrown me for a loop.

Escaping Enemies, giving rewards normally. HOW?!?

Seems that any way I make the only enemy escape, the result is instantly ended battle with no rewards. No EXP, no Treasure, nothing. How can I make the enemy, visually escape, but actually die (or trigger rewards)?

I am using Visustella's full suite, with BTB Battle Mechanic and VIctory Aftermath. (In case it matters)

Thanks!
of course that is what is happening - an escaped enemy is not defeated, so it doesn't give rewards.

and if you want a troop event to fire after all enemies are gone (before the battle aftermath is calculated), then you need to trick the engine with an immortal state- otherwise the battle ends without any event processing.

basically give all enemies an immortal state in turn 0, then make one event per enemy conditioned on HP=0. in the event you can do what you want before removing the immortal state. The enemy will die regularly once the immortal state is removed, but until then the engine will run the troop event even if that was the last enemy.
of course that is what is happening - an escaped enemy is not defeated, so it doesn't give rewards.

and if you want a troop event to fire after all enemies are gone (before the battle aftermath is calculated), then you need to trick the engine with an immortal state- otherwise the battle ends without any event processing.

basically give all enemies an immortal state in turn 0, then make one event per enemy conditioned on HP=0. in the event you can do what you want before removing the immortal state. The enemy will die regularly once the immortal state is removed, but until then the engine will run the troop event even if that was the last enemy.

Thanks for the feedback. I know the question seems rather obtuse. But I can't see how your method would work without ruining the escape.

I assume the immortality is so the player doesn't accidentally kill it before the event fires. But there is no chance of that happening anyway. (as it's set up)

...

There is one enemy in the troop, and it escapes if it's wounded enough. But, I'd like to grant the player the rewards for defeating it normally. With a normal aftermath.

I have seen other RPGMaker games do this, so I always assumed there was some easy way to do so (with a common plugin maybe), and never bothered to check because all the content I've made over the years, was narrative light. No reason to have reoccurring enemies escape.

I find myself making a story driven little thing now, and wouldn't you know it... Not so easy. :LZYhuh:
I assume the immortality is so the player doesn't accidentally kill it before the event fires.
wrong, the killing is intentional by the player, the state is to change the internal handling of the event.

the engine is build to end combat as soon as all enemies are dead - without bothering any events that might still be in the queue.
the immortal state will cause the event to be triggered on HP=0 even if that enemy was the last enemy (HP=0 fires normally if it isn't the last enemy), allowing the event to still process.
and when you remove the state after that, the regular battle end continues.

There is one enemy in the troop, and it escapes if it's wounded enough. But, I'd like to grant the player the rewards for defeating it normally. With a normal aftermath.
in that case you need to kill the enemy when the escape is supposed to trigger.

my alternative above was to let you process the rewards outside of the battle aftermath - if you want it to be part of the aftermath then you have to kill the enemy and just pretend that it run away.
At any rate. If there is an existing plugin to treat escape the same as death, I'd appreciate someone pointing it out.

Thanks again.
For now... I wrote this, and it appears to be compatible with VictoryAftermath.

Simply stick it in a .js file and set it above all other plugins. It overwrites the default function.
(This is the most compatible way I can find for Visustella plugins)

Code:
//Overwrite
Game_Unit.prototype.deadMembers = function() {
    return this.members().filter(member => (member.isDead() || (member.isEnemy() && member.isHidden())) );
};

Feel free to use it for any purposes you desire.
No credit necessary.

Escaping, is merely setting the hidden flag with the run sound played.
Easily reproduced by adding this to the Troops events.
escapeVictory.PNG


Simply set X in $gameTroop.members()[X].hide(); to whichever troop member ID you wish to make escape. (starts at 0 not 1)

If you're concerned with the enemy potentially dying, just do what Andar suggested regarding Invulnerability.

Note:
Oops. Sorry for the double post... Not intentional.
I think there is an alternative...

Make 2 identical enemies in the troop, both on the exact same spot.
Hide 1 of the enemies. Make the other one immortal.
Now when it is wounded enough, spawn the hidden enemy and kill it off right away, using troop events.
Then make the hidden enemy flee.

Now it looks like you only fought 1 enemy, and it looks like no-one died and it just flied, but you'll still get the loot and experience of 1 kill. Since they are a static image with no animation, it should not be noticeable that for a second there is a 2nd enemy behind it.
Thanks for the suggestion.

In all my attempts to physically kill an enemy, the death effect and the collapse sound, throws it all off.
Would it help if you just give it the state KO as soon as it spawns? Otherwise there has to be a way to prevent the collapse effect.
If you don't mind this effect to happen for EVERY fight where an enemy can escape, then turn this into a plugin and just play with its location in the plugin list to see where it works. (I say this because you did mention using Visustella plugins, so they might modify some of the code or alias it somewhere)

Code:
Game_Troop.prototype.expTotal = function() {
    return this.members().reduce((r, enemy) => r + enemy.exp(), 0)
}
Game_Troop.prototype.goldTotal = function() {
    return this.members().reduce((r, enemy) => r + enemy.gold(), 0) * this.goldRate()
}
Game_Troop.prototype.makeDropItems = function() {
    return this.members().reduce((r, enemy) => r.concat(enemy.makeDropItems()), [])
}

This makes the game only look at ALL TROOP MEMBERS, not dead, not hiding, ect and it does work if all members escape or were killed.

Edit: Also, this works in a clean battle, no need to set funky flags using script or anything, if you make an enemy use escape it plays the escape animation/sound effects as it should, and the enemy death collapse works as normal as well.

Edit #2: Decided to make a slight alteration if you want to make it so only certain battles work that way by adding in a switch check. Edit the code as you need if you decide to use this version instead.

Code:
Game_Troop.prototype.expTotal = function() {
    if ($gameSwitches.value(1) === true) { // Change Switch ID
        return this.members().reduce((r, enemy) => r + enemy.exp(), 0)
    }
    else { // Original Code
        return this.deadMembers().reduce((r, enemy) => r + enemy.exp(), 0)
    }
}
Game_Troop.prototype.goldTotal = function() {
    if ($gameSwitches.value(1) === true) { // Change Switch ID
        return this.members().reduce((r, enemy) => r + enemy.gold(), 0) * this.goldRate()
    }
    else { // Original Code
        const members = this.deadMembers();
        return members.reduce((r, enemy) => r + enemy.gold(), 0) * this.goldRate();
    }
}
Game_Troop.prototype.makeDropItems = function() {
    if ($gameSwitches.value(1) === true) { // Change Switch ID
        return this.members().reduce((r, enemy) => r.concat(enemy.makeDropItems()), [])
    }
    else { // Original Code
        const members = this.deadMembers();
        return members.reduce((r, enemy) => r.concat(enemy.makeDropItems()), []);
    }
}

Original thread: https://forums.rpgmakerweb.com/threads/rewards-for-enemy-escaping-in-mz-and-others.149651/