Removing state when TP hits 0 + other questions

---
Greetings! I've modified the thread title as we've moved past the boundaries of the original question. Thank you all for your help! <3
---

Hello, all!

I'm having an issue with a battle mechanic I'm trying to implement. It's a transformation-style state that requires 100 TP to activate (but immediately fills it back up).

It gives stat boosts and unlocks other skills, usually costing TP themselves. Character loses 20% TP per turn. When TP hits 0, the state is supposed to end.

I've made some progress figuring out how to get this to work, but despite my best efforts I'm running into issues. Entering the state and the state itself works fine, but I'm having great difficulty with getting them to exit the state.

I have a common event 'if' statement that's basically 'if character's TP hits 0, remove these states'. And I have a troop event that's trying to call the common event at the end of every turn, in an ATB (wait) battle system.

But for whatever reason, the event isn't working. My guess is that the 'span' of the event has something to do with it, but I'm unsure how to make it function properly.

If span = battle, seems to do nothing
if span = turn, the state stops draining TP each turn
if span = moment, the game softlocks

I'm trying to figure out what to do from here, and wondering what can be done to properly get this to work. I thinkthis should be something do-able with events, but I'm not certain. Could I get advice to address this? My past tutorials were mainly getting advice on an RPG Maker discord on where to look. I'm unsure where to look for additional tutorials. Thank you for your help.

Images attached as follows are

--Plugins List, Actor page, skill page (event is called here as well from previous testing),state page, common event page,troop event page
1710269588426.png
1710269575941.png
1710269564491.png
1710269539291.png
1710269518445.png

1710269478168.png
Why are you making a common event just for this instead of placing those commands into the troop event?

But for whatever reason, the event isn't working. My guess is that the 'span' of the event has something to do with it, but I'm unsure how to make it function properly.

If span = battle, seems to do nothing
if span = turn, the state stops draining TP each turn
if span = moment, the game softlocks
See the tooltip for Span:
1710270797589.png


You definitely don't want Battle, because you need to check this more than once.

You don't want Moment because it will sit there continuously doing it at the end of the turn (your softlock).

As for turn, I don't see what this event could possibly have to do with anything in your state's TP Regeneration.
Okay, I think I might have actually solved something--
Why are you making a common event just for this instead of placing those commands into the troop event?
This part is because I would've needed to put it in every troop, and doing/calling common events makes that a lot easier. I did find a plugin that allows me to have a troop event that gets added to every troop, though.
See the tooltip for Span:
View attachment 298165

You definitely don't want Battle, because you need to check this more than once.

You don't want Moment because it will sit there continuously doing it at the end of the turn (your softlock).

As for turn, I don't see what this event could possibly have to do with anything in your state's TP Regeneration.

I think some of this might actually be visual clarity. I'm realizing that the 'exit state' message either isn't coming up, or otherwise that it gets missed because it goes by too fast. Do you know if a state still has its 'if the state is removed' text if it's removed via event?

I'm going to try and implement a change to the actor's face during the state, I thought that was more of a cosmetic thing but it turns out that clarity is important. With TP regen there's a chance I may have just actually forgot to enter the state during that test battle - I can't replicate the issue after considering that error/mistake.

Beyond that...

I think the event is working okayish at this point, the issue is the TP gain. It looks like the event is only running AFTER the player uses an attack of some sort. This means that their TP hits 0 from the state, but then they gain more TP from the attack they just used, and the event doesn't activate because it comes after the attack.

I'm going to try and adjust this more when I get a chance. Do you have any more possible insight/information on how to figure this out from here?
This part is because I would've needed to put it in every troop, and doing/calling common events makes that a lot easier.
I don't see how. It's one click to copy an event page in one troop and one click to paste the event page in another troop.

It takes more clicks/keystrokes than that to copy or enter the Call Common Event event command and set the Turn End condition separately.

I did find a plugin that allows me to have a troop event that gets added to every troop, though.
Yes, a base troop event plugin is useful for this kind of thing. But you could also do this through a notetag on the state if you're going to add in plugins, so I wasn't going to recommend anything outside the default engine functionality.

(that would be a much more concise way to implement all of this)

