MV MP reaching 0 induces state, Sleep

Hello! I was wondering if there was a way, preferably without plugins, to make it so that running out of MP causes the character to fall asleep.

The idea is that the character gets exhausted, the Sleep state is induced, and they rest for 2-3 turns; restoring their MP by a certain percentage.

I have created a status called Sleep, that causes the unit to not act for 2-3 turns, and made it so that it restores MP - but I am not sure how to make it so that it triggers upon running out of MP.
Without plugins, I would think you'd need to make a troop event for every troop in the game, checking every turn if any character is out of MP, then apply sleep to that character. It's gonna be fairly many conditional branches depending on how many characters there are, so using a plugin would be recommended.
Without plugins, I would think you'd need to make a troop event for every troop in the game, checking every turn if any character is out of MP, then apply sleep to that character. It's gonna be fairly many conditional branches depending on how many characters there are, so using a plugin would be recommended.
Thank you for the response! Are there any plugins you would recommend? I'm rather new to this, I only started 4 days ago. I looked a little into adding plugins the other day, and to be frank I cannot afford the $30 for Yanfly's pack. Do you know if there are any free (or at least more affordable) alternatives? I'm not sure where to begin.
More affordable than pretty much any plugin you'll ever need for 30 bucks? No lol. That being said, yanfly has a whole bunch of plugins for free still: https://yanflyengineplugins.itch.io/free-starter-pack-essentials

The ones you're looking for are autopassive states and buffs and states core (You'll also need the battlecore engine and perhaps the regular core engine ones, as they serve as a requirement for most of his other plugins, you'll have to check the descriptions). With them, you can add a state to your characters that they'll always have active and within that state you can have a notetag with a custom turn end effect that automatically applies the sleep state whenever their MP is 0.

The notetag should look something like this:
Code:
<Custom Turn End Effect>
if (user.mp === 0 && !user.isStateAffected(X)) {
  user.addState(X);
}
</Custom Turn End Effect>

Replace x with the ID of your sleep state.
One issue I can see with this is when your MP economy doesn't really end up with them having 0 MP. If they even got 1 MP left, this would not trigger.
More affordable than pretty much any plugin you'll ever need for 30 bucks? No lol. That being said, yanfly has a whole bunch of plugins for free still: https://yanflyengineplugins.itch.io/free-starter-pack-essentials

The ones you're looking for are autopassive states and buffs and states core (You'll also need the battlecore engine and perhaps the regular core engine ones, as they serve as a requirement for most of his other plugins, you'll have to check the descriptions). With them, you can add a state to your characters that they'll always have active and within that state you can have a notetag with a custom turn end effect that automatically applies the sleep state whenever their MP is 0.

The notetag should look something like this:
Code:
<Custom Turn End Effect>
if (user.mp === 0 && !user.isStateAffected(X)) {
  user.addState(X);
}
</Custom Turn End Effect>

Replace x with the ID of your sleep state.
One issue I can see with this is when your MP economy doesn't really end up with them having 0 MP. If they even got 1 MP left, this would not trigger.
Thank you so much! I appreciate your help. I had no idea some of them were available for free, I'll be sure to use those and I'll probably save up for the full package too. You also bring up a good point at the end there, I'll have to think of a solution for that. Thanks for pointing that out!
You also bring up a good point at the end there, I'll have to think of a solution for that
The first solutions i see would be making sleep trigger once youre below some threshold like 10%, allow mp values to be negative, or make all your skill costs cap out to the user's current mp. Each one of those would bring their own quirks to how a player would appproach the game though.

The latter 2 require different plugins though. The 3rd could use yanflys skill core (also free) but the 2nd afaik would need a custom plugin
The first solutions i see would be making sleep trigger once youre below some threshold like 10%
I like that idea, any clue what the code for that would look like? Would I just have to edit the code from earlier in the thread? Not sure how that would work, I'm not really familiar with coding. I ended up installing the autopassive states and buffs and states core and the skill core, as well as the other plugins from the free package, if that helps. Thank you for the reply!
If I'm not mistaken, it should be edited like this:
Code:
<Custom Turn End Effect>
if (user.mp <= user.mmp * 0.1 && !user.isStateAffected(X)) {
  user.addState(X);
}
</Custom Turn End Effect>
With them, you can add a state to your characters that they'll always have active
Hey, I know it's been a hot second but I have one last question (I think)! How do I make it so that the state is always active?
Hey, I know it's been a hot second but I have one last question (I think)! How do I make it so that the state is always active?
The autopassive state? By reading the plugin instructions from autopassive states.
1752432627573.png

1752432657234.png

1752432690387.png

Not sure if I'm doing this correctly, everything works fine until I add <Passive State: 0013>, then I get this error message when I try to playtest the game doing a battle test.

When trying to playtest the full game, I get this:
1752432961086.png

When I remove "<Passive State: 0013>", everything works fine again.

Am I doing something wrong?
remove 0 as 0013 just as 13, no leading 0 as it cause tons of errors
if you add them, always use it without it.
Tysm, that worked! One last problem - How do I make it so that the Sleep state restores 30% of the actor's MP?

1752434497327.png

This part doesn't do what I thought it did, so the MP stays below the 10% threshold - keeping the actor in an endless loop of falling asleep.

Thank you guys so much again for your help!
How do I make it so that the Sleep state restores 30% of the actor's MP?
give the state a trait to regenerate the user's mp
This part doesn't do what I thought it did, so the MP stays below the 10% threshold
you reduced the user's max mp by 70% instead of regenerating it

Original thread: https://forums.rpgmakerweb.com/threads/mp-reaching-0-induces-state-sleep.177696/