MP -% regeneration not working?

So this is a problem i have been tripping over for the last couple hours because it MAKES NO SENSE...


Why is this -% mp not triggering?


0bb90dceb8.png



The +10% hp recovery works. The MP -regen does not... I'd imagine it would work the same way as poison does, with -hp regen, so i know the function works... But why is it not working for MP??


I have even tried setting these as two different states that activate at the same time, but only the HP one ever does anything. The MP one does not...


To explain what I am trying to do:

I am running a permadeath feature where reaching 0 hp does not kill you. But what it does do, is knock you out for the remainder of the battle, in which the deathstate is removed upon battle end (this works, it also puts you at 1 hp when it does). But what CAN kill you completely is when you reach 0 mp. MP in my game is not actually MP, it's an essence of life energy that once snuffed out, the character is gone. toast, poof, no more. removed from the game. MP damage can happen in one of two ways. Special attacks and other special conditions, but also if you reach 0 hp, you take 10% mp dmg, effectively meaning you can "die" a few times, but not too many.


ANYway.. I am using yanflys auto passive states so that when you do die (0 hp), after battle you recover 10% hp, and lose 10% mp. The only way i've been able to figure out how to do this is through adding an additional state that is added with a condition of your hp being less than 2. (since removal of the knockout state places you at 1 automatically)....


ALL of this works EXCEPT THAT -10% MP!! It just refuses to go down...


All that being said though, if someone can explain to me why this mp dmg is not working, or if they have any more efficient way of doing this, please let me know. Really i just want a very minor recovery with a hit to current mp after the battle is over. That's it. If this can be done differently than the use of states, wonderful. If not, please give me some ideas here.


I already know that I could do this using a similar function i have in a parralel process checking the states of all actors mp at all times to see when they hit zero (even all that works perfectly!), but that's another always running parralel process of huge proportions, and that idea scares me.. (or should i really be scared at all? but god that's a lot of writing).
I haven't tested it, nor am I using the script you're asking about, but I have a question.  Does the subtracting MP work if the character is not dead?  It could be the fact that you have the death state on the character that you cannot lose MP.


I understand that you could gain HP, but still have the state, but I'm not even sure you could lose HP if in the death state.


I'm just curious if it works in any other circumstance except death?  If so, then the Death state is probably your issue.


EDIT:  Would it be possible to make the death state itself subtract 10% of your MP instead of the recovery?  Does it work then?
I haven't tested it, nor am I using the script you're asking about, but I have a question.  Does the subtracting MP work if the character is not dead?  It could be the fact that you have the death state on the character that you cannot lose MP.


I understand that you could gain HP, but still have the state, but I'm not even sure you could lose HP if in the death state.


I'm just curious if it works in any other circumstance except death?  If so, then the Death state is probably your issue.



Nope! The state is only applied when the user is at 1 hp, which is caused by the death state being removed.


That being said, this is the order it happens


1. Character reaches 0 hp and is given death state.


2. battle ends and death state is removed, and the player recieves 1 hp


