MZ Storing damage for counterattack || Visustella plugins

So I'm attempting to copy a skill from Yanfly Tips and Tricks MZ version again. I'm trying to make a version of Bide, where the user gains a state, takes a certain amount of damage while the state is active, and deals it back to the targets when the state is removed. I tried to modify it so it takes the physical and magical damage separately, then whichever is larger determines the damage dealt.

The problem seems to be with the damage, but I don't know why exactly? For starters, my code doesn't even show the number popups, so I'm not sure if I formatted something wrong or if it's not reading the variables?

JavaScript:
<JS On Add State>
user._physicalDamageTaken = 0;
user._magicalDamageTaken = 0;
</JS On Add State>

<JS Pre-Damage As Target>
if (this.isPhysical() && value > 0) {
target._physicalDamageTaken += value;
} else if (this.isMagical() && value > 0) {
target._magicalDamageTaken += value;
}
</JS Pre-Damage As Target>

<JS On Erase State>
$gameTemp.requestAnimation([user], 97);
if (user._physicalDamageTaken >= user._magicalDamageTaken) {
const damage = Math.ceil(user._physicalDamageTaken);
} else {
const damage = Math.ceil(user._magicalDamageTaken);
}
const enemies = user.opponentsUnit().aliveMembers();
for (const enemy of enemies) {
$gameTemp.requestAnimation([enemy], 107);
enemy.gainHp(-damage);
enemy.startDamagePopup();
enemy.clearResult();
}
delete user._physicalDamageTaken;
delete user._magicalDamageTaken;
</JS On Erase State>

I tried to use the original skill's code as a reference, but even that's not working. The damage actually popup shows, which is why I thought I did something wrong, but for some reason the number is always 0.

JavaScript:
<Hide State Turns>

<JS On Add State>
  user._bide = 0;
</JS On Add State>

<JS Pre-Damage As Target>
  if (value > 0) {
    target._bide += value;
  }
</JS Pre-Damage As Target>

<JS On Erase State>
  $gameTemp.requestAnimation([user], 97);
  const damage = Math.ceil(user._bide * 2);
  const enemies = user.opponentsUnit().aliveMembers();
  for (const enemy of enemies) {
    $gameTemp.requestAnimation([enemy], 107);
    enemy.gainHp(-damage);
    enemy.startDamagePopup();
    enemy.clearResult();
  }
  delete user._bide;
</JS On Erase State>

So yeah, at this point I just have no idea what to try. The attack the enemy did is Physical, and I've already turned off my non-Visustella plugins to make sure it wasn't a compatibility issue, but I'll send them just in case. Theo_StackingStates was the non-Visustella I temporarily turned off, no difference.

Screenshot - 7_18_2025 , 3_13_56 PM.png
Screenshot - 7_18_2025 , 3_14_48 PM.png
I tried to use the original skill's code as a reference, but even that's not working. The damage actually popup shows, which is why I thought I did something wrong, but for some reason the number is always 0.
Have you tried Post-Damage instead?
It sounds like to me that pre-damage is running before damage calculaion entirely. There'd be no value to add onto bide
Add/Erase state notetags:
The 'user' variable refers to the current active battler.
The 'target' variable refers to the battler affected by this state.

If it's a self skill, user will work when adding state, but can cause problems when erased.
Have you tried Post-Damage instead?
It sounds like to me that pre-damage is running before damage calculaion entirely. There'd be no value to add onto bide

Add/Erase state notetags:
The 'user' variable refers to the current active battler.
The 'target' variable refers to the battler affected by this state.

If it's a self skill, user will work when adding state, but can cause problems when erased.
So I at the very least found the problem with Bide. Theo Stacking States didn't cause a compatibility issue per se, but because of the order I had it in something seems to clash with the code. Moving it up fixed it.

Though that means something's most likely wrong with my code. I tried adding target calls where the users were, Post-Damage, multiplying the variable by 1 to see if I needed a number, it's just not showing anything.
it's just not showing anything
But it is dealing the damage? The hp's are decreasing? You probably just have to call startDamagePopup() on each enemy as you damage them if thats the case
But it is dealing the damage? The hp's are decreasing? You probably just have to call startDamagePopup() on each enemy as you damage them if thats the case
Oh wait sorry, I made a mistake. I meant it wasn't doing anything.

Original thread: https://forums.rpgmakerweb.com/threads/storing-damage-for-counterattack-visustella-plugins.179006/