EDIT: after making this change, for some reason, it's the user of the skill that dies on the first use - progress, but I wonder what happened
user in all of your code. You need to be doing all that stuff to the target object instead.However, there's one other big issue in your code. You've got it coded so that the effect is stackable, yet once the state wears off, it will only restore the atk that was drained by the last stack applied. So if a target gets the state applied to them multiple times before it wears off, they will permanently lose some atk.
I haven't tested it, but assuming that you do want the effect to be stackable, something like this should be close to what you're going for:
Code:
<JS On Add State>
const drainAmount = Math.randomInt(8) + 1;
target._drainedAttack ??= 0;
target._drainedAttack += drainAmount;
target.addParam(2, -drainAmount);
if (target.atk <= 0) {
target.die();
}
</JS On Add State>
<JS On Erase State>
if (target._drainedAttack) {
target.addParam(2, target._drainedAttack);
delete target._drainedAttack;
}
</JS On Erase State>*edit* Oops, I had accidentally left in one reference to
user in the "On Erase State" note tag. It is now fixed.