MV 'Finishing move' skill and state applying formulas

I am trying to make a skill that could check target's HP and apply "Knockout" state on that target if its HP is low.
I even found the formula: b.hp < b.mhp * 0.25 ? b.AddState(1) : a.atk * 4 – b.def * 2
But ingame it is not working. Just deals no damage. I think that I made wrong conditions but I can't understand where I have mistaken.
I am using RPG Maker MV, steam version. The project for which I am asking about the skill also uses Yanfly's Battle Engine Core and Skill Core plugins.
Try this instead:
Code:
b.hp < b.mhp * 0.25 ? (b.addState(1), 0) : a.atk * 4 - b.def * 2
As far as I understand it it breaks because your version doesn't return a number, but returns undefined instead, which breaks it. This version *should* return zero and apply the state, although you could also just use:
Code:
b.hp < b.mhp * 0.25 ? b.hp : a.atk * 4 - b.def * 2
This should just deal their current HP as dmg if they are below 25%, which kills them anyway and you don't have to fiddle around with a state in the dmg formula. If they're not below 25%, it will deal the regular a.atk * 4 - b.def * 2 dmg.
The formula without state applying is working perfectly. But I decided to check out why I cannot use states in previous formulas
Code:
b.hp < b.mhp * 0.25 ? (b.addState(1), 0) : a.atk * 4 - b.def * 2
The conditions are working, it deals damage if target has more than 25% of mhp. However the state is not applying.
I tried to rewrite the formula into this but instead it deals 0 damage anyway.
Code:
b.hp <= b.mhp * 0.25 ? b.addState(1) ; 0 : a.atk * 4 - b.def * 2

Tbf once I started to use states in formulas, there are something going off.
For example this formula is also not working correctly.
Code:
b.isStateAffected(11) ? b.addState(12) : 0;
Might be simply due to how states work in rpg maker. If a state for example is applied, it can not be applied again in the same turn, even if it is removed. I don't know how these formulas work in your game, so it's hard to tell. Generally I would recommend not applying states through the dmg formula.

Original thread: https://forums.rpgmakerweb.com/threads/finishing-move-skill-and-state-applying-formulas.177847/