Yanfly's Buffs & States Core - Reapply same state to target

I have a state which expires after 3 turns, then there is a 50% chance that it will automatically be reapplied on the target again. I use this Custom Remove Effect in Yanfly's Buffs & States Core for my state (http://yanfly.moe/2015/12/25/yep-50-buffs-states-core/):
Spoiler
<Custom Remove Effect>
if (Math.random() < 0.5){
target.addState(411);
target.startAnimation(49);}
</Custom Remove Effect>

When it expires, i can see the animation played, but the target is totally unaffected by "target.addState(411)" (411 is the same state itself). I guess i cannot reapply the same state via this method so is there any other way to do so?
According to description: "The code will process before the state is actually removed", so state 411 is reapplied, but then immediately removed. If that's the case, create a dummy state (e.g. 412), add that and make it have a custom apply effect that applies state 411 and removes 412.
I followed your suggestion and created a dummy state 412 like this:
Spoiler
- 411:
<Custom Remove Effect>
if (Math.random() < 0.5){
target.addState(412);
target.startAnimation(49);}
</Custom Remove Effect>

- 412
<Custom Apply Effect>
user.addState(411);
user.removeState(412);
user.startAnimation(14);
</Custom Apply Effect>

Unfortunately, it did not work too :blink: the Animation No.14 was still played but State No.411 was not added again :dizzy:
Did animation 14 precede animation 49? If yes, then the entirety of the apply effect resolved before the remove effect ended, so status 411 was reapplied before it was removed again. My bad, I should have thought of that.

If status 411 is removed when the battler's turn ends, you could try using the Custom Turn End effect instead of apply effect for state 412 since according to the description, it takes place after everything else. That way, the entirety of the remove effect resolves, state 411 is removed and at the end of the turn end process, state 412 reapplies it (if I understand correctly). Also, if you want this status to regenerate only when it expires by time (instead of being removed by a dispel skill for example), then use Leave effect instead of Remove effect.
Two animations were played at the same time (as i observed with my own eyes). I also did "Custom Turn End" for state 412, but it was still the same. It did not reapply state 411 on the target.
I tried "Leave Effect" and no luck too :blink:
It is so hard to deal with this in MV. Back in VX Ace, there was a Ruby script called "State Auto Apply" by Victor Sant which could do this easily, but he hasn't ported it to MV :blink: I guess i have to change the way how my skill works :blink: Thank you very much for your support, @Naridar ☺️
The state won't be able to reapply itself through a remove function. You may need to think a little differently to make this work.

What if you have no turn timer, but at a certain point with the state, like after 3 turns, do a randomness check, followed by an if/else statement. If the state remains, do nothing. If it fades, remove the state in the statement. To make this work, you could use a regenerate effect to increase a variable that you designate by 1, and when it hits 3, do the check. Just be sure to set the variable in apply, while making it undefined upon removal.
With your suggestion, I finally made it work, @shockra. Thanks a lot for your help ☺️

Original thread: https://forums.rpgmakerweb.com/threads/yanflys-buffs-states-core-reapply-same-state-to-target.77603/