Help with a code using Yanfly state core

I've made this to run when a state is applied on the actor.

Spoiler

Spoiler
<Custom Action Start Effect>

var skillusada = Math.floor(Math.random() * 6)

var ataqueRandom = 1;

if (Math.random() < ataqueRandom) {

var skill = $gameActors.actor(1)._skills[skillusada];

var target = -1;

if ($gameActors.actor(1)._mp <= 0) {

var skill = 1;

}

BattleManager.queueForceAction(user, skill, target);

}

user.removeState(60)
</Custom Action Start Effect>

Everything work as intended except one thing, I don't know how to force the game forget the first input, the action. So it becomes awkward since he does the random action and then the right one.

I can't find anywhere the code to make it forget the input, or if it's even possible. Lastly I tried using user.clearActions(); but the game dies.

I'm asking here because I lost a good time trying to figure it out, I think I will just use a workaround and don't mind that this isn't going how I wanted. Doing it on the beggining of the turn instead of action makes this actor move before the fastest actors, which is weird.
Hello again, I'm doubleposting, but I guess it is ok because I got the solution! It's not pretty, but it works, probably there's a better way to do this, but my lack of knowledge prevents me from doing it better.

Here it is a way my character will do a Random attack if one variable of my game is too low, I hope it helps people trying to do random attacks too.

I'm using Yanfly plugins, I only tested this thing I wrote using: Skill core and instant cast

I'm also using base troop, but I guess it doesn't matter for the code, here is how I did this random attack:

It all starts at making every turn apply a state on actor 1 if a variable is too low.

Spoiler
<Cancel Instant Skill: 1 to 2000>
<Cancel Instant Item: 1 to 2000>

<Custom Action Start Effect>
var independence = 0.5;
if (Math.random() < independence) {
user.startAnimation(142);
if (user.currentAction()) {
user.useItem(user.currentAction().item());
}
user.clearActions();
var logWindow = SceneManager._scene._logWindow;
if (state.message3) {
var msg = '<CENTER>' + user.name() + state.message3 + user.name() + state.message2;
logWindow.addText(msg);
}
BattleManager.actionWaitForAnimation();
logWindow.push('clear');
user.removeState(60);
}
</Custom Action Start Effect>

<Custom Remove Effect>;
var skillusada = Math.floor(Math.random() * 6);
var skill = $gameActors.actor(1)._skills[skillusada];
if ($gameActors.actor(1)._mp <= 0) {
var skill = 1;
}
$gameActors.actor(1).forceAction(skill, -1);
</Custom Remove Effect>

This means that everytime the player clicks to do something there is a 50% chance of the character doing whatever he wants from the pool of skills he has. I'm also using equip skills from yanfly, that's why there is so few skills to choose from.

EDIT: Oops, forgot to put remove state inside the { } thing, now it's ok!

I hope this helps anyone!
Thread closed IgnoreMe

Original thread: https://forums.rpgmakerweb.com/threads/help-with-a-code-using-yanfly-state-core.106987/