(Help) Stack state and then explode it (Solved)

I'm trying make you can stack a debuff (like poison or bleeding), and when get enough stacks, it explodes (the debuff dissapear) doing lots of damage to the creature what had that debuff.

The problem is, I don't know how make the debuff explode when reach certain stacks and dissapear, doing the damage.

I'm using VisuStella MZ T1 plugins
I assume you mean states. It's usually done something like this:

<JS On Add State>
target._poisonStacks = target._poisonStacks || 0;
target._poisonStacks++;
if (target._poisonStacks >= 5) {
delete target._poisonStacks;
target.gainHp(-100);
target.removeState(X);
}
</JS On Add State>

<JS On Erase State>
delete target._poisonStacks;
</JS On Erase State>

EDIT: Added line to remove state (replace X with state Id). Also, if you want animation to play when it "explodes", add the script line: $gameTemp.requestAnimation([target], animationId);
I assume you mean states. It's usually done something like this:

<JS On Add State>
target._poisonStacks = target._poisonStacks || 0;
target._poisonStacks++;
if (target._poisonStacks >= 5) {
delete target._poisonStacks;
target.gainHp(-100);
target.removeState(X);
}
</JS On Add State>

<JS On Erase State>
delete target._poisonStacks;
</JS On Erase State>

EDIT: Added line to remove state (replace X with state Id). Also, if you want animation to play when it "explodes", add the script line: $gameTemp.requestAnimation([target], animationId);
Lots of thanks. And yeah, I mean states, sorry, my english no its the best xD.

I should check a video about JavaScript for understand better what happens in that code

Also, just for be sure (im working and cant test it now) That notetag go to State note, or Skill note?
There's 2 notetags, both go to states' notes. You need VS Skills & States Core.

