How to make execution abilities?

So I wanted to create abilities that will execute targets at a certain HP percentage remaining, ex: “Will instantly kill enemies at 20% or less HP, does not effect bosses”
For the HP part, that's easy to do

you can use a formula like this in the damage formula.box

Code:
if (b.hp<(b.mhp*0.2)){b.hp=0;}else{actual damage formula}

so like if your normal damage formula is a.atk*4 - b.def*2

Code:
if (b.hp<(b.mhp*0.2)){b.hp=0;}else{a.atk*4-b.def*2}

These arent tested though so it might have syntax errors or others

I think there is also a function called hpRate in which case you can just do
Code:
if (b.hpRate <= 0.2)

but for the does not affect bosses, you need a way first to determine if the target is a boss.
Just a thought as to how you could stop this affecting bosses. At the start of your game have an event set a variable to an array holding all the ids of your bosses. Eg.

Spoiler
upload_2019-2-25_18-35-56.png

You can add more values to this, so long as they're separated by commas. After this have your execute damage formula check the enemyId against this array. Something like this should work:

Code:
(!$gameVariables.value(1).includes(b._enemyId) && b.hpRate() <= 0.2) ? b._hp = 0 : a.atk*4-b.def*2
To separate bosses from the rest, I use a boss state that I put on every boss,
then in the skills that need to behave differently with bosses and standard enemies I use that condition :
Code:
if (!b.isStateAffected( state id)) { enemy case } else { boss case }
It also allows me to easily add specific parameters to all bosses at once (like poison resistance or whatever).
@Engr. Adiktuzmiko @TWings

Is it possible to let it still deal damage even if it won’t execute? Cause if possible, I don’t want it to be completely useless within boss fights
Yeah, you can just mix it up to do the same to bosses and enemies who have more than 20% HP
Code:
if ((b.hp<(b.mhp*0.2))&&(!b.isStateAffected( your boss state id )){b.hp=0;}else{ damage formula }
If you look at the first line of code I posted there is this part

else {actual damage formula}

What that part does is that it deals damage based on the formula you write there in case it doesnt execute

Original thread: https://forums.rpgmakerweb.com/threads/how-to-make-execution-abilities.106061/