Common Event Variables giving MP by going into negative numbers. [SOLVED]

So I'm having a very curious issue. I'm attempting to set up a very simple counter system, where I use conditions to check for counter states, roll a variable, and if the variable is higher than a certain number, the counter is triggered and damage is dealt. I wrote this myself because I wanted more control over both the events I can trigger and states I can use in the counter process itself. For example, the enemy has different body parts that can be damaged, and if that part of the enemy has 0 HP, not only does it vanish, but the main body loses one of its attack types.

In making this I have a simple alternative attack sequence using common events for the enemies, which also includes writing out the code for the usual attack sequence as variables, and applying it to the player character, though I did decrease the multiplying factors because I'm using less HP and MP than is standard. Here's what I've written:

◆Control Variables:#0011 Enemy Attack Roll = Attack of #1
◆Control Variables:#0011 Enemy Attack Roll *= 2
◆Control Variables:#0012 Player Defence Roll = Defense of Player
◆Control Variables:#0011 Enemy Attack Roll -= Player Defence Roll
◆Show Animation:Player, Bodyslam (Wait)
◆Play SE:Damage5 (90, 100, 0)
◆Change MP:Player, - {Enemy Attack Roll}

Now I am having a very unusual situation, where if the Player Defence Roll variable is higher than the Enemy Attack Roll variable, then instead of dealing 0 damage to the player's MP, it actually gives them MP instead, using the negative value. Changing it so that the player receives MP, ignores the negative value and still gives them full MP.

EDIT: I actually fixed this as I wrote this, typing it out here gave me an idea and I put it in play. The problem is the program does not seem to recognise the issue if you try to use an if statement/condition to recognise a variable that's at 0 or less. For example:

◆Control Variables:#0011 Enemy Attack Roll = Attack of #1
◆Control Variables:#0011 Enemy Attack Roll *= 2
◆Control Variables:#0012 Player Defence Roll = Defense of Player
◆Control Variables:#0011 Enemy Attack Roll -= Player Defence Roll
◆Show Animation:Player, Bodyslam (Wait)
◆If:Enemy Attack Roll ≥ 0
◆Control Variables:#0011 Enemy Attack Roll = 1
◆
:End
◆Show Animation:Player, Bodyslam (Wait)
◆Play SE:Damage5 (90, 100, 0)
◆Change MP:Player, - {Enemy Attack Roll}

I wrote this out and it does not work, the 0 on ◆If:Enemy Attack Roll ≥ 0 needs to be changed to 1 or higher, so that the code looks like the following:

◆Control Variables:#0011 Enemy Attack Roll = Attack of #1
◆Control Variables:#0011 Enemy Attack Roll *= 2
◆Control Variables:#0012 Player Defence Roll = Defense of Player
◆Control Variables:#0011 Enemy Attack Roll -= Player Defence Roll
◆Show Animation:Player, Bodyslam (Wait)
◆If:Enemy Attack Roll ≥ 1
◆Control Variables:#0011 Enemy Attack Roll = 1
◆
:End
◆Show Animation:Player, Bodyslam (Wait)
◆Play SE:Damage5 (90, 100, 0)
◆Change MP:Player, - {Enemy Attack Roll}

I wanted to post this despite solving it as I was typing it, because I might forget the solution later or somebody else might have had the same issue. There are only minor problems now, where the animation doesn't seem to be playing and I need to display damage numbers for the players.
>= 0 means equal to 0 or higher, so that should work to 1.

but while it becomes negative, you want to use < 0 (lower than 0)
and than set it to 1 or to 0 otherwise, if its higher, you don't want it to be
1 but the number to lose it full like 10-20 as well.

problem left here is that the MP can be lower than 0 this way, so if it does,
you need to set the MP to 0 if it gets lower as fail-safe =)
>= 0 means equal to 0 or higher, so that should work to 1.

but while it becomes negative, you want to use < 0 (lower than 0)
and than set it to 1 or to 0 otherwise, if its higher, you don't want it to be
1 but the number to lose it full like 10-20 as well.

