MV Help making Camouflage Skill

I am trying to make skill that camouflages the battler. The skill applies a state alled camouflage that upon being apoplied changes the battlers opacity to 128 but when the state is removed it is supposed to return to 255 but it doesn't. Can anyone help me with this?
JavaScript:
<Custom Apply Effect>
console.log(user.name() + " is now camouflaged!");
if (user.isActor()) {
    user._spriteOpacity = this.spriteOpacity();
    user._battleSpriteOpacity = 128;
    user.refresh();
}
</Custom Apply Effect>

<Custom Remove Effect>
if (user.isActor()) {
    user._spriteOpacity = this.spriteOpacity();
    user._battleSpriteOpacity = 255;
    user.refresh();
}
</Custom Remove Effect>
Try *not* using ai to get your code?
Neither _spriteOpacity nor _battleSpriteOpacity are properties of a Game_Actor, and spriteOpacity() is not a function available to them, so you'll end up causing an error for trying to call a function that doesn't exist and then create a new property that doesn't do anything.
Maybe this (untested):

<Custom Apply Effect> var sprite = user.battler(); if (!("_preCamoOpacity" in user)) user._preCamoOpacity = sprite.opacity; sprite.opacity = 128; </Custom Apply Effect> <Custom Remove Effect> user.battler().opacity = user._preCamoOpacity || 255; delete user._preCamoOpacity; </Custom Remove Effect>
This requires 2 Yanfly plugins:
  • Battle Engine Core (for the battler method);
  • Buffs & States Core (for the notetag).
Maybe this (untested):

<Custom Apply Effect>
var sprite = user.battler();
if (!("_preCamoOpacity" in user))
user._preCamoOpacity = sprite.opacity;
sprite.opacity = 128;
</Custom Apply Effect>

<Custom Remove Effect>
user.battler().opacity = user._preCamoOpacity || 255;
delete user._preCamoOpacity;
</Custom Remove Effect>

This requires 2 Yanfly plugins:
  • Battle Engine Core (for the battler method);
  • Buffs & States Core (for the notetag).
Thank you, this worked perfectly. I appreciate it.

Original thread: https://forums.rpgmakerweb.com/threads/help-making-camouflage-skill.176410/