MV Trying to create a status effect that causes additional damage to the affected battler with the Yanfly Engine.

Okay, so I'm working on a status effect for a boss fight in my game called Debt. How I want it to work is that for each stack of Debt a battler has, they take a flat, additional 25 damage, capping at 25 stacks. I've been trying to use Yanfly's buffs and states core and it's Custom React Effects to achieve this, but I can't figure out the scripting. Can someone help me with this? Thanks!
Okay, so I'm working on a status effect for a boss fight in my game called Debt. How I want it to work is that for each stack of Debt a battler has, they take a flat, additional 25 damage, capping at 25 stacks. I've been trying to use Yanfly's buffs and states core and it's Custom React Effects to achieve this, but I can't figure out the scripting. Can someone help me with this? Thanks!
First, I think everyone needs to know if you already have something set up to give players stacks of Debt and just need to know how to deal more damage. If so people will
need to know what that set up is and if you don't then everyone will know you need help adding Debt stacks
to players and dealing damage.
If you only want it to work in the current battle, you can make use of the State Counter from Buffs & States Core. Just know when to increase the State Counter (to add more stacks) or when to decrease the State Counter (reduce stacks). And in React Effect, multiply the number of State Counter by 25 and add it to the value.
It only needs to work in the current battle, and I am using the State Counter to have stacks of Debt, like you say. My issue has to do with the scripting regarding the react effects and stuff; the actual math of having increased damage.
If you only want it to work in the current battle, you can make use of the State Counter from Buffs & States Core. Just know when to increase the State Counter (to add more stacks) or when to decrease the State Counter (reduce stacks). And in React Effect, multiply the number of State Counter by 25 and add it to the value.
if youre using the state counter to track the stacks, then try this

Code:
<Custom React Effect>
if (this.isDamage())
  value += 25*target.getStateCounter(stateId);
</Custom React Effect>
if youre using the state counter to track the stacks, then try this

Code:
<Custom React Effect>
if (this.isDamage())
  value += 25*target.getStateCounter(stateId);
</Custom React Effect>
Tried using this, changing the stateid to the state itself and everything, but I was met with this error when it tried to calculate damage. Any ideas?
Screenshot 2026-01-11 153914.png
Tried using this, changing the stateid to the state itself and everything, but I was met with this error when it tried to calculate damage. Any ideas?
the counter wasnt set yet then? do this then

Code:
<Custom React Effect>
if (this.isDamage())
  value += 25 * target.getStateCounter(stateId) || 0;
</Custom React Effect>
also theres no need to remove the stateId. in yanfly's buffs and states core plugin, its a variable to refer to the state's id automatically
the counter wasnt set yet then? do this then

Code:
<Custom React Effect>
if (this.isDamage())
  value += 25 * target.getStateCounter(stateId) || 0;
</Custom React Effect>
also theres no need to remove the stateId. in yanfly's buffs and states core plugin, its a variable to refer to the state's id automatically
Tried this and it didn't work, with or without the stateid change. Maybe I need to set the counter on another line? How would I do that if so?
Maybe I need to set the counter on another line? How would I do that if so?
I am using the State Counter to have stacks of Debt, like you say
im confused here. have you or have you not set the state counter? you havent shown where you did so i cant tell you if you need to set it on another line, but if you have it set at all, the notetag should work as-is.

1768189727116.png

1768189835479.png


debt.gif
Screenshot 2026-01-11 221121.png

Here's what mine looks like. ^ Maybe the removal conditions are making it not work? I also did some additional testing. When i am effected by the effect and should take damage, the game crashes. But when an enemy is effected by it and they should take damage, the normal number appears and they lose no health. It's pretty confusing...
im confused here. have you or have you not set the state counter? you havent shown where you did so i cant tell you if you need to set it on another line, but if you have it set at all, the notetag should work as-is.

View attachment 357441
View attachment 357442

View attachment 357440
It's pretty confusing...
where are you setting the state counter?
if you havent, you still need to. I showed that i quickly did it in my troop event as a test, but if your state application, some skill, some troop event, etc. doesnt set it, then its not going to do anything.