problem left here is that the MP can be lower than 0 this way, so if it does,
you need to set the MP to 0 if it gets lower as fail-safe =)
Oh that's interesting! I'm glad I still opened this up, partially because I did get the greater than sign wrong as you explain (that's somewhat embarrassing) but I didn't know that MP could actually be lower than 0, that's probably going to help me later down the line, so thanks for the advice.

>= 0 means equal to 0 or higher, so that should work to 1.

but while it becomes negative, you want to use < 0 (lower than 0)
and than set it to 1 or to 0 otherwise, if its higher, you don't want it to be
1 but the number to lose it full like 10-20 as well.

problem left here is that the MP can be lower than 0 this way, so if it does,
you need to set the MP to 0 if it gets lower as fail-safe =)
I'm kind of at a loss honestly for how to set MP to 0. It seems simple enough, have a variable be that of MP, if the variable is less than 0, set it to 0, and set the MP to equal that variable. Unfortunately, there doesn't appear to be a way to have the MP to equal that variable, change MP only allows me to increase or decrease MP by a certain amount.
I'm kind of at a loss honestly for how to set MP to 0.
if you use multiple actors and it would go lower than 0 (like -10), than its
better to grab the snippet from the core that handles this, and hardcode to 0
if it goes below it (as I think it was there) but unsure, but you gotta test for
results and outcomes if it goes to 0 if below it or not, if not, your good, it if does,
than try to find what handles the mp handling and hardcode it there in plugin.
if you use multiple actors and it would go lower than 0 (like -10), than its
better to grab the snippet from the core that handles this, and hardcode to 0
if it goes below it (as I think it was there) but unsure, but you gotta test for
results and outcomes if it goes to 0 if below it or not, if not, your good, it if does,
than try to find what handles the mp handling and hardcode it there in plugin.
I decided to use the following script:

$gameParty.battleMembers().forEach(function(actor) {
actor.setMp(0);
});

So altogether the MP Failsafe looks like this:

◆Control Variables:#0021 MP Failsafe = MP of Player
◆If:MP Failsafe < 0
◆Control Variables:#0021 MP Failsafe = 0
◆Script:$gameParty.battleMembers().forEach(function(actor) {
:Script: actor.setMp(0);
:Script:});
◆
:End

This works (I tested it repeatedly with setting MP to 50 instead of 0 and with MP Damage set way too high), and I only have one playable character in the game so setting the MP for everyone to 0 doesn't really matter. I tried setting it so that only party member #1 would have 0 MP, but I guess I don't know how to write out the script that the game will want because different variations of calling the first party member (using $gameParty.members()[0] and other functions rather than .forEach since that doesn't work when you're calling only a single member) don't seem to be working so well. I'm not sure how to get the game to recognise them as the only actor being called.

I also had the MP Failsafe be set to 0 for use in later events, rather than this one since MP falling to 0 in my game currently has the player result in an exhausted state, and this will let me record how many times that happened in other events in case I want to do something with the player being exhausted 3 times in one battle, as an example, and it should be fine anyway since the MP Failsafe will be refreshed every time the player is hit.
$gameParty.leader() could work, as it has 1 member (always the leader in this case).
or testing isBattleMember function.

but if forEach or .some can work better for a single actor, than it is a nice failsafe
if it does indeed drop below 0MP as fail-safe.

fail-safes can also avoid soft locking to prevent other things, if the skill
are complex and unable to make inside the notetag of what you seek 🙂

Good luck with your project ^^
$gameParty.leader() could work, as it has 1 member (always the leader in this case).
or testing isBattleMember function.

but if forEach or .some can work better for a single actor, than it is a nice failsafe
if it does indeed drop below 0MP as fail-safe.

fail-safes can also avoid soft locking to prevent other things, if the skill
are complex and unable to make inside the notetag of what you seek 🙂

Good luck with your project ^^
That would probably work, but the idea is to figure out how to call each party member for having 0 MP in case I do a game that has more than 1 party member later. I probably wouldn't do the same system with that, since my game has a number of additional systems tied to this alternate attack sequence that would be annoying to manage if you had to do it more than once per turn. It's fine to have the player change one character's state to better counter an enemy, but when they need to do it 2-4 times in a row, it's just busy work. I could have a separate skill/sequence that would make everyone's state change at the same time, but then that would just feel like you have 1 party member attacking 2-4 times.

I'll put that on the backburner for now, since the best way to manage more than 1 party member for this sort of system eludes me, and just work on finishing this product as it is. Thanks for your help.
probably in a loop for actors or party members for this line:

$gameParty.leader().mpbut I need to check
that for myself in the core or parts to get the correct code.
so only the id is taken and not each one (depending on which turn)

but based on variable, you need to store somehow the variable battlemember.

so you can do $gameParty.member()[$gameVariables.value(21)].mp and set this member
mp to 0 (0, 1, 2, 3) for 4 party members) but the value of this can be set based on
actors turn.

but you got to find that so it target the correct battlemembers position,
and use that for its MP 🙂
This thread is closed due to being marked solved. Report the next one so it’s easy to find! If you need this thread reopened, report it to let us know. Thank you!

Original thread: https://forums.rpgmakerweb.com/threads/common-event-variables-giving-mp-by-going-into-negative-numbers-solved.177393/