Detect which Enemy in the Database deals the Killing Blow, and turn a Switch ON

I want the enemy in a Troop of multiple enemies that deals the killing blow to taunt the player before the Game Over screen.

I also want to turn a switch on called for example:
"[X enemy] has dealt final blow to player"

Every enemy has their own dialogue, so using 'Last Enemy Index to Act" would not work, as I need to detect which enemy is it who dealt the killing blow, and not their index in the current Troop.

I'm no expert (╥﹏╥) So I would really appreciate if someone told me how to easily do this. Thanks! :LZSproud:
If you have the last enemy index to act in a variable X, I think it's (you may need to subtract 1 from variable X):

$gameTroop.members()[$gameVariables.value(X)].enemyId();
If you have the last enemy index to act in a variable X, I think it's (you may need to subtract 1 from variable X):

$gameTroop.members()[$gameVariables.value(X)].enemyId();
Sorry, but I don't understand 🙁 In what order should these commands be in the Battle Event and why should I subtract 1?

I'd like to know how make a switch turn on when that happens.
For example, "[X enemy] has dealt final blow to player = ON"
So I thought you had it set up, I replied to the part where you said that you can't use the index but need the enemy id. Subtract 1 because you want the array index, not the index the game shows. Like this:

$gameTroop.members()[$gameVariables.value(X)-1].enemyId();

That script gives you the the enemy id, then you can just turn ON a switch that you use for that id.

edit: like said above, if you have the last enemy index to act in variable X
Thank you for your help! Unfortunately with my current knowledge I have an hard time trying to understand what I have to in the engine as I don't understand what event commands I should use and where I should put the script D:

This is what I have now, and it does not seem to work. 7 is the Database ID of the Enemy (Crow)😢

Screenshot 2025-03-14 204223.png
Thank you for your help! Unfortunately with my current knowledge I have an hard time trying to understand what I have to in the engine as I don't understand what event commands I should use and where I should put the script D:

This is what I have now, and it does not seem to work. 7 is the Database ID of the Enemy (Crow)😢

View attachment 334335
So you've put a script command in there that just returns the enemy ID of the last enemy to act, but doesn't actually do anything with it.

Change your conditional branch to a script operand and do

JavaScript:
$gameTroop.members()[$gameVariables.value(8) - 1].enemyId() == 7
So you've put a script command in there that just returns the enemy ID of the last enemy to act, but doesn't actually do anything with it.

Change your conditional branch to a script operand and do

JavaScript:
$gameTroop.members()[$gameVariables.value(8) - 1].enemyId() == 7
Thank you!

It works, but when the Battle Event condition is "Enemy/Actor HP is 0% or below", the Party Defeat Message and Game Over screen is triggered (OR Victory if the enemy dies and it's the last one) before the event is executed. So I can't turn the switch on or show text.

Is there a way/plugin to execute the event before the battle ends? (Game Over or Victory)



Edit: I used Hime End Phase to achieve this. My only problem is that I can't find a way to detect if current every party member is dead.

I have found a method called $gameParty.isAllDead() that could be used to turn a switch on when every party member is dead to activate the killing blow event but it will now work
🙁

Screenshot 2025-03-14 230150.png
Do you use VS Battle Core action sequences? Have you considered copy/pasting at the end of the enemy skill sequences that isAllDead conditional to call a common event where you check the id, show text and turn on switches?
Do you use VS Battle Core action sequences? Have you considered copy/pasting at the end of the enemy skill sequences that isAllDead conditional to call a common event where you check the id, show text and turn on switches?
Oh! Is there an alternative way that lets me check if every party member is dead? I don't use VS Plugins.

It would be nice to run code when you use skills.
if it's equal to MV: you can try: $gameParty.aliveMembers() < 1 to check
if all party members are defeated.

as I use that inside my BattleMessages plugin to call a common event.
which that check could be used 🙂

so it should do the trick I believe.
if it's equal to MV: you can try: $gameParty.aliveMembers() < 1 to check
if all party members are defeated.

as I use that inside my BattleMessages plugin to call a common event.
which that check could be used 🙂

so it should do the trick I believe.
I tried, but it does not seem to work. The party gets defeated before the event gets executed, even if I use Hime End Phase Triggers.
🙁

I'll send my events again, in case I did something wrong.

e1.png

e2.png


Edit: I managed to get it working by creating a common event with a conditional "$gameParty.aliveMembers() < 1". If true, it turns the switch on. I then assign it to every skill in my database by click on an empty space in Effects then Other > Common Event

I now need to know to find a way to know if every enemy is killed.
I now need to know to find a way to know if every enemy is killed.
the opposite: $gameTroop.aliveMembers() < 1 🙂
the opposite: $gameTroop.aliveMembers() < 1 🙂
Thank you very much! I am extremely grateful :LZSproud:

Original thread: https://forums.rpgmakerweb.com/threads/detect-which-enemy-in-the-database-deals-the-killing-blow-and-turn-a-switch-on.176233/