MV Help applying KO via Yanfly Skills

In my game, i have elemental magics deal damage with a chance of applying an ailment state. If the mage is under a specific state, the rate of the ailment is boosted to 100% amongst other changes that aren't not relevant. I'm using yanfly's skills plugin and I have the checks done in pre-damage eval note tags. It works perfectly for custom ailment states that I've made but when I try to attach instant death to a spell it never activates, even though the same code works for the other spells and ailments.

<Pre-Damage Eval>
if (user.isStateAffected(17)){
target.addState(14);}
else{
if (Math.random() < 0.2){
target.addState(14);}}
</Pre-Damage Eval>

This works as intended where the spell has a 20% chance to apply [Insert Ailment Here] unless the caster has the state, where it then becomes 100%. I then made a spell that deals damage, but under the special state gain a 10% chance at instant KO, and i set it up like this:


<Pre-Damage Eval>
if (user.isStateAffected(17)){
if (Math.random() < 0.1){
target.addState(14);}}
</Pre-Damage Eval>

It didn't work, so i thought that i just butchered the code and i decided to set it to something that I knew worked just to test it out. I took the same code that the other spells work with and just changed the ailment state to death and it still does not work

<Pre-Damage Eval>
if (user.isStateAffected(17)){
target.addState(1);}
else{
if (Math.random() < 0.2){
target.addState(1);}}
</Pre-Damage Eval>

Instant death never triggers. Any help?
A couple of general suggestions for you:
When you're typing code, you should use the CODE tags (the </> icon on the edit bar). This preserves indentations and stops the forum from turning anything with brackets into BBCode.

Also, there's not really a point to saying
Code:
else{
    if{
and creating two code blocks. You can just say else if

As far as your actual question:
Instant death never triggers. Any help?
Are you sure that the state doesn't get added, or is it just that the target doesn't die?

There's nothing in the code for addState() that checks for the state to be the death state and make the battler die if it is. You would have to manually do that (try adding target.performCollapse() )

The other way to do it, of course, would be to inflict damage equal to the target's HP, in which case the rest of it becomes more automatically handled by the engine.
A couple of general suggestions for you:
When you're typing code, you should use the CODE tags (the </> icon on the edit bar). This preserves indentations and stops the forum from turning anything with brackets into BBCode.

Also, there's not really a point to saying
Code:
else{
    if{
and creating two code blocks. You can just say else if
Thanks for the tips! I'm still new to coding and this forum in general so i appreciate them and ill keep these in mind going forward.

There's nothing in the code for addState() that checks for the state to be the death state and make the battler die if it is. You would have to manually do that (try adding target.performCollapse() )
I see now. The clarification was helpful. I had assumed that for battlers, having the KO state was the same as being dead, and following that, that dying was caused by having the KO state being applied to the battler from the default description of KO. Which would have meant that i could use addState to force deaths.

It was also my assumption that addState(1) would have been the same as "Add State : Knockout" in the default skill effects list but its as you said, rpgmaker handles addState differently. There's also the realization that addState() doesn't actually check for state rates on application and forces it on If you don't manually place a random roll and a check for state rate for it in the skill

I tried adding in performCollapse() and it makes the death animation and sound play when the battler is hit but still doesn't kill the target. I've learned about die() and since then it seemed to work on first glance when I made a skill with it as a direct effect. I haven't put it into the intended skill yet with the roll but I also know now ahead of time that ill have to add in a check with math.random() and target.stateRate(1) so that it doesn't work against enemies with KO state rate: *0% when the first 10% roll goes through.

The other way to do it, of course, would be to inflict damage equal to the target's HP, in which case the rest of it becomes more automatically handled by the engine.
I had thought about doing that and making it so that the damage number just doesn't pop up. But my initial concern was that had I done it that way, I would have to make a manual check against state rate on every skill with a similar property and I wanted to avoid that. However, I now see that its an unavoidable step I have to add regardless of what I do

I'm not in a position at the moment to add in these changes but there aren't any flaws with anything said above right? Once again, thank you for the answer to the previous question. I was about to scrap the idea until you mentioned that addState() doesnt work the way I thought it would for instant kills.
I see now. The clarification was helpful. I had assumed that for battlers, having the KO state was the same as being dead
Well, it is. It's one of the things that the engine checks for in the code for isDead() - HP isn't even in there.

But simply applying the state doesn't automatically trigger the visual things you're looking for, the actor falling over or the enemy disappearing. That's built into the larger process of "take damage, if that eliminates all of their HP, apply the death state and do this other stuff." If you're skipping some of those steps, you'll have to add it back in manually.

I also know now ahead of time that ill have to add in a check with math.random() and target.stateRate(1) so that it doesn't work against enemies with KO state rate: *0% when the first 10% roll goes through.
If you use State Resist instead of State Rate * 0, it will work as expected without you doing any extra steps.

I don't see anything in die() that would make it work without calling a battler refresh or executing the collapse, but if it works for you, awesome.
If you use State Resist instead of State Rate * 0, it will work as expected without you doing any extra steps.
I had tried using the KO resist trait but it resulted in me being unable to kill enemies by any means, even with die() skill. They went down to 0 hp but they couldn't die and kept acting. It did end up resulting in an idea for a later boss fight to make unskipable phases though

But simply applying the state doesn't automatically trigger the visual things you're looking for, the actor falling over or the enemy disappearing.
I'm not sure if maybe one of the yanfly plugins I have on changes death behavior, but whatever bits of dying that wasn't just happening wasn't just the visual parts. It didnt seem like any parts were working. when I was trying to use addState(1), their hp never changed, the target was still able to act as if nothing happened, they didn't seem to have any state applied on them, even if they were the only enemy/ally the skill didn't end the fight like what usually happens when one side dies, and when I added the performCollapse along with the addstate for KO to the notebox they did visually die, but then got back up/reappeared immediately after without ending the fight

But its also just as you said earlier, just having damage cause the death lets the engine handle everything the normal way as well. in the event die() stops working or has some unintended effect ill be sure to have the skill do b.hp and then hide the damage popup for it. Thanks again for the help. I appreciate it
I had tried using the KO resist trait but it resulted in me being unable to kill enemies by any means
That's the point. I'm not sure what you're trying to do with this trait, but if you're saying KO State Rate * 0%, that should mean it's impossible to apply the state, which should mean it's impossible for them to die.

The Common use for that concept (which would be better done via State Resist) is to keep an enemy from dying once they hit 0 HP so you can trigger events to run before the enemy is allowed to die.

If you're trying to make that be something like they are resistant to your death magic spells, I don't think that's a good approach. You'd do better by making your death magic have its own element, then use the elemental resist system built into RPG Maker.

Playing around directly with the death state can get messy and have unintended consequences.

Good luck.

Original thread: https://forums.rpgmakerweb.com/threads/help-applying-ko-via-yanfly-skills.151986/