Make a state cost MP, and lose it if MP hit 0.

Hello, I'd like to incorporate a transformation system into my game.
These transformations cost a certain number of MPs for each action, I would also like it to automatically remove itself if we don't have enough MPs to maintain it.

I googled it, I thought I'd fall on it directly, because it's a very simple idea, but the scripts that come close to what I want always have one of those things missing. Can you help me?
Is the percentage MP reduction per turn using MRG in the default feature database enough? or you want more control over it? i.e, are you requesting a state that expires once the MP runs out or might as well as requesting a custom MP degeneration?
It greatly depends on what meaning the "action" word holds in this situation. An action in battle can be considered a "turn", but out of battle it could be using an item, interacting with an event, or something that is completely unrelated to that. What do you mean by "action"?
The base system of RPG Maker allows a degeneration of a percentage of MP each turn.
What I'd like to do is:
1 - Lose a specific number of MPs
2 - Do it after each action, (as if acting costs MPs)
3 - The state automatically removes if you have less MP than its cost.

Thank you for helping me!
Using the default VX Ace battle system you can achieve that with any normal state and then use troop events at the end of each turn to check if the character affected by that state has enough mp left. If the amount of mp is too low, reduce it to 0 and remove the state, otherwise just subtract the normal amount.

Code:
$game_party.members.each do |m|
  if m.state?(your_state_id)
    m.remove_state(your_state_id) if (m.mp < your_state_cost)
    m.mp -= [m.mp, your_state_cost].min
  end
end

This is the code that you have to put in your troop event for something like that. Just remember to change your_state_id and your_state_cost to be the actual state ID of your state and the mana cost required to sustain the said state.
Hey, try using Lunatic States by Yanfly.


Put in any of the add-on plugins you wish, then within those modules add one more "when" branch into one of the add-ons. It's a bit messy but it works, as you can see here:

1HoQoUL[1].png


Set up your state so that you have it lower your mana as you wish using the MRG (mana regen) stat. It can go negative, doing what you wish!

jx8cPwq[1].png


Then add this to the notetag of the state:
Code:
<close effect: end transform>

Within our when branch, we want this:
Code:
    when /END TRANSFORM/i
      user.remove_state(n) if user.mp == 0 # replace n with your state id

Note that you'll need to replace n with your state id.. We could have this always remove the state its called in by replacing n with state.id, but this way you can make other effects (like stuns) remove the specific transform should you wish. Up to you.

I didn't actually test the above snippet, but I can 99% guarantee it'll work :^)

If you want more state ideas/inspiration, download pretty much any of my games. https://rpgmaker.net/users/Craze/ i keep most of them open so people can poke through and learn how i did things~
Heiruichi's elegant solution is all you need to add the functionality you've described and more importantly exposes you to a very amusing aspect rpg maker. states are a fun thing to toy around with and learn scripting from and you can see the results quickly
I applied your solution. It allows me to remove a state under any conditions I want, it's cool ^^

But I also need to lose a specific number of MPs after each action, not a percentage at the end of each turn as the base RM allows.

As if all skills had an increase of x MP at their cost.
Hey, then you'll need to take a look at Yanfly's Lunatic State script to see what other triggers you can use (you'll probably want to make a new <while effect: string> tag for the status effect.

Then, it's as simple as --

Code:
when /TRANSFORM MP/i
    user.mp -= n # replace n with the mp value you like

If you want it to be based on something else, like a variable ($game_variables[27] for variable 27) or something else, like 1/10 of your MGC stat (user.mp -= [user.mat / 10].to_i), you can do that!
Okay, thanks, I hadn't thought of that ^^

Original thread: https://forums.rpgmakerweb.com/threads/make-a-state-cost-mp-and-lose-it-if-mp-hit-0.116697/