Wanting something different to happen depending on which enemy in a troop is the last alive in battle

RoseRainblood

Veteran
Veteran
Joined
Nov 29, 2018
Messages
71
Reaction score
8
First Language
English
Primarily Uses
RMMV
I have a battle with 5 different enemies in the troop. I want a different thing to happen depending on which of these 5 enemies are the last enemy left alive in battle.

I'm looking under the Battle Event conditions until the Troops section of the database, but there doesn't seem to be a simple way to do this. I've searched on the forums but I don't think anyone has asked this question yet. Hoping that this won't be too tricky and that someone here will be able to help me out. It would be super appreciated!
 

Solar_Flare

Veteran
Veteran
Joined
Jun 6, 2020
Messages
478
Reaction score
210
First Language
English
Primarily Uses
RMMV
An interesting question... I think a setup something like this could work:
1593967090907.png
So inside the outer if statement, you just add one if statement for each enemy to see if they're dead, and only do something in the Else branch. The script condition (for copy-paste purposes) is:

JavaScript:
$gameTroop.aliveMembers().length == 1
It just means there's only one enemy left.
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
30,390
Reaction score
7,220
First Language
German
Primarily Uses
RMMV
the simplest way would be to have five troop events conditioned on HP>0 setting the same variable to different numbers once per moment. That might cause too much lag, so you'll have to test.
But that way the last alive enemy would have its number in the variable because all other enemy troop events would stop as soon as those enemies are dead.

a more complex way without lag would be to have those troop events triggered on death and overwrite the same variable, but that needs to use an immortal state to prevent the battle from ending before the last troop event triggers.

EDIT:
@Solar_Flare
Your solution will not work because the troop events will not be triggered after last death, that last death will go directly to battleend without troop events unless you trick the engine into believing one enemy survived. It also has a problem with turn end if more than one enemy was killed in the last turn
 

Solar_Flare

Veteran
Veteran
Joined
Jun 6, 2020
Messages
478
Reaction score
210
First Language
English
Primarily Uses
RMMV
@Solar_Flare
Your solution will not work because the troop events will not be triggered after last death, that last death will go directly to battleend without troop events unless you trick the engine into believing one enemy survived. It also has a problem with turn end if more than one enemy was killed in the last turn
I think you misunderstood my solution. It doesn't trigger events when the enemy died but instead checks each turn how many are left.

You do appear to be correct about the problem of more than one enemy dying in the same turn, though.

It can probably be solved with the Immortal state like you said - add it to every enemy at the start of the battle, and then remove it from any enemy whose HP reaches 0. That's probably trickier than it sounds though...
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
30,390
Reaction score
7,220
First Language
German
Primarily Uses
RMMV
It doesn't trigger events when the enemy died but instead checks each turn how many are left.
not exactly - it triggers at turn end, and that still means that it will not trigger in the last turn when the last enemy died, because that still goes to battleend without triggering any troop event, same as when enemy dies.

and yes, using the immortal state is trickier unless you have already done this before - which is why I placed that as second solution and not first in my answer above
 

CHKNRAVE

I don't end projects, I start them.
Veteran
Joined
May 11, 2020
Messages
65
Reaction score
45
First Language
French
Primarily Uses
RMMV
Another idea:

Make a page in which the condition is that the first enemy has 0% HP or less. Triggered once per battle.
In the event's page, make a script condition: $gameTroop.aliveMembers().length == 1
If it's true, that means there's only 1 enemy left, execute your commands.
Once you're done putting everything down, copy the page and paste it to have as many as there are enemies. Change the condition so that each one will be triggered by a different enemy dying.

If you want to make it easier to make changes later, another option would be to set up a switch that will be off at the start of the fight.
In the troop event pages, instead of all the commands and the condition, add the command to turn on the switch.
Add a page in which the condition is that switch. Set the triggering to "Moment".
In this page, first of all turn off the switch. Then add the condition, and the commands to execute.
 

Solar_Flare

Veteran
Veteran
Joined
Jun 6, 2020
Messages
478
Reaction score
210
First Language
English
Primarily Uses
RMMV
not exactly - it triggers at turn end, and that still means that it will not trigger in the last turn when the last enemy died, because that still goes to battleend without triggering any troop event, same as when enemy dies.
Which is basically fine, because the intent is to trigger when there is an enemy still alive. Even if it triggered when all enemies were dead, it would not do anything, so who cares?

