MV [SOLVED]Applying a state based on TP

Hi! I'm trying to achieve something I thought I could do easily enough, but clearly I'm missing something.

What I'd like is: when an actor's TP = max (in this case, 100) a state is applied to that actor. When their TP reaches 0, the state is removed.

I'm using yanflys states/buffs core and auto passives, but I'm definitely missing something. I can get the state to apply but not remove.

Any help?
It would be helpful if you showed what you already have that is partially working.

See Yanfly's Trance Tip and Trick:
Hi @magfeenix. I assume you can already apply the state at 100 TP so we'll only tackle the removal when TP reaches 0.

Can you try the following and see if they work? Place the following notetags in your "Actor Passives" state.
Spoiler: State Lost at TP <= 0
JavaScript:
// Usually TP is depleted when the actor uses a skill.
<Custom Action End Effect>
var tpStateId = 10;    // set this number to your TP state
if (user.isStateAffected(tpStateId) && user.tp <= 0) user.removeState(tpStateId);
</Custom Action End Effect>

// In case another actor or enemies have skills that deplete TP.
<Custom Respond Effect>
var tpStateId = 10;    // set this number to your TP state
if (target.isStateAffected(tpStateId) && target.tp <= 0) target.removeState(tpStateId);
</Custom Respond Effect>
EDIT: Added case for adding and removing at TP max and min.
Spoiler: State Applied / Lost at TP >= 100 / TP <= 0
JavaScript:
// Usually TP is depleted when the actor uses a skill.
<Custom Action End Effect>
var tpStateId = 10;    // set this number to your TP state
if (!user.isStateAffected(tpStateId) && user.tp >= 100) user.addState(tpStateId); // in case TP is GAINED after using a skill
if (user.isStateAffected(tpStateId) && user.tp <= 0) user.removeState(tpStateId); // usual case, TP is consumed by a skill
</Custom Action End Effect>

// TP is normally GAINED when the actor gets damaged with an attack.
// TP is sometimes lost through TP draining skills.
<Custom Respond Effect>
var tpStateId = 10;    // set this number to your TP state
if (!target.isStateAffected(tpStateId) && target.tp >= 100) target.addState(tpStateId); // usual case, TP gained depending upon amount of damage inflicted on actor
if (target.isStateAffected(tpStateId) && target.tp <= 0) target.removeState(tpStateId); // sometimes skills that hit the actor deplete the latter's TP
</Custom Respond Effect>

// In case TP regenerates or certain states add or deplete TP at the end of each turn.
<Custom Turn End Effect>
var tpStateId = 10;    // set this number to your TP state
if (!user.isStateAffected(tpStateId) && user.tp >= 100) user.addState(tpStateId); // usual case for TP regeneration
if (user.isStateAffected(tpStateId) && user.tp <= 0) user.removeState(tpStateId); // sometimes certain states increase or decrease TP at the end of each turn
</Custom Turn End Effect>
@wolfr136a1 The odd thing about that code is that it seems to be relying on the passive state triggering another state when the user is at 100 tp.

There are ways to do that, you could use my snippet to enable Apply Effects on passive states, or you could use an embedded variable like Yanfly does in his Trance tip, but if you're going to make the passive have that much code in it, you might as well just put everything in there instead of using a second state.
@wolfr136a1 The odd thing about that code is that it seems to be relying on the passive state triggering another state when the user is at 100 tp.

There are ways to do that, you could use my snippet to enable Apply Effects on passive states, or you could use an embedded variable like Yanfly does in his Trance tip, but if you're going to make the passive have that much code in it, you might as well just put everything in there instead of using a second state.
With that code you can add multiple non-passive states depending on TP levels instead of having to add <Custom Passive Condition> notetags on every single one of them.

Sure, with Yanfly's Auto Passive States there are built-in conditions that determine when a passive state becomes active. However from my past experience with YEP Auto Passive States using multiple <Passive Condition: x> or <Custom Passive Condition> notetags tend to cause a lot of lag.
With that code you can add multiple non-passive states depending on TP levels...using multiple <Passive Condition: x> or <Custom Passive Condition> notetags tend to cause a lot of lag.
I mean, you're not wrong, but the OP only asked about "a state," there's no real reason to assume he'd have any intent to manipulate more than one.

But the code you added for checking and adding definitely improves your solution.
I mean, you're not wrong, but the OP only asked about "a state," there's no real reason to assume he'd have any intent to manipulate more than one.

But the code you added for checking and adding definitely improves your solution.
Well, yeah, you're right, he only asked for one. But he did mention he already figured out how to apply the state so I only supplied the code snippet for when to remove them. I just added the adding part because why not?

I have to agree with you it's a bit roundabout. Using a state to apply another state. But that is the solution I developed to counter the lags from Yanfly's Auto Passive States if such passive states have passive conditions. The code is for in case the OP requires a "lag-resistant" code if you will.

The OP is welcome to use the built-in notetags from YEP Auto Passive States. This is his thread after all.
Agreed, he has two viable solutions at this point.

I have to ask under what conditions you've encountered this lag that you keep designing around. I, at some points of my game, will have maybe two passives with states on each character in my party, and I've never seen any lag during combat (on a, say, medium-powered laptop). I feel like there might be something else wrong there.

But that's not the point of this thread 😉
Agreed, he has two viable solutions at this point.

I have to ask under what conditions you've encountered this lag that you keep designing around. I, at some points of my game, will have maybe two passives with states on each character in my party, and I've never seen any lag during combat (on a, say, medium-powered laptop). I feel like there might be something else wrong there.

But that's not the point of this thread 😉
Passive states by themselves don't cause lag. Passive states with <Passive Condition: Stat Above x> and <Custom Passive Condition> condition that track stats do.

Or maybe my computer is just ancient.

Well yeah, this isn't the point of this thread. But we're both helping to solve the OP's problem, not each other's.😛
Hey, how about this thing: https://forums.rpgmakerweb.com/index.php?threads/damage-formulas-101.81905/ ? If this works, there is no need even for a plugin.
If you must use passive conditions @magfeenix here is the code. Just put this inside your TP State's notetag.
Spoiler: Code
JavaScript:
<Custom Passive Condition>
condition = false;
if (user.tp >= user.maxTp()) {
  condition = true;    
  user._tpState = true;
} else if (user._tpState) {
  condition = user.tp > 0;
  user._tpState = condition;
}
</Custom Passive Condition>
It would be helpful if you showed what you already have that is partially working.

See Yanfly's Trance Tip and Trick:
This actually worked perfectly! Thank you to everyone who had input. I have another issue, not entirely related to this one. Yanfly's Party Limit Gauge draws above message boxes, obscuring any messages/text that happens in battle. Does anyone know any code to make it draw beneath the message boxes? (Or, should I make a new thread?)

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/solved-applying-a-state-based-on-tp.143429/