Can I add a new state right after another one ends?

Hello. I'm planning to implement an item in my game that makes a character hyperactive, rising their states (like the invincible lollipops from Kirby) for 5-7 turns, and then adding an adverse effect that makes the same character confused and weak for some turns.
Is it possible to make it so right after the invincible state dissapears, the character is affected with the confused state?
Any help would be appreciated.
it is possible, although I can't recall with which plugin. it's something I have, because I do this in my game.
yanfly buff/state core
<Custom Leave Effect>
user.addState(X)
</Custom Leave Effect>
The code in between these notetags will run when the state is removed from
a battler due to turn decay. The code will process after the state is
actually removed and after <Custom Remove Effect>.

depending on the exact conditions you want triggering the new state you might use a different notetag. this tag only adds the new state if the state with this tag fades naturally. this tag wont add the new state if this state is cure by items or skills. (this 1 i used for death sentence and gradual petrify type states) this 1 should be good for your example.
if thats only supposed to happen on actors, than you can make an own switch for each actor which gets activated with the item(which activates the "invincible lollipop_state") usage ..
and if switch is on but "invincible lollipop_state" is off, an common event will set the related switch off and confusion state on..
this solution needs no extra plugins, but if you use a lot of actors that would need a lot of switches..

edit
( it should be possible to build a little plugin that stores these conditions in the "game battler", than no Game_switches or CommonEvents would be needed and it should work on all battlers )
Yanfly's Buffs and States Core is really the best way to do this.


I believe the notetags offered by @Tiamat-86 are correct.
yanfly buff/state core
<Custom Leave Effect>
user.addState(X)
</Custom Leave Effect>
The code in between these notetags will run when the state is removed from
a battler due to turn decay. The code will process after the state is
actually removed and after <Custom Remove Effect>.

depending on the exact conditions you want triggering the new state you might use a different notetag. this tag only adds the new state if the state with this tag fades naturally. this tag wont add the new state if this state is cure by items or skills. (this 1 i used for death sentence and gradual petrify type states) this 1 should be good for your example.
It worked! Thank you so much 🙂

Original thread: https://forums.rpgmakerweb.com/threads/can-i-add-a-new-state-right-after-another-one-ends.132696/