How to reflect magic one time only? [solved]

I am trying to create a spell to reflect 100% magic damage, until a spell is reflected.
One time only.

What I need:
User casts Magic Protection -> "Magic Protection" state is applied, a state with 100% magic reflection.
Enemy casts spell -> Damage is reflected and Magic Protection state is Removed

Problem:
The magic reflection is set to 100%, I cannot use "Remove on damage" on the state because damage is zero.
How can i remove the state when a spell is reflected?
Ok, so... at first I was thinking you'll need a plugin that... well, I don't know any other that does what you'd need but yanfly's buffs states core to be honest... but then I found out that while there is a way to see if the skill was reflected it would not work, because everything in yanfly's buffs states core happens on either the action's apply or execute damage - both that happen on the reflected battler rather than the one that hat it deflected from them.

So my thought was of you making a small plugin yourself to edit BattleManager.invokeMagicalReflection so that, if the target was under the state, it'd remove the state after reflection.

Just make a text file, save it with the extension .js instead of .txt, and put this in it (change the number of the state for the one you'll use for the reflection, I used 12 here):
JavaScript:
var reflection_invokeMagicReflection = BattleManager.invokeMagicReflection;
BattleManager.invokeMagicReflection = function(subject, target) {
    reflection_invokeMagicReflection.call(this, subject, target);
    if (target.isStateAffected(12)) target.removeState(12);
};
Did not test yet, but it should work.
Ok, so... at first I was thinking you'll need a plugin that... well, I don't know any other that does what you'd need but yanfly's buffs states core to be honest... but then I found out that while there is a way to see if the skill was reflected it would not work, because everything in yanfly's buffs states core happens on either the action's apply or execute damage - both that happen on the reflected battler rather than the one that hat it deflected from them.

So my thought was of you making a small plugin yourself to edit BattleManager.invokeMagicalReflection so that, if the target was under the state, it'd remove the state after reflection.

Just make a text file, save it with the extension .js instead of .txt, and put this in it (change the number of the state for the one you'll use for the reflection, I used 12 here):
JavaScript:
var reflection_invokeMagicReflection = BattleManager.invokeMagicReflection;
BattleManager.invokeMagicReflection = function(subject, target) {
    reflection_invokeMagicReflection.call(this, subject, target);
    if (target.isStateAffected(12)) target.removeState(12);
};
Did not test yet, but it should work.

Works like a charm, confirmed 🙂

Thanks for sharing the plugin @Waterguy
glad I was able to help

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/how-to-reflect-magic-one-time-only-solved.116995/