MZ Stacking burn state who explodes on beginning of turn.

Plugin: VisuMZ SkillsStatesCore
What i wanna create:
- A burn state who is stackable.
- when the targets turn starts it should deal x fire dmg * x stacks.
- it should then remove all stacks.
- the stacks should be visable like the barriers. (With a icon for the state and the number of stacks).

I really dont even know where to start, can anybody help me with the notetags and JS commands?
Put something like this in there (replace stateIds). The last notetag is from VS Battle Core. Oh and you might wanna add animation script and some other stuff there too:

<JS On Add State>
const number = (target.getStateDisplay(stateId) || 0) + 1;
target.setStateDisplay(stateId, number);
</JS On Add State>

<JS On Erase State>
const damageModifier = target.getStateDisplay(stateId);
if (damageModifier) {
target.gainHp(-1 * damageModifier * 100);
}
target.clearStateDisplay(stateId);
</JS On Erase State>

<JS Pre-Start Turn>
user.removeState(stateId);
</JS Pre-Start Turn>
Thank you very much.
I will try this out and try to add the animatins by myself. I will post the result qnd if it worked.
<JS On Add State>
const number = (target.getStateDisplay(stateId) || 0) + 1;
target.setStateDisplay(stateId, number);
</JS On Add State>

<JS On Erase State>
const damageModifier = target.getStateDisplay(stateId);
if (damageModifier) {
target.gainHp(-1 * damageModifier * 100);
}
target.clearStateDisplay(stateId);
</JS On Erase State>

<JS Pre-Start Turn>
user.removeState(stateId);
</JS Pre-Start Turn>

Well it works just fine on its own. But now i have another problem. It shouldnt add this state when the absorb barrier is active allready. And if the target gets a absorb barrier after this state is applied it should first reduce the absorb barrier to 0 before inflict damage to the hp.
Sadly i cant test further for now bc i have to work till sunday. Maybe you could help me again?
Well put in the add state notetag to remove the state if they are affected with the absorb barrier state and then make a tag to check that it doesn't use the remove state codes then. Or something. (edit: though it can happen that you first have this fire state, then get absorption barrier and then get more stacks of the fire state, so if you want to account for that, you need to build it more complex)

Then in the damage dealing part you need to check the state and the remaining points. I think in MZ the points is just the state display counter. So you modify it something like this:

if (damageModifier) {
let barrierPoints = 0;
if (target.isStateAffected(barrierStateId))
barrierPoints = target.getStateDisplay(barrierStateId);
let damage = 100 * damageModifier - barrierPoints;
if (damage < 0)
damage = 0;
target.gainHp(-1 * damage);
if (target.isStateAffected(barrierStateId)) {
let remainingBarrier = barrierPoints - 100 * damageModifier;
if (remainingBarrier < 0)
remainingBarrier = 0;
target.setStateDisplay(barrierStateId, remainingBarrier);
}
}

EDIT: Added the change in the barrier after damage
Cant wait to try it out tomorrow, i tryed it way different from your solution, im still new to java script but like to try it by myself first.
Anyway thank you for your time and i gonna add you in the credits when im done.
I had to change it a bit.
My solution is:

Item/Skill Notetag:

<JS Pre-Apply>
if (!target.isStateAffected(stateIDbarrier)) {
$gameVariables[variableID] = x;
target.addState(stateIDburn);
}
</JS Pre-Apply>


And the Code in the State:

<JS On Add State>
if (!target.isStateAffected(stateIDbarrier)) {
const number = (target.getStateDisplay(stateIDburn) || 0) + $gameVariables[variableID];
target.setStateDisplay(stateIDburn, number);
}
</JS On Add State>

<JS On Erase State>
const damageModifier = target.getStateDisplay(stateIDburn);
if (damageModifier) {
const baseDamage = x;
const barrierPoints = target.getStateDisplay(stateIDbarrier) || 0;
const fireElementRate = target.elementRate(elementTypeID);
let damage = baseDamage * damageModifier * fireElementRate - barrierPoints;
damage = Math.max(damage, 0);
target.gainHp(-1 * damage);
if (target.isStateAffected(stateIDbarrier)) {
let remainingBarrier = barrierPoints - baseDamage * damageModifier;
remainingBarrier = Math.max(remainingBarrier, 0);
if (remainingBarrier > 0) {
target.setStateDisplay(stateIDbarrier, remainingBarrier);
}
else {
target.removeState(stateIDbarrier);
$gameTemp.requestAnimation([target], animationID);
}
}
}
target.clearStateDisplay(stateIDburn);
</JS On Erase State>

<JS Pre-Start Turn>
user.removeState(stateIDburn);
</JS Pre-Start Turn>


The fun part is with this method that an enemy/actor who absorbs fire get healed trough the burn state. (Edit) I have to set a passive state with element absorb first and include it in the damage calculation. :eswt2::LZSsad:

Now there is still some work to do like:
- Show the damage on the Barrier in the battle and the Battle Log.
- Change the color of the damage in the color of the element. (Fire = Orange)

Original thread: https://forums.rpgmakerweb.com/threads/stacking-burn-state-who-explodes-on-beginning-of-turn.182652/