I think some of this might actually be visual clarity. I'm realizing that the 'exit state' message either isn't coming up, or otherwise that it gets missed because it goes by too fast. Do you know if a state still has its 'if the state is removed' text if it's removed via event?
It isn't displayed if it's prematurely removed by any means. The only time you see that text is when the state has an Auto-removal Timing and it expires.

You don't have an icon for any of the states to simply see that they've been taken off?

If you want a message, you'd add it to the event.

It looks like the event is only running AFTER the player uses an attack of some sort. This means that their TP hits 0 from the state, but then they gain more TP from the attack they just used, and the event doesn't activate because it comes after the attack.
That's not how it all works.

For one thing, are you using the default battle system or the Time Progress one? That changes what the definition of a "turn" is, and when your troop event runs.

Next, the order of events is:
- you do the skill
- it resolves anything in the skill's Effects area
- you gain the TP gain from the skill
- you have your regeneration phase

Since you brought up plugins, the easiest way to do this would be for you to grab my Eval Tags plugin (from the link in my signature).

In the notes area for your state, put:
Code:
<Regenerate Eval>
if (user.tp <= 0)
{
    user.removeState(1);
    user.removeState(2);
    user.removeState(3);
}
</Regenerate Eval>
where 1, 2, and 3 are the IDs of your three states.
I don't see how. It's one click to copy an event page in one troop and one click to paste the event page in another troop.

It takes more clicks/keystrokes than that to copy or enter the Call Common Event event command and set the Turn End condition separately.


Yes, a base troop event plugin is useful for this kind of thing. But you could also do this through a notetag on the state if you're going to add in plugins, so I wasn't going to recommend anything outside the default engine functionality.

(that would be a much more concise way to implement all of this)


It isn't displayed if it's prematurely removed by any means. The only time you see that text is when the state has an Auto-removal Timing and it expires.

You don't have an icon for any of the states to simply see that they've been taken off?

If you want a message, you'd add it to the event.


That's not how it all works.

For one thing, are you using the default battle system or the Time Progress one? That changes what the definition of a "turn" is, and when your troop event runs.

Next, the order of events is:
- you do the skill
- it resolves anything in the skill's Effects area
- you gain the TP gain from the skill
- you have your regeneration phase

Since you brought up plugins, the easiest way to do this would be for you to grab my Eval Tags plugin (from the link in my signature).

In the notes area for your state, put:
Code:
<Regenerate Eval>
if (user.tp <= 0)
{
    user.removeState(1);
    user.removeState(2);
    user.removeState(3);
}
</Regenerate Eval>
where 1, 2, and 3 are the IDs of your three states.

I'll respond further later, but I'm using the Time Progress (wait) system! It's mentioned in the original post <3 o7
I saw that, but then you weren't using any ATB plugin in your list, so I wasn't sure what to think.
I don't see how. It's one click to copy an event page in one troop and one click to paste the event page in another troop.

It takes more clicks/keystrokes than that to copy or enter the Call Common Event event command and set the Turn End condition separately.
Noted! I'll keep this in consideration for the future
Yes, a base troop event plugin is useful for this kind of thing. But you could also do this through a notetag on the state if you're going to add in plugins, so I wasn't going to recommend anything outside the default engine functionality.

(that would be a much more concise way to implement all of this)
I'm fine with plugins if they're not overwhelmingly complex, or otherwise require an understanding of JS to make function on a basic level. Guides for the plugin's own specific code are fine though

It isn't displayed if it's prematurely removed by any means. The only time you see that text is when the state has an Auto-removal Timing and it expires.

You don't have an icon for any of the states to simply see that they've been taken off?

If you want a message, you'd add it to the event.
I'm still new to this so didn't think to add one. It's been added o7
That's not how it all works.

For one thing, are you using the default battle system or the Time Progress one? That changes what the definition of a "turn" is, and when your troop event runs.

Next, the order of events is:
- you do the skill
- it resolves anything in the skill's Effects area
- you gain the TP gain from the skill
- you have your regeneration phase

Since you brought up plugins, the easiest way to do this would be for you to grab my Eval Tags plugin (from the link in my signature).

