Adding Sleep if an enemy has a state instead of damage.

I'm currently creating a skill that will either deal damage as a normal attack, or if the enemy has a specific state, it will instead inflict sleep.

I've browsed through several threads and other resources regarding the damage formula box, and none of the state-checking seems to be working properly.

The formula I'm using is

if b.state?(26) == true; b.add_state(6);0; else; a.atk * 4 - b.def * 2; end;where 26 is a custom state called "Is Human", which will be put on Bandits and the like, and 6 is Sleep.

Currently, through all of the "Battle Test" that I've done, the formula seems to be ignoring everything except the damage calculation.

I can see that the state 26 is applied to the enemy through means of the "Message when state remains" field on the state editor, so I'm not sure where the problem is.

If anyone could provide any insight as to how to make this work, please let me know.
the damage value needs to be the last command given in a damage formula.

Try the following (haven't tested it, but it needs to be something similiar): 

Code:
if b.state?(26) == true; b.add_state(6);dmg = 0; else; dmg = a.atk * 4 - b.def * 2; end;dmg
Excellent! It works great now.

Thank you very much.
This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/adding-sleep-if-an-enemy-has-a-state-instead-of-damage.16796/