Allowing specific states to remain active, even post KO.

Hello! I'm currently trying to figure out an issue I'm having in regards to my own personal take on the tried-and-true; Auto-Life.

What I'm trying to do is create a variation of Auto-Life that activates later, as opposed to instantly. I'm trying to do it this way for game design/balance/flavor reasons.

Of the plugin's that I'm using, YEP's Auto Passive States, BuffsStatesCore, StateCategories, BattleEngineCore, and CoreEngine are among said plugins. I'm also using BattleSysATB (which I'm aware no longer is officially supported).

What I have right now is this; A KO State (State 1), and 2 States called Auto-Life (State 37 and State 38 respectively).
Within the KO State, I have a snippet of code within <Custom Apply Effect> that goes like this;

Code:
if (!user.isEnemy() && user.isStateAffected(37))
{this.removeState(37);
this.addState(38);}

This removes the 1st Auto-Life state, which what is obtained through the auto-life spell and has no sort of expiration and uses the <Category: Bypass Death Removal>, and then adds the 2nd Auto-Life state, which is the state that contains the code for reviving the character.

The 2nd Auto-Life State expires in 5 turns, and carries this effect;

Code:
<Category: Bypass Death Removal>

<Custom Turn End Effect>
var autoLifeTurn = this.stateTurns(38);
var remTurn = autoLifeTurn - 1;
this.setStateTurns(38, remTurn);
</Custom Turn End Effect>

<Custom Leave Effect>
if (user.isDead())
{user.gainHp(user.mhp * 0.3);
user.startDamagePopup();
user.clearResult();
user.startAnimation(50);}
</Custom Leave Effect>

The <Custom Turn End Effect> decreases the state turn by 1, but other than that, it stops and stops decreasing. The <Custom Leave Effect> isnt final as I just was trying to get the state to expire in the first place before i kept adding on to address the potential nonsense and complications that can arise from a delayed auto revive.

The Bypass Death Removals is what allows Auto-Life 2 to even be added after the character is KO'd as without it on Auto-Life State 1, then Auto-Life State 2 doesn't get added when KO is applied.

So far I've been unable to figure out a way to allow states to keep running when the actor is KO'd without some really super roundabout way such as having a dummy state on other characters that decrease the turn count for the KO'd player or something just as extreme, complex, and silly.

If a script needs to be created, than so be it, that at least means that the problem can definitely be solved at that point, but I'd rather exhaust my options before jumping to creating a new script.

Thank you for reading and attempting to help, I hope this was thorough enough of description of my problem, and my attempts to solve it.

Original thread: https://forums.rpgmakerweb.com/threads/allowing-specific-states-to-remain-active-even-post-ko.97783/