I'm unsure how you've set up your game. If it were an situation like a mini-cut scene with using magic then you could just use events and do it that way. Similarly, you could call that event during combat. You just apply it for the troops in the database. The following is a tutorial on setting up enemy states. It should work in most situations.
▶ YouTube video
If you have a more custom situation then I also have this solution. This is a small script for changing the enemy state to sleep at 0 MP. It has been a long time since I've used Ruby, it might be pretty rough.
Spoiler: Script
Code:
#==============================================================================
# ■ Enemy MP Zero → Sleep State
#------------------------------------------------------------------------------
# Automatically applies the Sleep state when an enemy's MP reaches 0.
# Works during battle and checks whenever MP changes.
#==============================================================================
module MP_ZERO_SLEEP
SLEEP_STATE_ID = 2 # << Change this to your game's Sleep state ID
end
class Game_Enemy < Game_Battler
alias lj_mp_zero_sleep_change_mp change_mp
def change_mp(value, *args)
old_mp = @mp
lj_mp_zero_sleep_change_mp(value, *args)
# If MP has just hit 0 and the enemy is alive, apply Sleep
if old_mp > 0 && @mp == 0 && alive?
add_state(MP_ZERO_SLEEP::SLEEP_STATE_ID)
end
end
end
I feel like there must be a simple way to do this, but I can't think of one. How many attacks that cost the enemy MP do they have? Is it a recurring enemy, or a one-time boss? You could add a common event to those magical attacks/skills in which you'd check if after they're done, the MP is 0 and then apply the state, but I don't know how time-consuming that would be for you.
I'd assume there would be a script that could do something like this. Maybe try looking at
Yanfly's work, if there's anything that could help?
Note: Wrote this before DrFreeman posted their reply, so maybe it's not relevant any more
Thanks for the replies, that script unfortunately causes a crash even when I try it on a test game with 0 other scripts in it, and the video was not quite what I'm looking for
To explain more thoroughly what I'm trying to do, I'm trying to make it in every fight that if an enemy hits 0 MP than they stun that moment and go into a weakened state (like a stagger) then fully recover their MP at the end of the next turn, so while I was able to get it working at turns end I'd really like the weak state to apply the moment their MP drops to 0
I tried setting enemy MP to a variable that turns a switch on at 0 to activate a battle page to apply the state but I couldnt figure out how to get it running properly
I've also already looked through Yanflys scripts (Though not the lunatic ones thoroughly, there might be something in there to do it) and couldn't see a simple one to get the job done
And if theres just a script that could achieve something similar to the mechanic I'm looking for that could be great too