How to stack states

Like in the title, I want to make a skill that is similar to Demoman from Team Fortress 2 where he uses his sticky bomb to stack up and increase the damage. Making a similarity, I tried on the enemies but it just wont work (I tried using Yanfly stockpile).

Any recommendations?
Since you're already using Yanfly content, you could see what this Tips and Tricks entry shows about tracking and manipulating stacks within states on non-user targets. It does not sound like you will be creating a DoT effect, but this should illustrate how to work with the stacks generally. This entry may also be useful, especially if you intend for the state to stack through attacks and/or have a set maximum at which point the damage is triggered.
for the state:
Code:
<custom apply effect>
   user._stackingDamage = user._stackingDamage || 0;
   user._stackingDamage++;
</custom apply effect>

<custom remove effect>
   user._stackingDamage = 0;
<custom remove effect>

<custom react effect>
   user._stackingDamage = user._stackingDamage || 0;
   // your damage formula below. i put some examples. remove the // to make  one them valid or create your own

   //value = Math.floor(value * user._stackingDamage);
     
   //if(user._stackingDamage >= 4){value += 800;}
   //else if(user._stackingDamage == 3){value += 500;}
   //else if(user._stackingDamage == 2){value += 200;}

   //value = Math.floor(value * (user._stackingDamage * 500));
</custom react effect>
(Sorry for my english not the first language)
Thanks for the help but none of them are fit what i'm looking for but what I'm trying to say is that if i place the sticky bomb into the enemy then the state will appear until i stacked it up to 6/8 then i use a different skill to detonate into the enemy that has been affected by the state that will increase the damage depend of how many sticky bomb the enemy is affected.
(Sorry for my english not the first language)
Thanks for the help but none of them are fit what i'm looking for but what I'm trying to say is that if i place the sticky bomb into the enemy then the state will appear until i stacked it up to 6/8 then i use a different skill to detonate into the enemy that has been affected by the state that will increase the damage depend of how many sticky bomb the enemy is affected.
this explanation could have come sooner...

state:
Code:
<custom apply effect>
   user._stackingDamage = user._stackingDamage || 0;

   //limiting the stacks to 8 or adding one more
   if(user._stackingDamage > 8){user._stackingDamage = 8;}
   else{user._stackingDamage++;}
</custom apply effect>

<custom remove effect>
   user._stackingDamage = 0;
<custom remove effect>

skill:
Code:
<damage formula>
   b._stackingDamage = b._stackingDamage || 0;
   //setting damage to be 500 per stack. change what you need.
   value = 500 * b._stackingDamage;
</damage formula>
right i got two issues:

one for the state that wont stack in the enemy

Code:
<custom apply effect>
   user._stackingDamage = user._stackingDamage || 0;
   user._stackingDamage += 1;
   //limiting the stacks to 8 or adding one more
   if(user._stackingDamage > 8){user._stackingDamage = 8;}
   else{user._stackingDamage++;}
  user.setStateCounter(stateId, user._stackingDamage);
</custom apply effect>

<custom remove effect>
   user._stackingDamage = 0;
   user.setStateCounter(stateId, user._stackingDamage);
<custom remove effect>

And for the second it wont let me damage the enemy that has been affected by the state

Code:
<damage formula>
 if (!this._stackingDamage)
{
   b._stackingDamage = b._stackingDamage || 1;
   //setting damage to be 500 per stack. change what you need.
   value = 500 * b._stackingDamage;
}
</damage formula>

sorry i'm new for coding
mine works just fine... needs at least 1 stack to cause damage and does 5 damage per stack. used my original code.

plugin order or another factor, maybe?

Rather than creating a variable on the battler, you could just use Yanfly's built-in state counter functions. Not that adding one thing is going to make your save files bloated or anything, just a minor suggestion.

So...
Code:
<Custom Apply Effect>
if (!target.getStateCounter(X))
{
    target.setStateCounter(X, 1);
    target.clampStateCounter(X, 1, 8);
}
else
    target.addStateCounter(X, 1);
</Custom Apply Effect>
where X is the ID of your state.

Then in your skill you can reference b.getStateCounter(X) to reference how many stacks are on there.

And for the second it wont let me damage the enemy that has been affected by the state

sorry i'm new for coding
Then why did you change the code nuke gave you? That if check you put around the whole thing 1) isn't necessary, even if you did it correctly, and 2) broke your skill, along with the change from 0 to 1.

Also, do you have the required plugins? I don't see that addressed anywhere in this thread - the code nuke gave you relies on you having the States and Buffs Core as well as the Damage Core, which I don't think most people use.
the 1 he added was to make the skill cause damage even without a state present, but i think it would be weird based on his description. if one would press a detonator, it would make sense to have the explosive set first...

the rest, i really dont know why he changed.

Rather than creating a variable on the battler, you could just use Yanfly's built-in state counter functions. Not that adding one thing is going to make your save files bloated or anything, just a minor suggestion.
[...]
i just went along with the stacking damage tips and tricks... and i think its cleaner. kind of...
(Sorry for my english not the first language)
[...]
i just noticed: english is your 1st language (says your info)... :mrsatan:


