Instant kill attacks, but you need certain conditions for it to work

Hello, first of all, i only used this webpage to search info,for a year now, but now, since my problem is so specific, i will need to take a step ahead and ask myself. If i do something bad like the cathegory or something just tell me, i have rpg maker mv since 2019, but im basically newbie here. As i said, im using MV, and i want an attack with instakill, but you need certain conditions: The condition would be having less than 30% of hp, then you cast the attack and it kills. If not below 30%, just deal normal damage like a normal attack. I really would appreciate the help. Thanks
You could try a skill formula like this:

if (b.hpRate() < 0.3) b.addState(1); a.atk * 4 - b.def * 2
I.e. "if the target is at 30% HP or less, add state 1 to the target; then do (attack formula) damage". If you want to check the HP% of the skill user instead of the target, use a.hpRate() instead.

This is OK if the skill will never get evaluated by the AI when it is deciding what to use. By default only actors with an Auto-Battle trait use that AI (enemies have their own rules). Plugins might change that.


Otherwise, you could check out a plugin like this:
E.g. put an "Add State: Death 100%" effect on a skill and put this in that skill's notebox:

<effect condition: 1> b.hpRate() < 0.3 </effect condition>
I.e. "only apply effect 1 if the target is at less than 30% of their max HP". 👋
alright, i will try it. Thanks for the help
Another way you could do it if you need to use auto battle would be

Code:
(b.hpRate() < 0.3 && b.stateRate(1) > 0 && !b.isStateResist(1)) ? b.hp : a.atk * 4 - b.def * 2

i.e. "if the target has less than 30% HP and is not immune to instant death, deal damage equal to their remaining HP, otherwise deal damage according to the formula." Though, this might cause problems if you have enemies with partial resistance to instant death.
@AphoticAmaranth: resistance to the skill's element or hit type could also interfere, though you may just be able to increase the kill damage to like 100000 or something. That should also work more nicely with the auto-battle AI, because it judges a skill's value by its damage output.

Original thread: https://forums.rpgmakerweb.com/threads/instant-kill-attacks-but-you-need-certain-conditions-for-it-to-work.142313/