MV How to clear StateCounters after Battle or Defeat

I'm using the YEP_BuffStateCore, and I set a skill to add state(11) to the enemy, and when the Counters of state(11) is higher than enemy's def, the enemy will be defeat.

Let's say the player's def = 4. So when the player is affected by the state, and state's counter > 4, the player is dead.

The PROBLEM is:

After an enemy uses the skill to make the player dead. The state's counter is not clear.

When the player meets a new enemy, and the enemy just cast the skill ONCE. the player will die again.

So how to clear the StateCounter when the battle is end, or when the enemy is dead?

Below is the state's notetag:

<Custom Apply Effect>

this.addStateCounter(11, 1);

if(this.getStateCounter(11) > this.def) {this.addState(1)}

</Custom Apply Effect>



<Custom Deselect Effect>

if(this.getStateCounter(11) < 1) {

this.setStateCounter(11, 0);

this.removeState(11);}

</Custom Deselect Effect>
instead of on death, you can have it be on state removal.
try:
Code:
<Custom Remove Effect>
user.removeStateCounter(stateId)
<Custom Remove Effect>
Have you tagged the Remove at battles end for the State?
Have you tagged the Remove at battles end for the State?
that wouldnt necessarily help in the case a battler is killed as OP said unless the state persists through death with another plugin.

@ws6tbz
i ended up thinking it over and then took a look to confirm. dying normally calls clearStates() instead of removeState() for each state and clearStates() doesnt trigger remove effects. what i gave isnt a solution by itself.

I am accustomed to Turan's modification to make death trigger remove effects 🤣
if you apply the patch he has there under "Yanfly Buffs and States Core Death Remove Effects" then you should be good to go. you might not need the <Custom Remove Effect>

<Custom Victory Effect>
user.setStateCounter(stateId, 0);
</Custom Victory Effect>

<Custom Escape Effect>
user.setStateCounter(stateId, 0);
</Custom Escape Effect>

<Custom Defeat Effect>
user.setStateCounter(stateId, 0);
</Custom Defeat Effect>
that wouldnt necessarily help in the case a battler is killed as OP said unless the state persists through death with another plugin.

@ws6tbz
i ended up thinking it over and then took a look to confirm. dying normally calls clearStates() instead of removeState() for each state and clearStates() doesnt trigger remove effects. what i gave isnt a solution by itself.

I am accustomed to Turan's modification to make death trigger remove effects 🤣
if you apply the patch he has there under "Yanfly Buffs and States Core Death Remove Effects" then you should be good to go. you might not need the <Custom Remove Effect>
really thank you for your answer and patience, and I would try Turan's solution.

For now, I found a solution, I just put the "Clearing state" code before the state(1):


<Custom Apply Effect>

user.addStateCounter(11, 1);

if(user.getStateCounter(11) > user.def) {

user.setStateCounter(11, 0); // clearing the state counter

user.removeState(11); // remove the state

user.addState(1);}

</Custom Apply Effect>



<Custom Deselect Effect>

if(user.getStateCounter(11) < 1) {

user.setStateCounter(11, 0);

user.removeState(11);}

</Custom Deselect Effect>

I'm not sure if this method has any side effects, but at least it worked.


<Custom Victory Effect>
user.setStateCounter(stateId, 0);
</Custom Victory Effect>

<Custom Escape Effect>
user.setStateCounter(stateId, 0);
</Custom Escape Effect>

<Custom Defeat Effect>
user.setStateCounter(stateId, 0);
</Custom Defeat Effect>
Thank you all the same, but I tried these 3 tags, and did'nt work.😳


Have you tagged the Remove at battles end for the State?
No. But I used the "expiration after battle"

Original thread: https://forums.rpgmakerweb.com/threads/how-to-clear-statecounters-after-battle-or-defeat.176698/