MV Make state duration dependend on other battler's state

I'm still not sure how to title this, so here is what I mean:

An enemy inflicts a state on an actor. I want the enemy to be stunned as long as the actor keeps being in this state.

So I created a skill using Yanfly's Action Sequences that inflicted said State A to the Target and State B on the Caster. State B makes the enemy unable to move. Both states have the same duration, so if they wear of naturally they do so at the same time.

But what if the actor with State A dies or is cured? How do I check this and make State B on the original caster disappear? I could do something using battle events, but I think this will only work if there is just one enemy able to use this skill and my battle events are pretty cramped already, so I figured I'd rather use Yanfly's Buffs & States Core to do something like this:

<Custom Action End Effect> if(user.isDead()) { origin.removeState(59); } </Custom Action End Effect>

Unfortuantely I don't know how to refer correctly to the unit the state is inflicted on, nor at which time I should apply this effect, how to make State B wear of, when State A is cured or if this is the right approach at all.
You have the right idea, you just missed the correct notetag - Custom Remove Effect runs when the state is removed manually or due to decay. So inside there you'd just put origin.removeState(59)

The trick is that there are no tags which run when an actor dies and gets stripped of states. So there are a few ways to go about it, but I think the easiest is to make a Custom React Effect that checks whether incoming damage is enough to kill the actor, and if so removes the state from the origin as above.
Thanks! Putting it under Custom Remove Effect worked.
For the next step though, this only works for attacks, right? If the actor is killed by Damage Over Time Custom Respond won't trigger?
Correct. The only way I know to make it trigger if your game has that mechanic is for the state to also make the actor immortal, then every troop that uses this attack has an event page that checks every actor in the party to have no HP, sees if they have the state, remove it from the origin, then remove immortal.
Hmm, I'd rather disable death by damage over time, then, but I also use Custom Regenerate Effect to get those effects. Is there any way to make actors immune to being killed by those kind of effetcs, or maybe make them wear off automatically, if they'd reduce hp to 0?

I know it's slightly off topiv now, maybe I'll need to open another thread, but I'd be thankful for any idea to make this mechanic work properly.
Hmm, I'd rather disable death by damage over time, then, but I also use Custom Regenerate Effect to get those effects. Is there any way to make actors immune to being killed by those kind of effetcs
Several. You could make the damage be based on a percentage of the actor's current hp, so that can never take them to 0. You could use Math.min(your current damage, user.hp-1) so it can never hurt them lower than 1 HP.
or maybe make them wear off automatically, if they'd reduce hp to 0?
Right inside your custom regeneration add a check that says if current HP is 1, remove the state.
You could make the damage be based on a percentage of the actor's current hp, so that can never take them to 0
Wow, that's what I do anyway for all the states that have this effect. I just forgot that I included a line to round up the damage ... Sometimes I feel like the solution is just one minute of thinking away from the point it point where I gave in and asked xD

So deleting that line or using Math.floor instead should also do the trick.

Thank you again! If there aren't any other things that could cause death, I think I'll be able to make this work now.
Sometimes I feel like the solution is just one minute of thinking away from the point it point where I gave in and asked
I have days like that, man.

Original thread: https://forums.rpgmakerweb.com/threads/make-state-duration-dependend-on-other-battlers-state.141337/