3. That 1 hp triggers the state that recovers hp and reduces mp. (but it only recovers hp and doesn't reduce the mp!)


The state that changes hp and mp only exists -after- the death state is removed. But again, only the hp is being affected for some reason..
Nope! The state is only applied when the user is at 1 hp, which is caused by the death state being removed.


That being said, this is the order it happens


1. Character reaches 0 hp and is given death state.


2. battle ends and death state is removed, and the player recieves 1 hp


3. That 1 hp triggers the state that recovers hp and reduces mp. (but it only recovers hp and doesn't reduce the mp!)


The state that changes hp and mp only exists -after- the death state is removed. But again, only the hp is being affected for some reason..



I think I figured out your problem.  MP regen only seems to work INSIDE combat.  The state can persist all it likes, but it doesn't mean anything if you're outside of battle.


My suggestion would be to simply have dying itself remove 10% of your MP if you can.


Quick playtest reveals that you can only regen MP in combat instances, doesn't work outside of combat.  I'm not sure if it's hard-coded into the program or not, but that seems to be the case.  HP regen also seems to work the same way, except you're forcing the game to proc the HP regen just based upon having low HP.  Without that proc, I doubt it would work either.  I'm guessing the MP itself is just hard-coded to never proc on world map unless an event triggers it instead of a state.


States can persist or be added on the map, but they don't really do anything there unless you event it so that it does.  They just sit on a character until you enter the next combat.
I think I figured out your problem.  Regen HP works anywhere (in battle or out of battle).  MP regen only seems to work INSIDE combat.  The state can persist all it likes, but it doesn't mean anything if you're outside of battle.


My suggestion would be to simply have dying itself remove 10% of your MP if you can.


Quick playtest reveals that you can only regen MP in combat instances, doesn't work outside of combat.  I'm not sure if it's hard-coded into the program or not, but that seems to be the case.  HP regen also seems to work the same way, except you're forcing the game to proc the HP regen just based upon having low HP.  Without that proc, I doubt it would work either.  I'm guessing the MP itself is just hard-coded to never proc on world map unless an event triggers it instead of a state.


States can persist or be added on the map, but they don't really do anything there unless you event it so that it does.  They just sit on a character until you enter the next combat.



I see... Still the question though is this: The procing is happening on the map. My units gain 10% hp at some point (it actually take a few steps for it to happen), but the mp does not. So there is some slight difference in the two...


Anyway, regardless... 

My suggestion would be to simply have dying itself remove 10% of your MP if you can.



That would be the SIMPLE way of doing it.. if it could be done, but it can't. 


The only way to actually damage mp through the application of a state is by using -mp regen. But even then, as you mentioned before, hp and mp don't seem to be effected when in the death state, so no change. Doesn't work. If there was a way to force that -10% mp the moment they hit 0 hp and be done with it, that would be perfect, but I can't figure out how i can do that.
Okay, HP regen (either positive or negative) seems to happen every so many steps.  MP regen doesn't happen at all on the map.


So... I'm completely at a loss as to how to get it to work without a Common Event.


Personally, I'd just Common Event to check to see if each actor has the "death" state, then revive them, then play around with variables so that you lose 10% of your MP each time, and give you 10% HP at the same time.  It's messy, quite inelegant, and will probably eat up a bunch of memory to have it checking constantly (unless you can find a way to only make it check after each battle).


Otherwise... I guess I'd see if someone else has come up with a script/plugin for exactly what you want.  I'm not sure it can be accomplished currently.  😳 My expertise is really only limited to vanilla RMMV and what little I've played around with it.  I'm sorry I couldn't have been of more help.
How high is the MP of your characters? If the MP to be regenerated is below 1 MP in the end, it will never trigger. Otherwise, it should work as stated. I know in ACE MP Regen works on the map every 15 steps (it's in the default code). Did they maybe accidentally leave it out in the code in MV?
How high is the MP of your characters? If the MP to be regenerated is below 1 MP in the end, it will never trigger. Otherwise, it should work as stated. I know in ACE MP Regen works on the map every 15 steps (it's in the default code). Did they maybe accidentally leave it out in the code in MV?



I have two test subjects who's MP are 100, and 120. 10% mp loss should reduce them to 90 and 108. 


This doesn't happen though. They remain at 100 and 120.
Are you sure your state remains applied to the character long enough so they can tick the mp degen?


How do you make the hp damage happen?


OFVcz10.png



This works correctly in my vanilla game: running around the map removes both hp and mp as soon as a poison flash occurs.


If you ask me how to make a poison damage tick happen, I don't know, sadly.


The other possibility is that a plugin is modifying the mp regen function, but I highly doubt Yanfly would do that. Test it with poison and running around the map and we'll be settled.


If you want a solution using a common event, using the loop I showed you yesterday, take a look at the spoilers below.

Spoiler
First some script calls:



$gameActors.actor(actorId).mmp //will return an actor max mp by its id
$gameActors.actor(actorId).mp //will return an actor current mp by its id
$gameActors.actor(actorId)._states //will return the list of all states affecting an actor in an array [stateId1,stateId2,...,stateIdn]
array.contains(X) //will return true if the array given contains X
$gameActors.actor(actorId)._states.contains(X) // Will return true if actor [actorId] has state [X]
//Edit: instead of that you can use:
$gameActors.actor(actorId).isStateAffected(stateId) //It will be doing the same thing
$gameActors.actor(actorId).removeState(stateId) //will, you guessed it remove state [stateId] from actor [actorId]


Here you can see an example of how it can be done:


tmk5QKI.png



Detailed breakdown:

  • You remember the loop we set up yesterday: Variable 6  "i" will go from 1 to 4 before exiting the loop in this example.
  • So first after the check to see if the actor mp is 0 (for your custom permadeath), we add another check, to see if they have this KO recovery state of yours.
  • If they have we set variable 9 to the actor of id = variable 6 max mp and variable 10 to his current mp.
  • We then do the calculations to get 10% of current MP. (You can change it to 10 percent of max mp by doing (V[9] * 10 / 100)
  • Then we remove the appropriate amount of mp to the actor id = variable 6 ( "i" in my example).
  • The last line removes the KO recovery state.



If you fear about lag: Don't.


The most important factor about lag  is not the amount of calculations inside your common event. Except for very high amounts of calculations, I'm talking ten of thousands, and that should never happen unless something requires recursion, such as pathfinding for example.


The most important factor is actually the number of parallel processes going on at the same time.


Good practices to reduce lag:


Bundle your common event parallel process into a single one using switches to activate or deactivate part of it, instead of having several running at the same time, and you should have no problem.


If you don't already, add a wait at the start of each of your common event parallel processes, you probably don't have to run those calculations 60 times per second, a 10 frame wait will be unnoticeable (it will still run 6 times per second) by the player and pretty much ensures you won't get lag.
Astfgl66 saves the day again!


0fed6a251e.png



I tested the normal poison state with -mp regen added, and it did infact reduce the mp while walking on the map.


So i do have a theory regarding that. Since my trigger is only to be active as a state when the hp is below 2, (1). I think that the engine always applies hp changes before it applies mp changes, regardless of what order you put them in the traits list. That being said, the application of the hp regen is removing the state, which may interrupt the mp from being applied.. It's just a theory anyway. I dunno if trait lists can actually be interrupted like that.


Anyway, your scripting worked like a charm! That makes things so much simpler, and actually works BETTER than a "poison" effect, because the poison effect only ticks after several steps. It's not immidiate. So exiting battle and just checking hp would yield 1 hp, but then taking several steps would cause the tick of regen. Which was sorta not very smooth, if that makes sense.


All this going on, i'm tempted to just look up a list of those script indentities to see what does what. Those scripts are becoming too useful.


Now if i only could get a script that can remove party members based on that ActorID variable, aswell as display a text messege of the name of said ActorID... And then one last thing that i'm not sure could be done... (that last +1 mp adjustment i can craft together with the variables and scripts you gave me here, but I have 1 variable specifically set aside to keep track of "progress" of each individual character. For things like personal story progression for them. I set it to -1 when they die to prevent their events from showing up. The +1 mp at the end is because the commands of remove party member and text popup just kept showing up over and over again because they had 0 mp.)


I will probably post another thread explaining the actorprogress thing in a day or two. Thanks!
@Tsaiuki North


Please look at this for a complete list of script calls equivalent of event commands:





As for your questions:


$gameActors.actor(actorId).name() //will return the name of an actor
$gameParty.removeActor(actorId) //will remove an actor from the party based on his id.


So what you can do is:


$gameParty.removeActor($gameVariables.value(2)) //removes the actor of id = game variable 2 from the party
$gameVariables.setValue(your_variable_number, $gameActors.actor($gameVariables.value(2)).name())
//your variable is now equal to the actor of id = game variable 2 name.


You then just have to make a message calling "\V[your_variable_number] has died." And it will display the name correctly.


Yes, variable are fully capable of holding things other than numbers.


To change hp/mp based on actor id doesn't require a scipt call, you can do it from the event command. But, if you want a script call, here you go:


$gameActors.actor(actorId).gainHp(n) //will increase actor [actorId] hp by [n], you can use negative values.
$gameActors.actor(actorId).gainMp(n)
$gameActors.actor(actorId).gainTp(n)


Having a variable tied to each actor will need either conditionnals or some "clever" thinking. What you could do is have your variables representing story progress for each actor be 100 + actor id.


That way if actor 1 dies you can tell the game to set variable 101 to -1, if actor 27 dies, set variable 127 to -1 instead.


Something like this should work.


$gameVariables.setValue($gameVariables.value(2) + 100, -1)




Script calls are indeed a very easy way to increase the possibilities of event making. If you like them, be sure to check out the google doc inside the thread I mentionned.


You could even check out my plugin. It gives a lot of funtions to use during your script call event commands. If not to use it, checking inside can show you how to return/change most things via script calls.


Hope I helped.
@Tsaiuki North


Please look at this for a complete list of script calls equivalent of event commands:





Having a variable tied to each actor will need either conditionnals or some "clever" thinking. What you could do is have your variables representing story progress for each actor be 100 + actor id.


That way if actor 1 dies you can tell the game to set variable 101 to -1, if actor 27 dies, set variable 127 to -1 instead.


Something like this should work.



$gameVariables.setValue($gameVariables.value(2) + 100, -1)




Script calls are indeed a very easy way to increase the possibilities of event making. If you like them, be sure to check out the google doc inside the thread I mentionned.


You could even check out my plugin. It gives a lot of funtions to use during your script call event commands. If not to use it, checking inside can show you how to return/change most things via script calls.


Hope I helped.



Amazing! Thankyou! 


I do have their variables as 100 + (actor number) already, so that makes this really easy!


Thankyou so much for all of this 🙂

Original thread: https://forums.rpgmakerweb.com/threads/mp-regeneration-not-working.64378/