MV YEP_BuffsStatesCore - Changing Poison to Heal

Hi,

So I'm using YEP's Buffs and States Core to do a State that converts poison-type damage to heal.

The notetag in the State works almost perfectly :

JavaScript:
<Custom Regenerate Effect>
if (user.isStateAffected(252)){
var r = user.hrg;
var h = 0 - (r * 2);
var hot = Math.ceil(user.mhp * h);
target.gainHp(hot);
}
</Custom Regenerate Effect>

Where the State 252 is the one allowing the conversion into heal.
My issue comes with the timing of it. The battler is healed BEFORE the poison applies, meaning he will never get healed to full hp.

I haven't found a post that adresses this issue yet, so could someone help me with it ?
Would it be an option to have a 3rd state.

When your state is applied, it does not heal the poison when it happens, but cures the poison state, and replaces it with the new state, which should also be called poison (or anti-poison) and with the same (or similar) icon, but instead of -5% HP regen, it now has +5% HP regen.

So instead of using your state to heal against the poison, use your state to replace the poison state with a healing version of the poison state.

Now the poison truly heals, instead of healing twice but still get ge damage.

For the player it would look like the same state, or if you used a similar icon and name, it would look as a version of the state.
The rather obvious question is - how are you doing poison?

If you're leaving it as the default HP Regeneration Trait, then clearly, yes - the built-in traits code doesn't get executed at the same time as your notetag code. There's no such thing as two pieces of code canceling each other out or converting each other.

If you want to do what you describe, you'd do it all in one notetag.

As a suggestion - what you have isn't broken, but I would suggest against making so many different variables. It doesn't serve any purpose except to potentially confuse you by using the wrong one. You don't need to declare a new variable every time you modify a value (it also makes your code take up more room than it needs to - again, going to readability).

Also, any time you post code, you should make sure to put it inside the CODE tags (the </> on the edit bar). That preserves indentations and brackets.

I don't know what your original value was, but I'm replacing the hrg part with 10% of the user's HP. If you want something else, replace it accordingly. (note that means I'm actually doing 20% of the user's HP, since you had hrg * 2)

Code:
<Custom Regenerate Effect>
let amount=Math.ceil(user.mhp*.2);
if (user.isStateAffected(252))
    user.gainHp(amount);
else
    user.gainHp(-amount);
</Custom Regenerate Effect>
The rather obvious question is - how are you doing poison?

If you're leaving it as the default HP Regeneration Trait, then clearly, yes - the built-in traits code doesn't get executed at the same time as your notetag code. There's no such thing as two pieces of code canceling each other out or converting each other.

If you want to do what you describe, you'd do it all in one notetag.

As a suggestion - what you have isn't broken, but I would suggest against making so many different variables. It doesn't serve any purpose except to potentially confuse you by using the wrong one. You don't need to declare a new variable every time you modify a value (it also makes your code take up more room than it needs to - again, going to readability).

Also, any time you post code, you should make sure to put it inside the CODE tags (the </> on the edit bar). That preserves indentations and brackets.

I don't know what your original value was, but I'm replacing the hrg part with 10% of the user's HP. If you want something else, replace it accordingly. (note that means I'm actually doing 20% of the user's HP, since you had hrg * 2)

Code:
<Custom Regenerate Effect>
let amount=Math.ceil(user.mhp*.2);
if (user.isStateAffected(252))
    user.gainHp(amount);
else
    user.gainHp(-amount);
</Custom Regenerate Effect>
Thanks for the CODE tags 😅
I was taking hrg because I wanted the state to be part of a passive where it converts every poison-like state inflicted to the battler to heal (to give an exemple, Death's Grace state in Granblue Fantasy). So for every "Regeneration HP" state that is negative, I'd put the notetag in order to make it heal instead.

Anyway, I'll try your code just to see if it solves the problem while keeping the hrg, and if it doesn't work I'll try something else ^^
I was taking hrg because I wanted the state to be part of a passive where it converts every poison-like state inflicted to the battler to heal (to give an exemple, Death's Grace state in Granblue Fantasy). So for every "Regeneration HP" state that is negative, I'd put the notetag in order to make it heal instead.
Well, that can't work unless you get/make another plugin to change how HP regeneration works. As described above, the default code that does stuff with hrg is separate from anything you do in your notetags - you can't do anything in there to just ignore what the default effects of hrg are.

You would have to not use hrg at all and put code like this into every state that can drain health.

Even then, if there are multiple states like this you're going to see multiple popups unless you make some substantially more complex code to try to account for it.

Original thread: https://forums.rpgmakerweb.com/threads/yep_buffsstatescore-changing-poison-to-heal.158419/