Help! Creating a Skill That Will Reflect Only Certain Elemental Skills?

I would like to create a magic skill that when cast will make the recipient reflect a specific magic element attack.

For example:
Party member A casts "Reflect Fire," on Party Member B
Enemy A uses Ice attack on Party Member B and that attack goes through
Enemy B uses Fire attack on Party Member B and that attack reflects back onto Enemy B.

I've been doing some reading and exploring and am struggling to create this skill.

Any help would be appreciated, thank you so much!
This is not trivial, because reflection is done at a pretty low level; so you can't readily modify or just trigger it from within a skill or action sequence.

We're gonna give this a go. Paste the below into a text editor, save as a *.js file, include as a plugin.

Code:
var replaceMrf = Game_Action.prototype.itemMrf;
Game_Action.prototype.itemMrf = function(target)
{
    let result = replaceMrf.call(this, target);
    if (result)
    {
        let refState = target.states().find(state => {state.meta.reflectelement && Number(state.meta.reflectelement) == this.item().damage.elementId);
        if (refState)
            result = target.mrf;
    }
   return result;
};

You'd put into a state the notetag <reflectelement: x> where x is the ID of the element from the Types tab of your database.

This should make the target's magic reflection only apply if the element of the incoming skill matches the ID in the notetag (so if you want guaranteed reflection, put a trait in that state with magic reflection of 100%).
This is not trivial, because reflection is done at a pretty low level; so you can't readily modify or just trigger it from within a skill or action sequence.

We're gonna give this a go. Paste the below into a text editor, save as a *.js file, include as a plugin.

Code:
var replaceMrf = Game_Action.prototype.itemMrf;
Game_Action.prototype.itemMrf = function(target)
{
    let result = replaceMrf.call(this, target);
    if (result)
    {
        let refState = target.states().find(state => {state.meta.reflectelement && Number(state.meta.reflectelement) == this.item().damage.elementId);
        if (refState)
            result = target.mrf;
    }
   return result;
};

You'd put into a state the notetag <reflectelement: x> where x is the ID of the element from the Types tab of your database.

This should make the target's magic reflection only apply if the element of the incoming skill matches the ID in the notetag (so if you want guaranteed reflection, put a trait in that state with magic reflection of 100%).
Thank you so much, I will try this as soon as possible tonight when I'm working on my game. I'll let you know how things go!
This is not trivial, because reflection is done at a pretty low level; so you can't readily modify or just trigger it from within a skill or action sequence.

We're gonna give this a go. Paste the below into a text editor, save as a *.js file, include as a plugin.

Code:
var replaceMrf = Game_Action.prototype.itemMrf;
Game_Action.prototype.itemMrf = function(target)
{
    let result = replaceMrf.call(this, target);
    if (result)
    {
        let refState = target.states().find(state => {state.meta.reflectelement && Number(state.meta.reflectelement) == this.item().damage.elementId);
        if (refState)
            result = target.mrf;
    }
   return result;
};

You'd put into a state the notetag <reflectelement: x> where x is the ID of the element from the Types tab of your database.

This should make the target's magic reflection only apply if the element of the incoming skill matches the ID in the notetag (so if you want guaranteed reflection, put a trait in that state with magic reflection of 100%).
Okay so I've followed all the steps and have triple checked, so I'm pretty sure I did everything correctly, but it is reflecting all magic skills and not just the one associated with the ID from Types.

It says in the plug-ins "The plugin x may not support RPG Maker MZ" though everything still works.

What I may be misunderstanding is when you say "(so if you want guaranteed reflection, put a trait in that state with magic reflection of 100%)." what I did was include in the traits for the state "Ex-Parameter: Magic Reflection 100%"

Am I doing this correctly? Sorry if I'm missing something I'm pretty new to this, but I really do appreciate your help.
it is reflecting all magic skills and not just the one associated with the ID from Types.
Well that's because I wrote the code wrong 😛

I wrote it to reflect the type specified, when it already does that. We need to make it not count toward reflecting if there's a different type specified.


Code:
var replaceMrf = Game_Action.prototype.itemMrf;
Game_Action.prototype.itemMrf = function(target)
{
    let result = replaceMrf.call(this, target);
    if (result)
    {
        let badState = false, refState = false; 
        target.states().forEach(state => 
        {
            if (state.meta.reflectelement)
            {
                if (Number(state.meta.reflectelement) != this.item().damage.elementId) 
                    badState = true;
                else
                    refState = true;
            }
        });
        if (badState && !refState)
            result = 0;
    }
   return result;
};
Well that's because I wrote the code wrong 😛

I wrote it to reflect the type specified, when it already does that. We need to make it not count toward reflecting if there's a different type specified.


Code:
var replaceMrf = Game_Action.prototype.itemMrf;
Game_Action.prototype.itemMrf = function(target)
{
    let result = replaceMrf.call(this, target);
    if (result)
    {
        let badState = false, refState = false;
        target.states().forEach(state =>
        {
            if (state.meta.reflectelement)
            {
                if (Number(state.meta.reflectelement) != this.item().damage.elementId)
                    badState = true;
                else
                    refState = true;
            }
        });
        if (badState && !refState)
            result = 0;
    }
   return result;
};
Thank you so much, this is the biggest help to me. I cannot express how thankful I am. You are very skilled, and if my game goes over well, I will make sure you have a special place in the credits.

Original thread: https://forums.rpgmakerweb.com/threads/help-creating-a-skill-that-will-reflect-only-certain-elemental-skills.170343/