MZ MZ version of Unstable Affliction (Yanfly Tips & Tricks)

So I attempted to make a variant of Unstable Affliction from Yanfly Tips & Tricks. Following the tutorial here, I was able to come up with this:


JavaScript:
<JS On Erase State>
  const dispeller = BattleManager._subject;
  if (dispeller) {
    const stateId = 28;
    $gameTemp.requestAnimation([dispeller], 57);
    dispeller.addState(stateId);
  }
</JS On Erase State>

The intended effect works fine. If anyone dispels the effect, it will be transferred to them instead. However, it has an unintended effect where if anyone kills the target, they are also considered a "dispeller" since the system removes the control effect on the actor's death.

What would I have to do to prevent this? I tried adding: "&& target.hp >= 1" in front of "if (dispeller)," but it didn't seem to like that, as battles would not load.
I tried adding: "&& target.hp >= 1" in front of "if (dispeller),"
That's not valid JavaScript syntax.

It would be
Code:
if (dispeller && target.hp >= 1)

I also don't see the purpose of the whole dispeller variable...it's just getting the current active battler, which the user variable already is.

Perhaps the variables in the notetags were changed since Trihan started that thread.
That's not valid JavaScript syntax.

It would be
Code:
if (dispeller && target.hp >= 1)
So basically all I had to do was place it in the parenthesis. I don't know why I didn't think of that.

In any case it works, thanks.

Original thread: https://forums.rpgmakerweb.com/threads/mz-version-of-unstable-affliction-yanfly-tips-tricks.172387/