In the notes area for your state, put:
Code:
<Regenerate Eval>
if (user.tp <= 0)
{
    user.removeState(1);
    user.removeState(2);
    user.removeState(3);
}
</Regenerate Eval>
where 1, 2, and 3 are the IDs of your three states.

Thank you - I'll try and figure this out. Do you know what I'd do with the plugin if I wanted to swap an actor's face when the state is activated? As well as include a message/swapping face back when the state ends. I see a <State Remove Eval> tag in the plugin's tutorial but don't know the proper code for messages and face-swapping

edit: someone found it!!

the functions are BattleManager._logWindow.addText("text"); and $gameActors.actor(1).setFaceImage("SuperSexyHaroldFaces", 3)
edit: someone found it!!
It's not too hard 😉 There's a pinned thread with script calls, and pretty much all of these things should come right up if you Google "rpg maker mz script call whatever"

$gameActors.actor(1).setFaceImage("SuperSexyHaroldFaces", 3)
Note that this will only work correctly if your game is only using one actor. Or if only one actor can ever be affected with the state.

If you have other actors in your party, you'll need to refer directly to them, not to actor ID 1; and you'll need to track what their portrait is supposed to be.
It's not too hard 😉 There's a pinned thread with script calls, and pretty much all of these things should come right up if you Google "rpg maker mz script call whatever"


Note that this will only work correctly if your game is only using one actor. Or if only one actor can ever be affected with the state.

If you have other actors in your party, you'll need to refer directly to them, not to actor ID 1; and you'll need to track what their portrait is supposed to be.

Thank you! I was digging through the script calls logs myself but it was... a lot to get through--

And thank you. I think my only remaining question is whether I need to include the file extension (.png) to point to it, but I can figure that out in my testing. I'll edit this if I have any further issues!

edit: oh boy

Good news, I can enter the state fine, and I think it's removing okay. That said I have two bugs

One of them isn't game breaking - the state for changing the actor's face works, but it changes right back immediately after, even though the state is still present (through the state icon.)

The other is, though. I have a skill that's supposed to 'reload ammo' (basically recharge 100% MP). For whatever reason having Evaltags enabled breaks this entirely. When I use it, the character's ammo bar completely disappears, and I'm unable to use the Attack or Guard skills outright. Furthermore, the reload skill is greyed out and unusable.

The ammo bar disappearing remains persistent after the battle has finished. The character's 'Max MP' is granted by their gun rather than a built-in MP system. When trying to unequip a weapon, it returns TypeError Cannot read property 'clamp' of null. This is consistent even when all other plugins are turned off

I'll attach screenshots of possibly relevant information and see what can be done. I may move this to a thread in plugin support if this thread isn't sufficient for this kind of assistance.

1710296053766.png

1710296067485.png

1710296090251.png

1710296106647.png
You don't.
You don't.
Thank you o7

I've run into some bugs with the plugin that were edited into the above post, if you're still available to help. No new error messages show up in the F8 console either.
Basic overview: need more information on everything in order to effectively start troubleshooting.

One of them isn't game breaking - the state for changing the actor's face works, but it changes right back immediately after, even though the state is still present (through the state icon.)
Please paste the entire notetag and its contents.

The other is, though. I have a skill that's supposed to 'reload ammo' (basically recharge 100% MP). For whatever reason having Evaltags enabled breaks this entirely. When I use it, the character's ammo bar completely disappears, and I'm unable to use the Attack or Guard skills outright. Furthermore, the reload skill is greyed out and unusable.
I can't immediately think how that's possible. There are certain functions that I had to replace, rather than alias, in the plugin due to where the notetags resolve; but there's nothing in there that touches whether skills are usable or UI elements being drawn.

The ammo bar disappearing remains persistent after the battle has finished. The character's 'Max MP' is granted by their gun rather than a built-in MP system.
Then tell us which plugin is doing it and show how the item is configured.

When trying to unequip a weapon, it returns TypeError Cannot read property 'clamp' of null.
There's nothing in there that should be running when items are equipped or unequipped. When you get an error, you need to press F8, go to the Console tab, and provide a screenshot of the full error trace.

