Yanfly Buff & States Core - force action upon state expiring

http://yanfly.moe/2015/12/25/yep-50-buffs-states-core/
Go to 6:22 in the video so you'll know what I'm asking about.

Does anyone know the syntax that would force the actor who has a state (that lasts a few turns) to perform a skill/action when said state expires? (This would be like a curse state, that kills the actor when it expires)

And, similarly, syntax that would have a chance (let's say 50%) of forcing the actor with said state to perform a skill/action upon their turn starting, before their chosen action/skill? (this would be used like confusion in Pokemon. 50% actor will get a state that prevents them from acting that turn)
Check out these links, they might be helpful. At the very least it's a good jumping off point.

http://yanfly.moe/2016/07/22/tips-tricks-paralyze-pokemon-rpg-maker-mv/#more-3341

http://yanfly.moe/2016/07/02/tips-tricks-jump-final-fantasy-4-rpg-maker-mv/#more-3239
What you are looking for is the <Custom Leave Effect> header.

It will look something similar to this:

<Custom Leave Effect>
// Get the landing skill.
var skill = 295;
// Get the last targeted index.
var target = -2;
// Queue the forced action.
BattleManager.queueForceAction(user, skill, target);
</Custom Leave Effect>

var skill is the skill ID of the forced skill.
var target is the target ID
BattleManager is the actual script call to force the skill.
Ooooh, nifty! This is a great starting point. Thanks for point this out!

Original thread: https://forums.rpgmakerweb.com/threads/yanfly-buff-states-core-force-action-upon-state-expiring.79030/