Remove state from an enemy during the turn of the enemy

Ok this sounds kinda weird. I hope I can describe my problem as clear as possible.

I have a Spell: it's a fire shield. where the enemy gets damage when he attacks. I managed to implement it with a state, where the damage calculation is located.
Now my problem is there is a another spell which creates a state that protects enemies from physical hits. The state vanishes when the caster gets any kind of damage, this is implemented by the RPG-Maker MV standard function, which is applied for the example of the "sleeping" state as well.

There is one enemy in my game that uses the spell. A way to deal with him would be that you let him attack your fire shield. Now the problem is for some reason, the state won't go away although he takes damage. I assume it doesn't work when the enemy gets damage in his own turn at least it looks like that it doesn't count as "hit". Otherwise this works fine.

So what can I do now? I thought about removing the state of the enemy on the same site where the damage calculation for the fire shield state is located. This is made by a YanFly Plug-in: check this out for example:


I modified it but, I can't apply the remove state effect for some reason. How should it go? I can't use the same commands that I usually put in damage formulas, right?

Would be thankful for any help here.
So the problem is that a player character has Fire shield state, an enemy has a state that protects it from physical damage for one hit, but when this enemy attacks the player with Fire shield while have the protective state on it, the protective state does not go away when the damage happens?

You may need to add an if/then statement within your <custom react effect> that checks if a the damage is a physical or magical attack.

//check to see if the damage is physical and it deal positive HP damage
if (this.isPhysical() && this.isHpEffect() && value > 0) {
//make the damage received zero
value = 0;
}

I'm not sure if you have the damage being dealt by the Fire shield set to either Physical, Magical, or Certain; but, if you set the damage, then maybe use the protective state to check if the damage if physical because it's supposed to only protect against a physical attack right?

edit: sorry if I did not clarify, but within the if/then statement you would need to change it how you see fit to dispose of the state, I only put up a portion to check the type of damage being dealt.

Hopefully this helps

edit 2: probably by way of user.removeState(x)

Am I close to what the problem is?
Actually the state, will be lifted by any kind of damage it's just that if the attack is phyiscal it won't hit. The maker differs between physical and magical evasion and the phyiscal evasion is set to the maximum in this state.
So I assume I have to set this custom react effect for the "high physical evasion" stat instead for the fire shield? Thanks for the remove State command will it work in custom react effects? I will try it out once i'm at the maker again.
I think you would set the react effect with the if dmg is physical then remove the state and do zero dmg, if not physical then keep the dmg and remove the state. Since you can control dmg within the note tag you don’t need the evasion settings on the state because that would never allow the physical dmg to ever hit so the react effect would not happen.

edit: if you look at buff and state core lunatic code help file, it says that a custom react effect will occur before damage is calculated but only if the attack connects, so if the evasion for physical damage is set at 100% then a physical attack technically never hits, thus nullifying the custom react effect note tag.
Nah it's ok user.removeState(x) worked fine right under the damage calculation, i already check if the attack is physical for recoil damage. But there is no need to adjust the damage value, the enemy gets hit hit by the recoil (fire damage) regardless even if it's evasion is over 9000.

Original thread: https://forums.rpgmakerweb.com/threads/remove-state-from-an-enemy-during-the-turn-of-the-enemy.122644/