Apply a state under one condition and remove it by another

Okay so what I've been trying to do is basically apply a state called "Winded" when a characters resource called "Stamina" is low, like say <40%. Then I want that state to remain applied until the characters stamina has regenerated back to say over 80% to simulate a character having to catch their breath after using too much energy.
I've been trying to do this with the VisuStella Skills and States plugin using the passive state functionality

<JS Passive Condition>
condition = user.mp/user.mmp <= 0.4;
</JS Passive Condition>

This works fine for the first part, but I can't figure out how to have the state remain until more conditions are met, the characters stamina regenerates turn by turn so it goes away immediately (once it goes above the 40% condition), so I tried something like:

<JS Passive Condition>
if
a.states().includes($dataStates[90]) && (user.mp/user.mmp <= 0.8
{
condition = true;
}
else if
(user.mp/user.mmp <= 0.4) {
condition = true;
}
else {
condition = false;
}
</JS Passive Condition>

Which was supposed to be if the state is already applied and the characters stamina is below 80% then it remains applied, but I'm not very well versed in Java and I just get errors on my variations of the above. I'd really appreciate some help if any one has any ideas on how to achieve this, whether with this plugin or some other way I'm not familiar with.
Thanks!
if
a.states().includes($dataStates[90]) && (user.mp/user.mmp <= 0.8
youre missing parenthesis here
You're right! At the very least it starts up for testing now but the condition still doesn't seem to work, the state still goes away once stamina heals past 40%


<JS Passive Condition>
if
(a.states().includes($dataStates[90]) && ((user.mp/user.mmp) <= 0.8))
{
condition = true;
}
else if
(user.mp/user.mmp <= 0.4) {
condition = true;
}
else {
condition = false;
}
</JS Passive Condition>
then it might be the case that the passive eval contains a safeguard to never be able to check if itself is on the battler. Yanfly had a check for that in their version of the passive state plugin.

Maybe instead of trying to create an extended exit condition, you could have the passive give the player the applied version. I dont know if passives getting disabled trigger removal effects in VS as Yanfly's required a patch, but if a removal effect doesnt work, then you can have the passive apply itself to the battler at the end of every turn with user.addState(90) and add !user.isStateAffected(90) to the passive condition. isStateAffected was made to not include passives, so there shouldnt be a recursive loop there.

EDIT: the doc says passives dont trigger apply or removal effects either, and I dont want to test if isStateAffected works the way i think it does with VS's documentation, so try this instead.

Code:
<JS Passive Condition>
condition = user.mpRate() < .4 || user._winded;
</JS Passive Condition>

<JS Post-End Turn>
user._winded = user._winded || 3;
if (user.mpRate() >= .4)
    user._winded--;
</JS Post-End Turn>
shouldn't it be mpRate <= 0.4? rather than user.mp/user.mmp?
unless those are equal.

there is hpRate, so maybe mpRate too.
shouldn't it be mpRate() <= 0.4? rather than user.mp/user.mmp?
unless those are equal.
theyre the same. OP probably didnt know there was a function for it and just used the math youd use to get it normally.
then it might be the case that the passive eval contains a safeguard to never be able to check if itself is on the battler. Yanfly had a check for that in their version of the passive state plugin.

Maybe instead of trying to create an extended exit condition, you could have the passive give the player the applied version. I dont know if passives getting disabled trigger removal effects in VS as Yanfly's required a patch, but if a removal effect doesnt work, then you can have the passive apply itself to the battler at the end of every turn with user.addState(90) and add !user.isStateAffected(90) to the passive condition. isStateAffected was made to not include passives, so there shouldnt be a recursive loop there.

EDIT: the doc says passives dont trigger apply or removal effects either, and I dont want to test if isStateAffected works the way i think it does with VS's documentation, so try this instead.

Code:
<JS Passive Condition>
condition = user.mpRate() < .4 || user._winded;
</JS Passive Condition>

<JS Post-End Turn>
user._winded = user._winded || 3;
if (user.mpRate() >= .4)
    user._winded--;
</JS Post-End Turn>

Thank you for your time, so rather than using the passive state conditions in VisuStella I've managed to get it to work by using the VisuStellaBattleCore and running:

{
if (user.mpRate() <= 0.3) {
user.addState(90);
} else {
}
};

after an action is taken, and then this is ran:

{
if (user.mpRate() >= 0.8){
user.removeState(90);
} else {
}
};
After the regeneration phase. It's now working exactly how I had wanted! Very happy, problem is solved.

Original thread: https://forums.rpgmakerweb.com/threads/apply-a-state-under-one-condition-and-remove-it-by-another.179312/