MV Counting Poison stacks to develop Resistance.

Hello fellow game-makers!
I'm looking to make it so that the party members (and Player), will develop a passive [Poison Resistance] skill after being affected by Poison X amount of times. I've figured out a stacking debuff previously (with considerable help), and thought the principles were similar, but I have a feeling that I'm not using the correct script pieces.
Spoiler: Screenshot of State
1716430785122.png

The code in the screenshot is:
Code:
<Reapply Reset Turns>
  <Custom Apply Effect>
target._stackingPoison = target._stackingPoison || 0;
target._stackingPoison += 1;
  </Custom Apply Effect>

  <Custom Regenerate Effect>
var damage = Math.round(a.mhp * 0.05);
if(target.isStateAffected(167)){
damage = Math.round(a.mhp * 0.1);
target.gainHp(damage);
} 
Else{target.gainHp(-damage);}
</Custom Regenerate Effect>

<Custom Action End Effect>
if(target._hasSkill(387)||target._hasSkill(319)){target._stackingPoison = 0;}
Else{
if(target._stackingPoison >== 90){target.learnSkill(319); target.forgetSkill(318);}
Else{if(target._stackingPoison >== 70){target.learnSkill(318); target.forgetSkill(317);}
Else{if(target._stackingPoison >== 50){target.learnSkill(317); target.forgetSkill(316);}
Else{if(target._stackingPoison >== 30){target.learnSkill(316); target.forgetSkill(315);}
Else{if(target._stackingPoison >== 10){target.learnSkill(315)}
}}}}}
</Custom Action End Effect>

The poison should do 5% max HP damage, unless the character has a special skill, then the poison will heal. I got the damage to work initially, but it stopped working entirely when I added the conditional damage in there. The Custom Action End Effect doesn't seem to work at all. I'm guessing that I'm doing a small piece of the script incorrectly (namely, calling a function incorrectly).

This combines the effects of 3 or 4 different YanFly plugins. I have the complete pack of them, so if another one needs to be utilized to solve this, then this is not an issue.

Thank you in advance for the help!
A lot of the syntax of the JavaScript you added in there is wrong.

- Else is not capitalized
- There's no such operator as >==
- It's not technically wrong syntax, but your formatting of braces and line breaks is not what's commonly used, so it's really hard to read your code. (and so there might be syntax errors in it, but I'm not trying to puzzle through it)

What's the point of all the skills you're teaching and forgetting from the target? If the effects of poison depend entirely on how many times the target has been affected by poison, why aren't you just referencing _stackingPoison for everything?

That's what I suggested when you asked me about this earlier.
A lot of the syntax of the JavaScript you added in there is wrong.

- Else is not capitalized
- There's no such operator as >==
- It's not technically wrong syntax, but your formatting of braces and line breaks is not what's commonly used, so it's really hard to read your code. (and so there might be syntax errors in it, but I'm not trying to puzzle through it)

What's the point of all the skills you're teaching and forgetting from the target? If the effects of poison depend entirely on how many times the target has been affected by poison, why aren't you just referencing _stackingPoison for everything?

That's what I suggested when you asked me about this earlier.
I will go through and edit those items - thank you. I was always told by my coding teacher that I did brackets strangely xD

The learn/forget model there is to learn a better version of the passive Poison Resistance. Skill 315 is 20% Poison Resistance; skill 316 is 40% Poison Resistance, and so on until 319 is granted, giving immunity.
Okay, but none of that does anything. Unless you have other notetags you're not showing, the damage being dealt in in the Custom Regenerate Effect is not "poison damage" - that stuff only applies during attacks executing their damage formula that have the appropriate element specified.

Thus, what I was saying above - I don't see the point of a bunch of different skills with a bunch of different skills when you already have the _stackingPoison property right there to use in your math.

The only one that actually matters would be 319, which can simply have State Resistance to this state.

Code:
<Custom Regenerate Effect>
if (target.isStateAffected(167))
    user.gainHp(Math.round(user.mhp * .1);
else
{
    let damage = Math.round(a.mhp * .05);

    if (user._stackingPoison >= 70)
        damage = Math.round(damage * .8);
    else if (user._stackingPoison >=50)
        damage = Math.round(damage * .6);
    else if (user._stackingPoison >= 30)
        damage = Math.round(damage * .4);
    else if (user._stackingPoison >= 10)
        damage = Math.round(damage * .2);
    user.gainHp(-damage);
}
</Custom Regenerate Effect>

Logically, I'm not sure why you separated out all of the skill learning stuff to action end instead of just including it in the custom apply, but maybe you have a reason I'm not thinking of.

This combines the effects of 3 or 4 different YanFly plugins.
It's "Yanfly" 😉
Okay, but none of that does anything. Unless you have other notetags you're not showing, the damage being dealt in in the Custom Regenerate Effect is not "poison damage" - that stuff only applies during attacks executing their damage formula that have the appropriate element specified.

Thus, what I was saying above - I don't see the point of a bunch of different skills with a bunch of different skills when you already have the _stackingPoison property right there to use in your math.

The only one that actually matters would be 319, which can simply have State Resistance to this state.

Code:
<Custom Regenerate Effect>
if (target.isStateAffected(167))
    user.gainHp(Math.round(user.mhp * .1);
else
{
    let damage = Math.round(a.mhp * .05);

    if (user._stackingPoison >= 70)
        damage = Math.round(damage * .8);
    else if (user._stackingPoison >=50)
        damage = Math.round(damage * .6);
    else if (user._stackingPoison >= 30)
        damage = Math.round(damage * .4);
    else if (user._stackingPoison >= 10)
        damage = Math.round(damage * .2);
    user.gainHp(-damage);
}
</Custom Regenerate Effect>

Logically, I'm not sure why you separated out all of the skill learning stuff to action end instead of just including it in the custom apply, but maybe you have a reason I'm not thinking of.


It's "Yanfly" 😉
Okay, I believe I see where I'm being unclear - I'm not applying the Poison resistance to reduce poison-type damage, I'm applying the poison resistance to resist the character being affected by the state "Poison."
So, state 315 makes it so that the character is only 80% likely to be affected by the Poison state, rather than poison-type damage.
Spoiler: Skills-states screenshot
1716433784022.png

1716433714277.png

Hopefully, this clarifies. =]
Okay, I believe I see where I'm being unclear - I'm not applying the Poison resistance to reduce poison-type damage, I'm applying the poison resistance to resist the character being affected by the state "Poison."
That's not what that trait does. From the instructions:
1716434972602.png


That affects the percentage that you specify when that actor uses a skill that has Add State: Poison. It doesn't make them less likely to receive the state from other battlers.

If that's what you want, you'd remove the Add State from the skill that's giving Poison and put an After Eval notetag on the skill that calculates a chance to add the state to the target (again, you can just directly use the _stackingPoison property for that).
That's not what that trait does. From the instructions:
View attachment 306028

That affects the percentage that you specify when that actor uses a skill that has Add State: Poison. It doesn't make them less likely to receive the state from other battlers.

If that's what you want, you'd remove the Add State from the skill that's giving Poison and put an After Eval notetag on the skill that calculates a chance to add the state to the target (again, you can just directly use the _stackingPoison property for that).
Thank you for your guidance! I got it to work as-intended.
Thank you again!! =]
This thread is closed due to being marked as solved. If you need it reopened, let us know. Thank you!

Original thread: https://forums.rpgmakerweb.com/threads/counting-poison-stacks-to-develop-resistance.168918/