How to make a state that uses a specific amount of mp and turns off when you don't have enough mp?

I want the state to use let's say 50 mp every turn, and if you have less than 50 mp it gets removed.
Using VisuStella's States and Skills Core:

<JS Pre-Regenerate>
target.gainMp(-50);
if (target.mp < 50) target.removeState(state.id);
</JS Pre-Regenerate>
Just to confirm - which engine are you asking for? You're posting in MZ support, but your profile says you use VX Ace. You'll get very different answers.
Yeah I'm asking for vx ace, my bad I thought I was posting in vx ace support.

I've moved this thread to VXAce Support. Thank you.

I'll check this out, thanks.

Original thread: https://forums.rpgmakerweb.com/threads/how-to-make-a-state-that-uses-a-specific-amount-of-mp-and-turns-off-when-you-dont-have-enough-mp.145762/