MZ Steal buffs from enemies

I have a skill that I want to remove buffs from an enemy and apply those buffs to the user (including the turn count without resetting it if possible). I'm using Visustella plugins and saw some code that apparently works for Yanfly plugins in MV, but I don't know what the MZ equivalent would be, assuming there is one.
saw some code that apparently works for Yanfly plugins in MV, but I don't know what the MZ equivalent would be, assuming there is one.
you'd have to share the code you found for anyone to tell you for certain, but assuming it was an <After Eval> or a <Post-Damage Effect>, you'd have to use <JS Post-Apply> or <JS Post-Damage>. the actual JS between the tags would most likely work the same.
JavaScript:
<JS Post-Apply>
// Loop through all parameters
for (var i = 0; i < 8; i++) {
  if (target._buffs > 0) {
  // Copy the target's buffs, if they exist
    user._buffs += target._buffs;
  // Copy the duration of the target's buffs
    user._buffTurns += target._buffTurns;
  }
  // Remove the target's buffs
  target._buffs = 0;
}
</JS Post-Apply>

It was <After Eval> before. It sort of works this way but when I steal their buff with a turn count of 4 it gets removed, but when they reapply it the turn count doubles to 8 as if the buff they had before was still there. On top of that the buff stacks normally. I set it in the plugin parameters for the max buff stack to only be 1 (so its always 25% instead of ending up with 50%) but it seems to ignore that
JavaScript:
<JS Post-Apply>
// Loop through all parameters
for (var i = 0; i < 8; i++) {
  if (target._buffs > 0) {
  // Copy the target's buffs, if they exist
    user._buffs += target._buffs;
  // Copy the duration of the target's buffs
    user._buffTurns += target._buffTurns;
  }
  // Remove the target's buffs
  target._buffs = 0;
}
</JS Post-Apply>

It was <After Eval> before. It sort of works this way but when I steal their buff with a turn count of 4 it gets removed, but when they reapply it the turn count doubles to 8 as if the buff they had before was still there. On top of that the buff stacks normally. I set it in the plugin parameters for the max buff stack to only be 1 (so its always 25% instead of ending up with 50%) but it seems to ignore that
that code has a few errors. its not actually handling the array data correctly. or it might be the case that it was copied from here, but the poster didnt use code tags and the forum ate all of the[i]s to italicize the text. try this

Code:
<JS Post-Apply>
// Loop through all parameters
for (var i = 0; i < 8; i++) {
  if (target._buffs[i] > 0) {
  // Copy the target's buffs, if they exist
    user._buffs[i] += target._buffs[i];
  // Copy the duration of the target's buffs
    user._buffTurns[i] += target._buffTurns[i];
  }
  // Remove the target's buffs
  target._buffs[i] = 0;
}
</JS Post-Apply>
It's still doing the same thing. I don't suppose there's anything in the plugin parameters I might have to change is there?
It's still doing the same thing. I don't suppose there's anything in the plugin parameters I might have to change is there?
ah, ok. i thought that it might have been some effects from how it was before, but sounds like it was working properly. try this then

Code:
<JS Post-Apply>
for (var i = 0; i < 8; i++) {
  if (target.buff(i) > 0) {  
    user.addBuff(i, target._buffTurns[i]);
    target.eraseBuff(i);
  }
}
</JS Post-Apply>
Since you only use one buff stack, this should be fine. That being said, i assumed that you wanted to add the buff rather than copy the buff, right? the difference being that if you were already debuffed, youd come back to neutral as opposed to going to +1.
Now the skill's not taking the buff at all. And yeah I was looking to take the enemy's buff for an actor (multiple at once if they had more) and if the actor already had the buff just increasing the turns of it by whatever the enemy had. I didn't think about getting a buff with a debuff would cause the stats to even out but yeah that'd be ideal
Now the skill's not taking the buff at all.
my bad. forgot that its buff() and eraseBuff(), not buffs() and eraseBuffs()
i edited the previous post with the correction
Little things like that is why I struggle with code, but it works perfectly that way. Thanks for the help!

Original thread: https://forums.rpgmakerweb.com/threads/steal-buffs-from-enemies.182359/