Battle: Check if enemy killed at least 2 actors in one turn

Hey guys, I can't seem to figure this one out even after lots of googling and thinking.

How can I check in Battle if the enemy managed to kill >= 2 actors with one hit?
Because in that case I would like a little "alert" event to start.

Maybe it is something like

if (target.isDead()) {add 1 to a variable "how many killed in this turn")
if var "how many killed in this turn" >= 2


or


$gameParty.deadMembers().length >= 2
But obviously, that wouldn't count how many actors were killed in THAT particular turn...?? So sorry for my amateur scripting abilities...
You can do it much simpler.

Define one variable to count the number of alive members in the last turn and one for the current turn.
Have one troop event run at every turn end, counting the alive actors and compare that with the number from last turn.
It depends on whether you need to check the number of actors killed in one turn or one action.

If it's one turn, it's pretty easy. Do it like @Andar suggested - each turn, set a variable ("currently dead party members") to the number of currently dead party members... but right beforehand, set another variable ("last turn dead members") to the value that the "currently dead" variable contains right before you change it. Then add 2 to the "last turn dead" variable, and if it's still less than or equal to the "currently dead" variable (for example: 0 + 2 <= 2 which means that 2 members died this turn), trigger the event.

If it's one action, it gets harder. You can still handle it without plugins, but you'll need some complex damage formulas and eventing. The trick is to track the number of party members that are dead at the beginning of an action. You can do this by setting a variable equal to that number at the beginning of a damage formula - this will occur before damage is applied (multiple different things can be done inside a damage formula; just use a semicolon to separate each "line" of code). But since any action that can kill multiple members must be multi-target, and we don't want the number of dead members to be constantly updated each time one dies (in the middle of an action resolution), we have to make sure we only take the lowest number of dead members at any point during the action. The way to do this would be to set a variable ("dead members") to a high number like 99 at the beginning or end of each turn (using a standard Turn event) - and at the beginning of the damage formula, only set the "dead members" variable to the number of dead members if it is lower than the current variable. So, for example, if you start the turn with one dead party member, and the enemy uses an attack that kills 2 more (and fails to kill the third alive member), what will happen is that the variable will start at 99, become 1 as it's about to damage the first alive member, and then not change again for the rest of the turn. Finally, you need to have this action run a Common Event (using the Features box) - Common Events run after the action and its damage has been resolved - which you need to track the new number of dead members now that the action has been resolved ("after action dead members"), add two to the other variable ("dead members"), and if it's still less than or equal to the "after action dead members" variable, you can trigger the event (in this example, the "after action dead members" will be 3, and since 1 + 2 <= 3 it will trigger).

Whew! That's a lot of work. But it's a necessary grind if you want to check for cool logical stuff like "double kills" in a platform that has no reason to check for it otherwise.
@Andar Thank you very much, that makes perfect sense!

@Wavelength

Thanks for the heads up and your detailled answer, you're exactly right, I would like to do the one action option.

I nevertheless tried it the "easy" way first and added two lines, and it works like that. (see below)

Could you explain again why it would be better to do it the way you explained with setting the variable at 99? 👋 I'm so sorry for being so slow...


BattleManager.actionPerformAction = function() {
this._logWindow.performAction(this._subject, this._action);
if (this._subject.isEnemy()) {$gameVariables.setValue(1, $gameParty.aliveMembers().length); }; //alive members at action end
if (this._subject.isActor() && this._subject.isSpriteVisible) {
this._logWindow._waitCount += 20;
return false;
}
return true;
};

BattleManager.actionPerformFinish = function() {
this._logWindow.performActionEnd(this._subject);
if (this._subject.isEnemy()) {$gameVariables.setValue(2, $gameParty.aliveMembers().length); }; //alive members at action end
$gameParty.aliveMembers().forEach(function(member) {
member.spriteReturnHome();
});
$gameTroop.aliveMembers().forEach(function(member) {
member.spriteReturnHome();
});
return true;
};

Thank you soooo much!!!!
It looks like you've modified (or perhaps aliased) BattleManager methods, which apply to all battlers. Since you don't trigger the alert within the code, I'm going to make the further assumption that you are using an "end of turn" troop event to conditionally trigger the alert.

I'm only somewhat familiar with the way that MV's BattleManager flow works, but I believe the problem you will run into with this approach (or with any similar approach where you run the alert at the end of the turn) is if another enemy takes a turn after the enemy that killed 2 characters in one action. Variables 1 and 2 will be re-set by this new action, before they are ever used to trigger the alert.

Two possible solutions to this would be:
  1. Compare the variables directly in the code after you set Variable #2, and set a Switch ON if 2 characters were killed; the Switch will indicate that the alert should be displayed during the (Turn or Moment) Troop Event. This is probably the best way. Remember to set the Switch back OFF afterwards (as well as at the beginning of each turn, to prevent some oddities in edge cases).
  2. If there's only one skill or one enemy with a few skills that you want to make these checks for, instead of using a Troop Event you can attach a Common Event to the skill that you want to check kills for. This is like my "hard" approach above, but since you're setting the Variables within the code, you can skip all the way through my instructions to "have this action run a common event" and continue from there.

Original thread: https://forums.rpgmakerweb.com/threads/battle-check-if-enemy-killed-at-least-2-actors-in-one-turn.86100/