Free-spirit state help

I was wondering if there was a way for a state to run a common event each turn and remember what skill and target the player selected. I want to make it so there's a 50% chance the player will do the selected skill, and the rest they might do some random action or do something silly. Each one would have a positive effect, but the effect might not be wanted
The way I handle it is to run a Troop event each turn that simply calls a common event wherein you can check whether actors have the state on them and run your events from there. It may involve lots of conditional branches if you want multiple characters to be able to learn this skill, otherwise you can simply do a force action on the one character who knows it.

That leaves how to identify the user's last target. The only way I know of to do this is to use a custom script. I don't know where I originally found it (the cited website is under renovation at the moment), but here's a link to another post in this forum that provided the code:

https://forums.rpgmakerweb.com/inde...ting-conditional-branches-for-a-script.16794/

Using this, you can use the script call battle_info_user.last_target_index to get the enemy index (1-8) of the last enemy targeted by a skill. Store it to a variable using a common event call in the skill's extra effects, to ensure that it fires off immediately after the character does your special skill, so that they are definitely the "last user". Common event calls in skills will always activate immediately after the skill itself resolves, so the timing works well for this.

It's a bit of work, but hopefully you can make something out of all this. 😤

Original thread: https://forums.rpgmakerweb.com/threads/free-spirit-state-help.76866/