So just to check - whenever you add plugins, change database information (like notetags) or plugin parameters: you need to make the changes, save your project, and start a new playtest - don't try to load an existing save game.

Loading a save can introduce unexpectedly random results, which does sound like some of what you have going on.
Basic overview: need more information on everything in order to effectively start troubleshooting.


Please paste the entire notetag and its contents.
Update: this got fixed. I managed to do it by moving the skill's TP gain from 'invocation' to 'effects.' Since it's supposed to cost 100 tp then recover that back. I'm guessing that the invocation happened at the same time as the face check, and that caused an issue.


<State Apply Eval>

{
$gameActors.actor(1).setFaceImage("protagssurge", 0)

}

</State Apply Eval>

<Regenerate Eval>

if (user.tp <= 0)

{

user.removeState(32);

}

</Regenerate Eval>

<State Remove Eval>

{

$gameActors.actor(1).setFaceImage("protags", 0)

}

</State Remove Eval>

I can't immediately think how that's possible. There are certain functions that I had to replace, rather than alias, in the plugin due to where the notetags resolve; but there's nothing in there that touches whether skills are usable or UI elements being drawn.
My best guess it that it breaks the MP/skills system somehow? the MP bar disappears, and all the character's skills are unusable - including those that have nothing to do with MP, such as the TP-related transform skills. This is true even when ammo is renamed back to MP.

Screenshots are available below.
1710300912926.png
1710300939950.png
1710300956142.png
1710300983066.png

Then tell us which plugin is doing it and show how the item is configured.
Actor stat spread and the item stats are listed. TUR_Evaltags is 100% the plugin in question - turning it off resolves the bug, and the bug is still present even when all other plugins aside from it are disabled.

1710301208569.png

1710301223183.png

There's nothing in there that should be running when items are equipped or unequipped. When you get an error, you need to press F8, go to the Console tab, and provide a screenshot of the full error trace.
Full error trace found - I didn't think to check it at the crash itself instead of when the MP bar disappeared.[ATTACH type="full"]298195[/ATTACH]
So just to check - whenever you add plugins, change database information (like notetags) or plugin parameters: you need to make the changes, save your project, and start a new playtest - don't try to load an existing save game.

Loading a save can introduce unexpectedly random results, which does sound like some of what you have going on.
I can confirm I'm starting a new game! I have the game start me in a testing room for combat scenarios.
Just so you know, all of those braces you have in your notetag code are unnecessary and don't do anything.

As far as the UI and skill stuff...I can't duplicate any of it. I put the plugin into a new MZ test project. I made the battle system be front view and Time Progress, just like yours.

All MP gauges and skills display as expected.

As you can see from the error trace you posted, my plugin isn't even on the list of code files leading up to the crash. The error is happening when the battlers refresh and one of them somehow has a null or undefined value for MP.

I don't know what else to suggest beyond deleting your plugins from your plugin manager, saving your project, then installing them again.

You'll have to reconfigure any plugin parameters you set, but this will clear any weird settings that might be causing issues.
Just so you know, all of those braces you have in your notetag code are unnecessary and don't do anything.

As far as the UI and skill stuff...I can't duplicate any of it. I put the plugin into a new MZ test project. I made the battle system be front view and Time Progress, just like yours.

All MP gauges and skills display as expected.

As you can see from the error trace you posted, my plugin isn't even on the list of code files leading up to the crash. The error is happening when the battlers refresh and one of them somehow has a null or undefined value for MP.

I don't know what else to suggest beyond deleting your plugins from your plugin manager, saving your project, then installing them again.

You'll have to reconfigure any plugin parameters you set, but this will clear any weird settings that might be causing issues.

Thank you for trying! I'll do what you said and try to see if I can't do further work to isolate the issue. Deleting the other plugins didn't work - I'll try again on a new project and port stuff over until it breaks.

Edit: I FIXED IT HOLY

The reload skill was set up badly. In addition to 'recover MP' under effects, it had 'MP Recover' as the damage type w/o a formula from when I was tinkering with things. It went unnoticed without Evaltags, but whatever not having a formula did broke the MP system with the plugin.

Original thread: https://forums.rpgmakerweb.com/threads/removing-state-when-tp-hits-0-other-questions.166733/