[Solved] Creating a state reflection state using state triggers

I’ve been experimenting with implementing a state reflection effect using the StateTrigger.js plugin, which would apply a state to an enemy instead of granting it to the user when triggered. However, I haven’t been able to get it to work as intended. I would appreciate any advice on what kind of script might help achieve this.

I couldn’t find StateTrigger.js to look at how it works, so I’m not sure how to set it up for this. What if you tried a small plugin instead? Put <ReflectState: 4> in the reflect state’s note (or <ReflectState: 4,5,6> for more than one), and while a battler has that state, any of those states an enemy’s skill or item tries to add gets added to the enemy instead:

/*:
 * @target MZ
 * @plugindesc Reflects chosen states back to the attacker.
 * @help Put <ReflectState: 4> or <ReflectState: 4,5,6> in a state's note.
 * While a battler has that state, if an opponent's skill or item
 * would add one of those states to them, it goes to the user instead.
 */
(() => {
    const reflects = function(battler, stateId) {
        return battler.states().some(state => {
            const tag = state.meta.ReflectState;
            return tag && String(tag).split(",").map(Number).includes(stateId);
        });
    };

    const _addNormalState = Game_Action.prototype.itemEffectAddNormalState;
    Game_Action.prototype.itemEffectAddNormalState = function(target, effect) {
        const user = this.subject();
        if (user.isActor() !== target.isActor() && reflects(target, effect.dataId)) {
            _addNormalState.call(this, user, effect);
            this.makeSuccess(target);
        } else {
            _addNormalState.call(this, target, effect);
        }
    };
})();

The reflected state still rolls its chance against the enemy’s own state resistance, so an enemy that resists it won’t get it. It only covers states added by a skill or item’s Effects, not states added through the Attack State trait.


I was able to execute the state reflection from the plugin you provided! Thank you so much.