Create a skill that applies 1 of 6 states at random every 5 turns

I'd like to make a skill that would allow my enemy to give himself one of six available states at random every five turns. I'm using Yanfly's Buffs and States Core 


as well as various other Yanfly plugins. I'm sure this can be accomplished using Lunatic mode's Custom Apply Effect but I'm still not very proficient in js.


If anyone can give me a hand with this I'll be grateful (and you'll get mention in my credits to boot!)
Ok so after tinkering a bit with Yanfly's action sequences I thought I had come up with a solution:


I made a common event which sets a random variable from 1-6


then I built this action sequence

Spoiler
<setup action>


clear battle log


display action


common event: 28


wait: 30


immortal: targets, true


</setup action>


<whole action>


</whole action>


<target action>


if $gameVariables.value(1)


animation 277: user


add state 64: user


wait for animation


else if $gameVariables.value(2)


animation 284: user


add state 65: user


wait for animation


else if $gameVariables.value(3)


animation 278: user


add state 66: user


wait for animation


else if $gameVariables.value(4)


animation 276: user


add state 67: user


wait for animation


else if $gameVariables.value(5)


animation 279: user


add state 68: user


wait for animation


else if $gameVariables.value(6)


animation 213: user


add state 69: user


wait for animation


death break


</target action>


<finish action>


clear battle log


immortal: targets, false


</finish action>

Except that it seems to cancel out my action sequence after it attempts to play the common event.


Anyone have any suggestions?
Ok I got it figured out. Turns out I had to use this instead of using a common event:

Spoiler
<setup action>


clear battle log


display action


Eval: $gameVariables.setValue(181,(Math.randomInt(6)+1));


wait: 30


immortal: targets, true


</setup action>


<whole action>


</whole action>


<target action>


if $gameVariables.value(181) === 1


animation 277: user


add state 64: user


wait for animation


else if $gameVariables.value(181) === 2


animation 284: user


add state 65: user


wait for animation


else if $gameVariables.value(181) === 3


animation 278: user


add state 66: user


wait for animation


else if $gameVariables.value(181) === 4


animation 276: user


add state 67: user


wait for animation


else if $gameVariables.value(181) === 5


animation 279: user


add state 68: user


wait for animation


else if $gameVariables.value(181) === 6


animation 213: user


add state 69: user


wait for animation


death break


</target action>


<finish action>


clear battle log


immortal: targets, false


</finish action>

There's a code for anyone who might try something similar.


Sorry for the double post. This can be closed.

Original thread: https://forums.rpgmakerweb.com/threads/create-a-skill-that-applies-1-of-6-states-at-random-every-5-turns.69371/