Yanfly Buffs and States Core, Custom Remove Effects on death

Greetings! I have a question regarding Yanfly's Buffs and States Core http://yanfly.moe/2015/12/25/yep-50-buffs-states-core/ and its use for transformation states http://yanfly.moe/2016/07/06/tips-tricks-actor-transformations-rpg-maker-mv/

Specifically, I was interested in the fact that the Custom Remove Effects do not work if the state is removed via death (State 001, the default KO or death state). I have a character who transforms and becomes more powerful through transformation states and each transformation alters her appearance. This is working fine, but if she dies, I would like for her battler image to revert to its default appearance.

Normally, her appearance does revert to its default if the state is removed via dispelling it during battle, or when battle ends. However, it seems that Custom Remove Effects do not trigger if the state is removed via the application of the death or KO state.

The only solution I could come up with is adding a Custom Apply Effect to the death state that will check if the death state is being applied to her, and if it is, change her battler image to the default. I added the following Custom Apply Effect to the KO state:

<Custom Apply Effect>
if (user.actorId() === 8) {
user.setBattlerImage('Rei');
}
</Custom Apply Effect>

This worked just fine except for one problem: as I suspected, it didn't really jive when the death state was applied to an enemy, so every time the player defeats an enemy, a console error would appear (not a crash, just a console error). I know pretty much nothing about javascript, so I'm 99% certain the problem is just syntax or something with my Custom Apply Effect. I would like for it to just check if the entity that died is the actor in question, and simply do nothing if it's not. As I said, the effect works exactly as I intended it, but I get a console error every time an enemy is defeated.

Either I need to fix the Custom Apply Effect to the death state so that the game is not attempting to carry it out on enemies, OR is there something I can do with the actual transformation state so that it's Custom Remove Effect will work if the state is removed by death?
You're getting a console error because "actorId" doesn't exist as a function for enemies. You need to check if the user is an actor, too, before calling actorId. Try: if(user.isActor() && user.actorId() === 8)
You're getting a console error because "actorId" doesn't exist as a function for enemies. You need to check if the user is an actor, too, before calling actorId. Try: if(user.isActor() && user.actorId() === 8)

Yep, that was exactly it. I'm clueless on javascript, so checking to see if the subject is an actor in the first place went right over my head. It would be nice if the other issue could be addressed (why Custom Remove Effects don't work if they are removed by death), but that is a topic for another thread. Thank you for the response!
You're not doing anything wrong with Custom Remove Effects.

When a character dies, states are cleared, which is different from how the code works when a state is removed (by a timer, or another effect).

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/yanfly-buffs-and-states-core-custom-remove-effects-on-death.106862/