The code is like create your own property on the battler, make it keep its value (or create it and set it to 0 if it doesn't exist). Then increase the property by 1. Then check if the value is 5 (or more) and run the effects. Actually I think you don't even need the delete part in the 'if' part, because the remove state gets run which deletes it, but it doesn't matter because there shouldn't be a problem deleting a property that doesn't exist.
There's 2 notetags, both go to states' notes. You need VS Skills & States Core.

The code is like create your own property on the battler, make it keep its value (or create it and set it to 0 if it doesn't exist). Then increase the property by 1. Then check if the value is 5 (or more) and run the effects. Actually I think you don't even need the delete part in the 'if' part, because the remove state gets run which deletes it, but it doesn't matter because there shouldn't be a problem deleting a property that doesn't exist.
Ty a lots <3. I will try later when get to home.
I assume you mean states. It's usually done something like this:

<JS On Add State>
target._poisonStacks = target._poisonStacks || 0;
target._poisonStacks++;
if (target._poisonStacks >= 5) {
delete target._poisonStacks;
target.gainHp(-100);
target.removeState(X);
}
</JS On Add State>

<JS On Erase State>
delete target._poisonStacks;
</JS On Erase State>

EDIT: Added line to remove state (replace X with state Id). Also, if you want animation to play when it "explodes", add the script line: $gameTemp.requestAnimation([target], animationId);
No it's working. I changed ''X'' for the state ID, in this case, 7. But when get 5 stacks or more, nothing happens.


<JS On Add State>

target._poisonStacks = target._poisonStacks || 0;

target._poisonStacks++;

if (target._poisonStacks >= 5) {

delete target._poisonStacks;

target.gainHp(-15);

target.removeState(7);

}

</JS On Add State>



<JS On Erase State>

delete target._poisonStacks;

</JS On Erase State>
I tested it and it seems to work for me.
Show some screenshots. Also, did you make sure that you're adding the state?
I tested it and it seems to work for me.
Show some screenshots. Also, did you make sure that you're adding the state?
The state is being added, and when reach 5 turns or more, no do anything. Turns no count as stacks, right?
Not sure what you mean? You need to apply it 5 times. Are you using the skill that causes the state 5 times? If you are, then you need to show some screenshots.
Not sure what you mean? You need to apply it 5 times. Are you using the skill that causes the state 5 times? If you are, then you need to show some screenshots.
No, I no was applying the state, more like just adding turns to the state like a normal state.
1745068693258.png


Anyways. Already fixed it. I turned off the turn-time thing, and added a notetag for add 1 stack of the state, and everything is working.


JS On Add State>

target._poisonStacks = (target._poisonStacks || 0) + 1;



if (target._poisonStacks >= 3) {

target._poisonStacks = 0;

target.gainHp(-15);

target.startDamagePopup();

target.refresh();

target.removeState(7);

}

</JS On Add State>

Now I have a problem trying add an icon + number of stacks. Any notetag for that?
Now I have a problem trying add an icon + number of stacks. Any notetag for that?

State icon is set in the database? Use the state display to display the stacks:

target.getStateDisplay(stateId)
target.setStateDisplay(stateId, value)
target.clearStateDisplay(stateId)

So like add to the add notetag (if you need you can use that clear one in the erase notetag):

let displayN = target.getStateDisplay(stateId) || 0;
target.setStateDisplay(stateId, displayN+1);
State icon is set in the database? Use the state display to display the stacks:

target.getStateDisplay(stateId)
target.setStateDisplay(stateId, value)
target.clearStateDisplay(stateId)

So like add to the add notetag (if you need you can use that clear one in the erase notetag):

let displayN = target.getStateDisplay(stateId) || 0;
target.setStateDisplay(stateId, displayN+1);
How I use that code? For default, the icon of the state is already displayed on the enemies. (Its a fire state what when reach 3 stacks, explode). Usually the icon and number of turns appear. But with the stacks notetag no appear the number of stacks.
1745072054518.png
Also yeah, state icon is set.
1745072433254.png
The VS state display stuff is independent of the turn counters. Put it in the add state notetag that I posted earlier (below code needs stateIds and X changed):

<JS On Add State>
target._poisonStacks = target._poisonStacks || 0;
target._poisonStacks++;
let displayN = target.getStateDisplay(stateId) || 0;
target.setStateDisplay(stateId, displayN+1);
if (target._poisonStacks >= 5) {
delete target._poisonStacks;
target.gainHp(-100);
target.removeState(X);
}
</JS On Add State>

Don't understand what your problem with the icon is?
The VS state display stuff is independent of the turn counters. Put it in the add state notetag that I posted earlier (below code needs stateIds and X changed):

<JS On Add State>
target._poisonStacks = target._poisonStacks || 0;
target._poisonStacks++;
let displayN = target.getStateDisplay(stateId) || 0;
target.setStateDisplay(stateId, displayN+1);
if (target._poisonStacks >= 5) {
delete target._poisonStacks;
target.gainHp(-100);
target.removeState(X);
}
</JS On Add State>

Don't understand what your problem with the icon is?
I no had any problem with icon. I wanted icon+text, but only the icon was being displayed. Now works really smooth, and can see icon + stacks, lots of thanks!

Also im trying make with your notetag, the state no dissapear, but do certain damage * stack each turn. I'm able to make the state no dissapear, but idk how calculate the damage. Should be something like:

target.gainHp(-15 * target._poisonStacks); ?
If you want it to do like "poison"-damage every turn, you can use the slip damage notetags. Like state notetags, I think it's:

<JS HP Slip Damage>
damage = 15 * target._poisonStacks;
</JS HP Slip Damage>

<JS Slip Refresh>
If you want it to do like "poison"-damage every turn, you can use the slip damage notetags. Like state notetags, I think it's:

<JS HP Slip Damage>
damage = 15 * target._poisonStacks;
</JS HP Slip Damage>

<JS Slip Refresh>
Oooh right. I already used that notetag, but with turns. Lots of thanks and hope your have a good day! <3

And sorry for being kinda dumby 😛

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/help-stack-state-and-then-explode-it-solved.177046/