Instant death to characters with certain states

Hello, I've been searching for a way to implement something that appears in some boss battles, but I haven't been able to find the way to do it.

Some bosses use skills that kill every party member who has a certain state, like slept (Victoria's Twilight from Bravely Default) or terror (Werner's Rule by Fear from Octopath Traveler).

I think it could be done with a code that would check if some party member has "x" state and killing it if that were the case, but I don't know what would be the exact code.

Can anyone help with that, please?
Just have your skill target each actor and check if that actor is affected by a certain state via damage formula. You can use this to check the state:
Code:
b.isStateAffected(state_id_goes_here) ? do_something : formula_goes_here
This applies state 1 (death) to actors affected by the said state (change state_id_goes_here with your real state id). Instead of "formula_goes_here" just write your damage formula for actors that are not affected by the said state.

If you want to show the real damage dealt then you can do something like this instead:
Code:
b.isStateAffected(state_id_goes_here) ? b.mhp : formula_goes_here
This will inflict damage equal to target maximum hp if target is affected by that said state or normal damage if target is not affected by that said state. Which option you pick is up to you.

EDIT: I changed the first code to be a general version of the second one.
Just have your skill target each actor and check if that actor is affected by a certain state via damage formula. You can use this to check the state:
Code:
if (b.isStateAffected(state_id_goes_here)) { b.addState(1); }; formula_goes_here
This applies state 1 (death) to actors affected by the said state (change state_id_goes_here with your real state id). Instead of "formula_goes_here" just write your damage formula for actors that are not affected by the said state.

If you want to show the real damage dealt then you can do something like this instead:
Code:
b.isStateAffected(state_id_goes_here) ? b.mhp : formula_goes_here
This will inflict damage equal to target maximum hp if target is affected by that said state or normal damage if target is not affected by that said state. Which option you pick is up to you.

Thank you very much. For some reason, the first code didn't work when I tested it (it detected the state but didn't apply death). However, I managed to obtain the effect I wanted with the second one with a little modification:

Code:
b.isStateAffected(state_id_goes_here) ? 9999 : formula_goes_here

While it made a massive damage, it strangely didn't kill the target putting the "b.mhp" variable, so I decided to make it do 100000 fixed damage points, so the effect is the same as the one I wanted.
While it made a massive damage, it strangely didn't kill the target
This might happen if your target has Elemental Resistance against that skill element. If that is the case damage is reduced. Using an upper limit is a possible solution, this way you are sure to kill the target. However, my personal suggestion is to set your skill element to be none so that Element Rate is not involved.
This might happen if your target has Elemental Resistance against that skill element. If that is the case damage is reduced. Using an upper limit is a possible solution, this way you are sure to kill the target. However, my personal suggestion is to set your skill element to be none so that Element Rate is not involved.
Changing the Skill Element to none doesn't change the result, so I'll be sticking to the fixed damage points. But thanks anyway for giving me the code I wanted to know.
Changing the Skill Element to none doesn't change the result
Is your variance also set to 0?
Check this out: Yanfly Tips & Tricks FREEZE

It can do what you want and more! 🙂
-MIA
Is your variance also set to 0?
It wasn't but now it is, but it still doesn't kill the characters affected by the state (but leaves them almost at 0 HP).

Now the skill has a variance of 0% and no element with it's damage formula being:
Code:
b.isStateAffected(29) ? b.mhp : 0
29 is the ID number of the state I'm using.

Check this out: Yanfly Tips & Tricks FREEZE

It can do what you want and more! 🙂
-MIA

I think it's more than what I need for this, but it gives me an idea for another skills. Thanks!😀

Original thread: https://forums.rpgmakerweb.com/threads/instant-death-to-characters-with-certain-states.107555/