MV [Solved] Skill that allows me to heal when I'm inflicted with poison instead of taking damage

Hello! I have Yanfly plug-ins, specifically Buffs and States running a passive state for the skill [Poison Drinker] that (will eventually) heal the actor with the passive when they are afflicted with the state poison (that's state #4 for me). Here is a screenshot of what I have included. Here is the code itself:

EDIT:
HERE IS THE SOLUTION:
Spoiler
1603660406122.png

1603659375883.png

Code:
<Reapply Reset Add>
<Custom Regenerate Effect>
if (user.isStateAffected(142)) {
user.addState(140);
}
</Custom Regenerate Effect>
JavaScript:
<Custom Apply Effect>
if (target.isStateAffected(4)) {
    target.gainHp(Math.round(target.mhp * 0.1));
}
</Custom Apply Effect>
The issue was your use of just "mhp" w/o a unit associated w/ it (e.g. "target.mhp").
JavaScript:
<Custom Apply Effect>
if (target.isStateAffected(4)) {
    target.gainHp(Math.round(target.mhp * 0.1));
}
</Custom Apply Effect>
The issue was your use of just "mhp" w/o a unit associated w/ it (e.g. "target.mhp").
Thank you for the edit! Unfortunately, it still does not work. I tried with "a", "b", and "target".

Edit: Solution in original post!
Yanfly's Passive States never get applied: they're either there (active) or not. This means the Apply effect will never trigger. 😅

In this case I'd suggest building the effect into your poison state rather than the passive, e.g. try this notetag on your poison state:
Code:
<Custom Regenerate Effect>
// calculate poison damage
var dmg = user.mhp * 0.1;
if (user.isStateAffected(142)) {
  // has Poison Drinker, so heal
  user.gainHp(dmg);
} else {
  // otherwise damage as usual
  user.gainHp(-dmg);
}
</Custom Regenerate Effect>
If using this approach, you should also remove any negative regen traits on the poison state, since the damage is all being handled via the Regenerate Effect tag. 😮‍💨
Yanfly's Passive States never get applied: they're either there (active) or not. This means the Apply effect will never trigger. 😅

In this case I'd suggest building the effect into your poison state rather than the passive, e.g. try this notetag on your poison state:
Code:
<Custom Regenerate Effect>
// calculate poison damage
var dmg = user.mhp * 0.1;
if (user.isStateAffected(142)) {
  // has Poison Drinker, so heal
  user.gainHp(dmg);
} else {
  // otherwise damage as usual
  user.gainHp(-dmg);
}
</Custom Regenerate Effect>
If using this approach, you should also remove any negative regen traits on the poison state, since the damage is all being handled via the Regenerate Effect tag. 😮‍💨
Awesome! this way totally worked, as well, and works better because it is not Actor 1 specific. I might combine our solutions (adding the HOT state rather than the healing damage because I like how the numbers simplify at the end xD). Super great, thank you!
Edit: I put in the main comment the total solution after I tweaked it. I didn't like, visually, how the damage was showing (-5) as well as the healing (+10), so I did it this way so it was visually cleaner (just shows the +5 heal).
Awesome! this way totally worked, as well, and works better because it is not Actor 1 specific. I might combine our solutions (adding the HOT state rather than the healing damage because I like how the numbers simplify at the end xD). Super great, thank you!
Edit: I put in the main comment the total solution after I tweaked it. I didn't like, visually, how the damage was showing (-5) as well as the healing (+10), so I did it this way so it was visually cleaner (just shows the +5 heal).

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/solved-skill-that-allows-me-to-heal-when-im-inflicted-with-poison-instead-of-taking-damage.129131/