Cannot seem to get stacking states working with YF's Buffs & States Core.

So, the idea is that some states can "stack" up to 10 times, increasing their potency. This is achieved by simply re-applying the state while it's still active. Utilizing Yanfly's Buffs & States Core, I've tried a few things. The concept here is that states 81-90 are all Poison. Poison 1, Poison 2, Poison 3...Poison 10. Each one being more deadly than the last. Poison is only one skill. If an enemy uses Poison on an ally four times, then it's going to end up being State 84, which is Poison 4. That's what I'm trying to accomplish.


However, I've tried three different approaches, and each one offers a result that isn't quite doing what I'd hope it to do:


<Custom Apply Effect>


if (a.isStateAffected(81)) {


82;


} else {


81;


}


</Custom Apply Effect>


For this one, it just keeps giving me State 81. This is a notetag on State 81 itself. I figured it'd work where, if I didn't have State 81, it'd apply State 81. If I already had State 81, it'd apply State 82. Nope. I only get State 81. Never 82.


<Custom Apply Effect>


a.isStateAffected(81) ? 82 : 81;


</Custom Apply Effect>


Unfortunately, the exact same result as above. Being a bit more ambitious, I tried the following:


<Custom Apply Effect>


if (a.isStateAffected(81))


{


a.addState(82);


a.removeState(81);


} else


{0;}


<Custom Apply Effect>


This one was the most interesting. In this code, it always gave me State 82, and never State 81. Which means that when I used a skill that attempted to apply State 81, currently not having State 81 on the actor, it jumps right to giving me State 82.


Having this much trouble with 2 stacks certainly makes the prospect of 10 stacks a scary one.


Any help would be nice.


Thanks!
here is the full solution to your issue.


Buffs and States core has a build in 'counter' function, which can be used to add stacks to a state. In using this, you only need one state, not (up to) 10, and reapplying the state will increase the counter of that state automatically. You can then use a custom turn end effect to deal damage directly to affected battlers, using the number of stacks the state has as the base for the damage dealt.


<Custom Apply Effect>
target.addStateCounter(38, 1); //38 is the number of the state
if (target.getStateCounter(38) > 10){
target.setStateCounter(38, 10)}
</Custom Apply Effect>
<Custom Turn End Effect>
var rnd = 20 //the variance of the damage you want to deal
var formula = Math.round(15 * this.getStateCounter(38)); // this state will do 15 damage per stack. modify as you see fit
var total = Math.floor(formula * ((Math.random()*(rnd * 2)+(100-rnd))/100) // this should make the effect deal damage with 20% variance
this.gainHp(-total);
this.startDamagePopup();
if (this.isDead())
{
this.performCollapse();
}
</Custom Turn End Effect>
<Custom Leave Effect>
//this is so that the effect deals damage on the last turn it is active
var rnd = 20
var formula = Math.round(15 * this.getStateCounter(38));
var total = Math.floor(formula * ((Math.random()*(rnd * 2)+(100-rnd))/100)
this.gainHp(-total);
this.startDamagePopup();
if (this.isDead())
{
this.performCollapse();
}
</Custom Leave Effect>


I hope this helps you.

Original thread: https://forums.rpgmakerweb.com/threads/cannot-seem-to-get-stacking-states-working-with-yfs-buffs-states-core.66186/