Passive state on accessory not working

I have an accessory which, when the wearer is hit, is supposed to restore a small amount of MP. The accessory is otherwise inactive. Here it is, for what it's worth.

1734970227564.png


State 36 has the following notetag. I am using VS Skills & States plugin.

Code:
<JS Post-Damage>
if (this.isDamage())
    console.log("Took a hit?")
    target.gainMp(Math.floor(target.mmp*0.02))
</JS Post-Damage>

As you can see, I include a console check. The console showed no error, but no MP was restored. I reduced the amount of MP the actor had in case it was being restored but the little popup wasn't working. That showed that nothing was being added.

I therefore assume that my code is wrong (nothing new there).
Can anyone tell me what my mistake is?
Thank you.
Hiya,

The JS tag <JS Post-Damage> doesn't work on states. Only on Skills and Items. For the tag to be correct on the state you'd want to use <JS Post-Damage as User> or <JS Post-Damage as Target> depending on your use-case for where the mp should be going. I would assume <JS Post-Damage as Target>.

(I think. Admittedly I get the user/target stuff mixed up a lot. I just know that the base post-damage one doesn't work on states which hopefully will push things in the right direction and someone a little better with JS can fill in the gaps, haha)
@FrigidGaze Thanks. I knew that it had to be something basic.
I've tested it and it's target in this instance.

Thank you very much for your help. It's much appreciated.
Also, you have an error in the JavaScript.

Conditionals (if) only apply to the next single code statement, so in your example above if you got damaged it would print the console message - but the gainMp() would happen every time an action with a damage formula targeted them.

If you want both things to happen after the condition, you need to make a code block with braces.
Code:
if (condition)
{
    this happens
    so does this
}

Of course, if your console.log() was just for testing and you've removed it, then it will work the way you want.
Of course, if your console.log() was just for testing and you've removed it, then it will work the way you want.
I can confirm that it was just for testing and has now been deleted.

Original thread: https://forums.rpgmakerweb.com/threads/passive-state-on-accessory-not-working.174110/