If two enemies die in the last turn, then yes there's a problem. But the event doesn't rely on triggering when the last enemy dies.
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
2,369
Reaction score
1,537
First Language
English
Primarily Uses
RMMV
Which is basically fine, because the intent is to trigger when there is an enemy still alive. Even if it triggered when all enemies were dead, it would not do anything, so who cares?

If two enemies die in the last turn, then yes there's a problem. But the event doesn't rely on triggering when the last enemy dies.
If you've already checked that alivemembers().length is 1, why not just use $gameTroop.aliveMembers()[0].index() to get the index of which one is alive, rather than having a conditional branch checking isDead?
 

Solar_Flare

Veteran
Veteran
Joined
Jun 6, 2020
Messages
478
Reaction score
210
First Language
English
Primarily Uses
RMMV
If you've already checked that alivemembers().length is 1, why not just use $gameTroop.aliveMembers()[0].index() to get the index of which one is alive, rather than having a conditional branch checking isDead?
Yeah, that could work in a Control Variables command, and then you could use my SFG_SwitchCommand to branch based on which is the last enemy standing.
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
2,369
Reaction score
1,537
First Language
English
Primarily Uses
RMMV
Or just use "script" in the conditional branch and do

Code:
$gameTroop.aliveMembers()[[0].index() === 1
:p
 

Solar_Flare

Veteran
Veteran
Joined
Jun 6, 2020
Messages
478
Reaction score
210
First Language
English
Primarily Uses
RMMV
Or just use "script" in the conditional branch and do

Code:
$gameTroop.aliveMembers()[0].index() === 1
(FYT) Yeah that would work too, but then you have if branches nested 8 deep which is kinda crazy. :p
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
2,369
Reaction score
1,537
First Language
English
Primarily Uses
RMMV
Not really, just do the conditional branches one after the other. Only one of them is going to have its condition met. :p
 

Solar_Flare

Veteran
Veteran
Joined
Jun 6, 2020
Messages
478
Reaction score
210
First Language
English
Primarily Uses
RMMV
Ah, that's true, though that feels ugly for a different reason, because you're still checking those conditions that you know will be false. But sure, it will work.
 

CHKNRAVE

I don't end projects, I start them.
Veteran
Joined
May 11, 2020
Messages
65
Reaction score
45
First Language
French
Primarily Uses
RMMV
In that case, you could stick to the built-in conditions and check if an enemy has appeared. Dead enemies count as disappeared, after all, and scrolling down over the drop-down menu takes less time than changing a number in a string.
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
2,369
Reaction score
1,537
First Language
English
Primarily Uses
RMMV
Give me like five minutes and I'll verify. :p
 

CHKNRAVE

I don't end projects, I start them.
Veteran
Joined
May 11, 2020
Messages
65
Reaction score
45
First Language
French
Primarily Uses
RMMV
I've done that a few times, it's even a key feature in the event-based battle system I once posted to determine how many enemies are still standing.
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
2,369
Reaction score
1,537
First Language
English
Primarily Uses
RMMV
Ahh. The reason is because the interpreter command for the conditional branch calls isAlive() for the "appeared" check. So really it's checking whether the enemy has been killed or not.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

ESAMarathon on Twitch, now streaming "Eat Girl". Yep, that's the title of a game... Apparently it's a Pacman knockoff.... Which is of course the only logical conclusion one would get from a name like "Eat Girl". :kaopride: I can't believe anybody would think anything else! :kaoback:
Super stoked i just finished my first town in my project, by finished i mean i can always add more decorative aesthetics and the NPCs don't talk yet but the mapping is complete and all the important chess pieces are present!
My brain: Hey, I have an idea how to make the transition to the main story quest in The Wastes more natural!
Me: Good!
My brain: You need to remake the hotel you start out in, it's not realistic enough.
Me: Ok... This was unexpected, but I can do it.
My brain: Now make each hotel floor 5 times as large to match the main part. Oh, you also need to make a bunch of new npcs to fill in the space on these maps.
Me: Crap.
Should be able to release Haxe MV/MZ next weekend.
It look that somehow MZ tracks are messed up (for example battle4 is obviously a theme, castle2 is a ship, ship1 is a scene and so on..). Maybe they just named them after with some ambiguity.

Forum statistics

Threads
100,618
Messages
977,837
Members
132,228
Latest member
zhengdddddd
Top