When i am effected by the effect and should take damage, the game crashes
if its the same crash as before, use the 2nd version i sent with the || 0; at the end. its meant to prevent that crash.
where are you setting the state counter?
if you havent, you still need to. I showed that i quickly did it in my troop event as a test, but if your state application, some skill, some troop event, etc. doesnt set it, then its not going to do anything.



if its the same crash as before, use the 2nd version i sent with the || 0; at the end. its meant to prevent that crash.
When I add the || 0; at the end, the status effect doesn’t do anything. So do I NEED to set a counter for all my party members at the start of battle, even if it’s zero?

I’ve never needed to do this before with other status effects, so sorry for the confusion.
When I add the || 0; at the end, the status effect doesn’t do anything
it prevents condition that causes the crash. not having a state counter isnt the same as having a state counter of 0. the || 0 there substitutes the undefined value you would have gotten from the non existent counter and replaces it with 0.

otherwise, the undefined value becomes NaN when you do math with it, then makes your damage dealt NaN, which then makes the actor's hp NaN, and then crashes the game when the hp gauge try to display NaN as a bar.

So do I NEED to set a counter for all my party members at the start of battle, even if it’s zero?
if youre using the || 0, then strictly speaking from a functional standpoint, no. but you should still set it just to have the visual for the player.

I’ve never needed to do this before with other status effects, so sorry for the confusion.
when youre dealing with state counters, you have to set them if you intend on using them. thats usually going to be done by some skill (yanfly's skill core, generally), or with a state effect from yanfly's buffs and states core (i.e. <custom apply effect>). I dont know how you want gaining stacks to work, but as an example...

Code:
<Custom Apply Effect>
user.setStateCounter(stateId, (user.getStateCounter(stateId)+1) || 1);
</Custom Apply Effect>
would increase the counter by 1 automatically every time the state is applied to the battler, which would then increase all damage taken from actions by 25 per application and should only reset if you set the counter to 0, or the battler loses the state
Okay, I think I figured out the issue. I assumed that the amount of turns that the status effect had left WAS the state counter. I did not realize you could have both at once. Whenever I was referring to the "stack" terminology, what I meant was extending the turn amount. So for each additional turn the effect lasted, attacks would deal an additional 25 damage.

Once I followed your guide to apply a counter to all my party members, I got it working in the form that you've shown and described. I can use that, but hopefully you can show me something different now that I've made I'm looking for clearer.

Thank you so much for helping me with this! I'm learning a lot.
it prevents condition that causes the crash. not having a state counter isnt the same as having a state counter of 0. the || 0 there substitutes the undefined value you would have gotten from the non existent counter and replaces it with 0.

otherwise, the undefined value becomes NaN when you do math with it, then makes your damage dealt NaN, which then makes the actor's hp NaN, and then crashes the game when the hp gauge try to display NaN as a bar.


if youre using the || 0, then strictly speaking from a functional standpoint, no. but you should still set it just to have the visual for the player.


when youre dealing with state counters, you have to set them if you intend on using them. thats usually going to be done by some skill (yanfly's skill core, generally), or with a state effect from yanfly's buffs and states core (i.e. <custom apply effect>). I dont know how you want gaining stacks to work, but as an example...

Code:
<Custom Apply Effect>
user.setStateCounter(stateId, (user.getStateCounter(stateId)+1) || 1);
</Custom Apply Effect>
would increase the counter by 1 automatically every time the state is applied to the battler, which would then increase all damage taken from actions by 25 per application and should only reset if you set the counter to 0, or the battler loses the state
I can use that, but hopefully you can show me something different now that I've made I'm looking for clearer.
in that case, instead of the state counter system you just use the stateTurns() function yanfly's buffs and states core adds.

Code:
<Custom React Effect>
if (this.isDamage())
  value += 25 * target.stateTurns(stateId);
</Custom React Effect>
THANK YOU SO MUCH, this works!
in that case, instead of the state counter system you just use the stateTurns() function yanfly's buffs and states core adds.

Code:
<Custom React Effect>
if (this.isDamage())
  value += 25 * target.stateTurns(stateId);
</Custom React Effect>

Original thread: https://forums.rpgmakerweb.com/threads/trying-to-create-a-status-effect-that-causes-additional-damage-to-the-affected-battler-with-the-yanfly-engine.181891/