[RMMZ]Need to create an immortal character

Hello everyone,

I'm trying to create a battle system with one of the party characters being immortal, but I need to create a constant check to see if all other party members are dead (with exception of the immortal one, of course) the game shows game over, but I've already tried with common events and battle events and it does not work anyway I tried, either the game over doesn't shows when the party members dies or when one of the characters dies the battle system freezes with the constant checking, just so I don't post 1000 screenshots here is what I have right now:

Plugins: Yanfly base troop events and Weapon Skill

Events: I've tried to make like a death counter so every time a character is affected by knockout the counter goes up and when it reaches a certain amount depending on the number of characters on the party it should show the game over.

Battle System: Time Progress (Active)
Making a character immortal is easy - just give them State Resist to Dead. However, by default that would mean you can never get a game over if that character is in your battle party.

Since you're using base troop events, I think one possible way to do it (assuming the immortal character has State Resist to Dead) would be to have an event that triggers every turn if that character's health is below some value (you can set any low value, it doesn't really matter). That event would check if everyone (other than the immortal character) is dead and, if they are, remove the immortal character from the party.

By removing the immortal character, you then end up with a party of three dead characters, which should trigger a standard game over.

I haven't tested this (not even in MV), but I think the idea is sound.
The immortal part I was doing by using battle troop event to check if the character is in the party and if he is it adds on turn 0 the immortal state, but that's the thing, how do I make an event that checks if the party members are dead? I've searched over the options but I couldn't found none.
The only way I could create it, it was by checking if the specific characters in the party are affected by knockout, but when I do that either the game over does not trigger or the battle freezes after one character dies.
As Solar_Flare said, make the character immortal by giving them "state resist: death", no troop event needed to revive them every turn.

For the game over effect, have a troop event which runs every turn with a script conditional branch, the condition for which should be

$gameParty.aliveMembers().filter(member => member.actorId() !== ID OF IMMORTAL CHAR).length === 0

Then in that branch, call the game over scene.
Can you describe the effect of each section of this script call just so I'm able to apply it correctly? Like it checks if the only member alive is the immortal character and if yes it shows game over, is that it?
Can you describe the effect of each section of this script call just so I'm able to apply it correctly? Like it checks if the only member alive is the immortal character and if yes it shows game over, is that it?
Almost. I'll break it down piece by piece.

$gameParty returns the class that handles party functions.

aliveMembers() returns an array of party members who aren't dead.

.filter() returns only elements of the given array which return true for the function passed to it. In this case, I've passed in an arrow function that returns whether the current member's ID is NOT that of the immortal one. In other words, it'll give us an array of living party members other than the immortal one.

.length just returns how many elements are in the array.

So put that all together and we're checking how many living party members aren't the immortal actor, and if it's 0 we go to game over.
Yeah, as we both said, you don't need to give the character the Immortal state. Just copy the trait from the Immortal state into that actor's own traits list.
I see, well I tested it and it works fine, I just noticed that checking every turn is the only way to do it and the game over runs only after the end of the current turn (e.g. if enemies and the immortal character still have actions to perform they will perform before the game over). I tried to use the common options on MZ to execute as soon as the last character dies but it freezes the system again with the constant verification, but I think it's ok like that. Thanks @Trihan and @Solar_Flare

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/rmmz-need-to-create-an-immortal-character.138404/