How to make a move like Substitute from Pokemon

I'm attempting to make a move in RPG Maker MV similar to Substitute from the pokemon games. For those that are not familiar with the move, you can read about it here.

My current struggles with it are trying to make a state that goes away when the person that has it gets hit while not taking damage. Setting it up with 1000% def and mdf and remove by damage just results in permanent damage immunity, and if I try to give it an evasion rate that will make it so the user takes full damage when they get hit which is not what I want.

I did find a similar question answered by users Zalerinian and Shaz, but It didn't give me an answer that could really help me out with what I'm needing.
My current struggles with it are trying to make a state that goes away when the person that has it gets hit while not taking damage.
This is easily done with Yanfly's Buffs and States Core, a free plugin. Put in your state's notetags:
Code:
<Custom React Effect>
if (this.checkDamageType([1, 5]))
{
    value=0;
    user.removeState(X);
}
</Custom React Effect>

where X is the ID of the state.
This is easily done with Yanfly's Buffs and States Core, a free plugin. Put in your state's notetags:
Code:
<Custom React Effect>
if (this.checkDamageType([1, 5]))
{
    value=0;
    user.removeState(X);
}
</Custom React Effect>

where X is the ID of the state.
Would I need to change the (this.checkDamageType([1, 5]) effect to include every element I have?
That doesn't have anything to do with elements. It will return true if the skill Damage Type is HP Damage or HP Drain. I figured that was a sensible condition for what you were asking for - if you want the state to go off regardless of whether the skill is doing MP Damage or Healing, you can remove the if line and the two braces.
That doesn't have anything to do with elements. It will return true if the skill Damage Type is HP Damage or HP Drain. I figured that was a sensible condition for what you were asking for - if you want the state to go off regardless of whether the skill is doing MP Damage or Healing, you can remove the if line and the two braces.
I just didn't know exactly what it meant. I'm very new to working with RPG Maker and even more so with moves, so help like this is very much appreciated. That being said, it does not seem to remove the state after they take the 0 damage hit.
Did you replace X with the correct state ID?
Did you replace X with the correct state ID?
the Substitute effect is state 0012 and user.removeState(12); is how it is written
That's the correct syntax.
Would it not be target.removeState(x) rather than user.removeState(x) ? Since the target of the attack is the battler that needs to have the state removed?

Also, if this "block one hit of any magnitude" implementation satisfies your needs, then no worries. But if you are concerned with emulating Substitute more fully, you'll want to determine how you want the "Substitute's HP" to be calculated (In Pokemon, it is equal to the HP spent to use the move) and work both that value and the damage the sub has taken so far into the logic.
Would it not be target.removeState(x) rather than user.removeState(x) ? Since the target of the attack is the battler that needs to the state removed?

Also, if this "block one hit of any magnitude" implementation satisfies your needs, then no worries. But if you are concerned with emulating Substitute more fully, you'll want to determine how you want the "Substitute's HP" to be calculated (In Pokemon, it is equal to the HP spent to use the move) and work both that value and the damage the sub has taken so far into the logic.
This small fix worked! Thank you both for the help, I appreciate it!

Original thread: https://forums.rpgmakerweb.com/threads/how-to-make-a-move-like-substitute-from-pokemon.149463/