MV YEP_AutoPassiveStates Custom Remove effect freezes game

I'm trying to make a Ghost state which will change the actor's SV_Actor sprite to the Ghost version upon reaching 0 HP if there is MP remaining, and then return the previous SV_Actor sprite upon revival or death. To accomplish this, I followed Yanfly's Actor Transformations guide, and then modded YEP_AutoPassiveStates with ATT_Turan's "Auto Passive States - Apply and Remove" Terrific Tweak to fix the Custom Apply and Custom Remove functions of Passive States.

Here's what I got:

State: Ghost
- State Resist: Dead
Spoiler: Notetag Code for State
[
<Passive Condition: HP Below 1>
<Passive Condition: MP Above 0>
<Custom Turn End Effect>
// Lose 1 MP
target.gainMp(-1);
</Custom Turn End Effect>

<Custom React Effect>
// Convert would-be HP damage to MP damage
if (this.isHpEffect && value > 0) {
var offset = Math.floor((Math.min(value*1.0, target.mp)));
value -= offset;
target.gainMp(-offset);
}
</Custom React Effect>

<Custom Apply Effect>
// Check if user is an actor.
if (user.isActor()) {
// Archive the previous settings.
user._prevCharName = user._prevCharName || user._characterName;
user._prevCharIndex = user._prevCharIndex || user._characterIndex;
user._prevBattlerName = user._prevBattlerName || user._battlerName;
// Check if the actor ID is 1.
if (user.actorId() === 1) {
// The filename of the character graphic without the file extension.
var charName = 'Ripple';
// The index of the character graphic used.
var charIndex = 0;
// The filename of the battler graphic without the file extension.
var battlerName = 'ActorCow_2';
// If none of the above actor ID's match, use this setting.
} else {
// The filename of the character graphic without the file extension.
var charName = 'Ripple';
// The index of the character graphic used.
var charIndex = 0;
// The filename of the battler graphic without the file extension.
var battlerName = 'ActorCow_2';
}
// Changes the character image to the setting applied from above.
user.setCharacterImage(charName, charIndex);
// Changes the battler image from the setting applied from above.
user.setBattlerImage(battlerName);
// Refreshes the user's appearance.
user.refresh();
}
</Custom Apply Effect>

<Custom Remove Effect>
// Retrieve archived settings.
var charName = user._prevCharName;
var charIndex = user._prevCharIndex;
var battlerName = user._prevBattlerName;
// Changes the character image to the archived setting.
user.setCharacterImage(charName, charIndex);
// Changes the battler image from the archived setting.
user.setBattlerImage(battlerName);
// Clear archived data.
user._priorityCharacterName = undefined;
user._priorityCharacterIndex = undefined;
user._priorityBattlerName = undefined;
user._prevBattlerName = undefined;
// Refreshes the user's appearance.
user.refresh();
</Custom Remove Effect>
]
The application of the status works great, just as I'd like it to; the state activates, and the SV_Actor switches to the ghost one. The real trouble begins when the state should be removed, in which case it will freeze the game. I'm completely at a loss as to why this happens-- I think I've modded the plugin correctly. It seems to be something in the removal process which screws things up, both when reviving and dying for real. If anyone has any idea what might be causing this and/or how to fix it, I'd greatly appreciate hearing it.
As a general tip, when you're posting code you should use the CODE tag (the </> in the edit bar) - that preserves indentations and brackets.

<Passive Condition: HP Below 1>
<Passive Condition: MP Above 0>
I don't see how this would work. Without researching in the code, you can only have one condition - if you want both of those things to be true, you need to write them out as a code in a Custom Passive notetag.

Code:
<Custom Passive Condition>
condition = user.hp < 1 && user.mp > 0;
</Custom Passive Condition>

// Clear archived data.
user._priorityCharacterName = undefined;
user._priorityCharacterIndex = undefined;
user._priorityBattlerName = undefined;
user._prevBattlerName = undefined;
You don't want all this. I know you copy and pasted it from a Yanfly Tip & Trick, but that snippet is wrong and has random extra things in it. First, you're removing values from all these priority properties that you never created and don't use. Second, it's not clearing all of the values that you did use. Lastly, instead of making them undefined you should remove them entirely.

So:
Code:
// Clear archived data.
delete user._prevCharName;
delete user._prevCharIndex;
delete user._prevBattlerName;

// Refreshes the user's appearance.
user.refresh();
This is your error. The code added by my snippet to add the remove effects is going inside of the refresh() function. So when you call it again at the bottom of your notetag, you're causing an infinite loop - refresh is executing your code which is calling refresh which is executing...

Just delete that line.
Thanks so much, it works perfectly now! I guess the main thing that was causing the issues was just the user.refresh(); line, but it's great to know about these other ones as well-- I have fixed them accordingly.

I don't see how this would work. Without researching in the code, you can only have one condition - if you want both of those things to be true, you need to write them out as a code in a Custom Passive notetag.
As for this, according to the Help box in YEP_AutoPassiveStates, "All conditions must be fulfilled in order for the passive state to appear", which, when I read I assume means that you can have multiple Passive Conditions, and the state only activates when all are met. As far as my testing has provided, this is the case-- Ghost state functions using either your custom condition or the two I was using previously. (Regardless I'll be using your fixed line along with the rest).
As for this, according to the Help box in YEP_AutoPassiveStates...As far as my testing has provided, this is the case
You are correct - as I said, I hadn't referenced the plugin itself when typing that out. Yanfly did specifically go to extra lengths to make that work, so what you had originally is fine.

It's a good rule of thumb, however, to keep in mind that under normal circumstances you can't use two of the same kind of notetag in one data object.

Original thread: https://forums.rpgmakerweb.com/threads/yep_autopassivestates-custom-remove-effect-freezes-game.178281/