Remove passive state with damage?

I'm making an accessory inspired by the pokémon's air balloon, it gives immunity to an element until the user suffers an attack from another type of element. I did this by creating a state with a trait that gives immunity to the psychic type, and giving that passive state to the aluminum hat. I found a code and tried to adapt it to my purpose, but I don't know java and the effect isn't removed when damaged. If anyone can help, I'd be grateful!

That's the code I found and put on the state notetag:

Code:
<Custom Apply Effect>
var atkcount = 1; //This is the attack counter. Change it to fit your purpose
target._attackCount = atkcount;
target.setStateCounter(44, target._attackCount); //Set a counter to your state. Change X to your state ID
</Custom Apply Effect>

<Custom React Effect>
//Check if actor takes dmg
if (value > 0 && !this.isHpRecover()){
//Decrease the attack counter by 1
target._attackCount -= 1;
//Set a counter to your state. Change X to your state ID
target.setStateCounter(44, target._attackCount);
//Check if attack counter reaches 0
if (target._attackCount <=0){
//Remove the state. Change X to your state ID
target.removeState(44);}}
</Custom React Effect>

<Custom Remove Effect>
user._attackCount = undefined;
</Custom Remove Effect>

Here is the link to the trend I got the link from:
I found a code and tried to adapt it to my purpose, but I don't know java and the effect isn't removed when damaged.
RPG Maker uses JavaScript, not Java. They're two different languages.

Your problem is that you're talking about a passive state and using code for regular states. You can't use removeState() on a passive state, you have to use the notetags from the plugin instructions to determine whether the passive state is turned on or off.

So there are a few different ways you could do this, but the method I'll give you here uses two states. One is a passive state on the accessory. That state has no Traits, no icon, nothing.

Give it this notetag:
Code:
<Custom Battle Effect>
user.addState(44);
</Custom Battle Effect>

I assume 44 is your air balloon state because that's what you have in the code you posted.

Now, in the notes of 44, get rid of all of the garbage that doesn't have anything to do with your skill and just put this:
Code:
<Custom Respond Effect>
//Check if actor takes dmg
if (value > 0 && !this.isHpRecover())
    target.removeState(44);
</Custom Respond Effect>

That should be all you need. If the state is giving State Resist to a certain element and you want it to go away after it actually takes damage, and the state ID is 44, this will do that.
That should be all you need. If the state is giving State Resist to a certain element and you want it to go away after it actually takes damage, and the state ID is 44, this will do that.
Yup, it works indeed, thank you so much. I never really had time for RPG maker till the last couple weeks, but since then I've already seen you in so many threads and solving so much of my problems lol. Keep the good work and saving peoples games! 😀

Original thread: https://forums.rpgmakerweb.com/threads/remove-passive-state-with-damage.155815/