EDIT: so, let me redo, step by step, what was proposed:
1) have yanflys plugins set in the right order. youre going to need damage core and buffs & states;
2) create a blank state, give it an icon, set it to auto-remove however youd like (or leave it there without decaying);
3) put the code below in its note box. ive added the counter to the code since i think youd like the player to know how many stacks are there.

Code:
<custom apply effect>
   user._stackingDamage = user._stackingDamage || 0;

   //limiting the stacks to 8 or adding one more
   if(user._stackingDamage >= 8){user._stackingDamage = 8;}
   else{user._stackingDamage++;}
   //change ID below to fit your game
   user.setStateCounter(ID, user._stackingDamage);
</custom apply effect>

<custom remove effect>
   user._stackingDamage = 0;
   //change ID below to match your state
   user.setStateCounter(ID, 0);
<custom remove effect>

4) create a skill to apply the state;
5) create a skill to cause damage. put the code below in its note box. ive added a line that removes the state since the bombs will detonate
Code:
<damage formula>
   //if changing zero below to 1, the skill will work without the state
   b._stackingDamage = b._stackingDamage || 0;

   //setting damage to be 500 per stack. change what you need.
   value = 500 * b._stackingDamage;

   //remove the bombs. replace ID with your state id
   b.removeState(ID);
</damage formula>

6) test.

EDIT2: also, hit F8 whenever youre testing and something didnt work. the console might give you a hint of what went wrong.
the 1 he added was to make the skill cause damage even without a state present, but i think it would be weird based on his description.
Exactly, that's why I said it broke his skill...it makes putting the state on the target one time pointless if it's going to cause one stack of damage anyway. Better to cause a set amount of damage and then add or multiply based on the stacks, including 0.

Even better yet to use the Selection Core and not be able to use it on a target who doesn't have the state. But that's a separate matter...
yea i thought its going to change the language for the website

Other than that, it finally worked because i've restart the plugin and the application entirely.

Thank you very much for the help
i just noticed: english is your 1st language (says your info)... :mrsatan:


EDIT: so, let me redo, step by step, what was proposed:
1) have yanflys plugins set in the right order. youre going to need damage core and buffs & states;
2) create a blank state, give it an icon, set it to auto-remove however youd like (or leave it there without decaying);
3) put the code below in its note box. ive added the counter to the code since i think youd like the player to know how many stacks are there.

Code:
<custom apply effect>
   user._stackingDamage = user._stackingDamage || 0;

   //limiting the stacks to 8 or adding one more
   if(user._stackingDamage >= 8){user._stackingDamage = 8;}
   else{user._stackingDamage++;}
   //change ID below to fit your game
   user.setStateCounter(ID, user._stackingDamage);
</custom apply effect>

<custom remove effect>
   user._stackingDamage = 0;
   //change ID below to match your state
   user.setStateCounter(ID, 0);
<custom remove effect>

4) create a skill to apply the state;
5) create a skill to cause damage. put the code below in its note box. ive added a line that removes the state since the bombs will detonate
Code:
<damage formula>
   //if changing zero below to 1, the skill will work without the state
   b._stackingDamage = b._stackingDamage || 0;

   //setting damage to be 500 per stack. change what you need.
   value = 500 * b._stackingDamage;

   //remove the bombs. replace ID with your state id
   b.removeState(ID);
</damage formula>

6) test.

EDIT2: also, hit F8 whenever youre testing and something didnt work. the console might give you a hint of what went wrong.
Other than that, it finally worked because i've restart the plugin and the application entirely.
I don't know what "restart the plugin" means, but you don't need to do that. What you do need to do, is any time you make changes to your project you need to start a new game, not load a save. Save games store a lot of the game info in them, so many changes won't be reflected.

Glad you got it working.
restart a plugin means that you remove it from the list and add it again. it will come with its default settings. handy if there are a lot of settings, things are wrong somehow and you have long forgotten what and how you changed it.
restart a plugin means that you remove it from the list and add it again.
If you say so - I know what that procedure does, but that's not the word I would choose 😉
is there a way to make a requirement for the skill like the skill wont be used unless the enemy has the "sticky bomb" as a state? or do i need to make a new post?
is there a way to make a requirement for the skill like the skill wont be used unless the enemy has the "sticky bomb" as a state? or do i need to make a new post?
that will depend on your approach. how much do you want to hide and how will the skills operate?

a simpler way is just making the skill select targets with "bombs".
like this:
Even better yet to use the Selection Core and not be able to use it on a target who doesn't have the state. But that's a separate matter...

other matter would be making the skill only visible if there are "bombs".

theres also the matter of the targeting scope of the detonating skill: will it detonate all of the bombs at once or will it only detonate targets you select (so if multiple targets are with "bombs", only one of them "gets bombed" per use, leaving time to other targets remove the bombs, maybe - maybe not)?
that will depend on your approach. how much do you want to hide and how will the skills operate?

a simpler way is just making the skill select targets with "bombs".
like this:


other matter would be making the skill only visible if there are "bombs".

theres also the matter of the targeting scope of the detonating skill: will it detonate all of the bombs at once or will it only detonate targets you select (so if multiple targets are with "bombs", only one of them "gets bombed" per use, leaving time to other targets remove the bombs, maybe - maybe not)?
Yea the selection core is what I needed, cheers!

Original thread: https://forums.rpgmakerweb.com/threads/how-to-stack-states.149086/