State-Dependent State Effects (Probably)

My first thread was for an oddball curiosity of effect -- Which, sadly, looks like it'll either require some complex state and/or common event interaction and finagling, or straight-up programming -- and it seems my second question here will be no different.

How would I bring about the following?
  • A skill, let's call it Third Eye Sight, is used against a single target.
  • This skill will trigger a state, let's call it Third Eye Sight (Target), which reduces the target's Evasion by 50%.
  • This Evasion reduction should only be available to the individual who used Third Eye Sight, and have zero effect when anyone else targets the target.
  • If Third Eye Sight skill is used against a different target, then the original target loses the Third Eye Sight (Target) state, and the new target gains the state.
To lay out the flow of how it would just work in combat:

Turn 1: Sarah and John use Attack on the Ogre 1. The enemy's Evasion is at 100% of its default value. The attack fails for both Sarah and John.
Turn 2: Sarah uses Third Eye Sight, and John uses Attack on the enemy. The enemy's Evasion is now 50% of its default value for Sarah, and 100% its default value for John.
Turn 3: Sarah and John use Attack on the enemy. The enemy's Evasion is at 50% of its default value to Sarah, and the Attack connects. The enemy's Evasion is at 100% its default value to John, and the Attack fails.
Turn 4: Ogre 2, who has just been putzing around so far, is targeted by Sarah with Third Eye Sight. Ogre 1 is now no longer under the effect of Third Eye Sight, and has an Evasion 100% against Sarah and John. Ogre 2 now is at 50% of its original Evasion against Sarah.
​
.. And that's kinda all I have at the moment. I know I can use Add State to enable the Ex-Parameter reduction, but I'm not quite sure how to make the effect contingent on the presence of another state -- For the sake of things, going to just call it Third Eye Sight (User) being present on the attacker -- or even just making it so that only one person can take advantage of that effect.
I'm not sure if you could do the conditional evasion part without a Plugin.

You can't do anything with the damage formula since it isn't evaluated unless the attack hits.
You can't do anything with common events, because those happen after accuracy and damage evaluation.
You can't do anything with troop events, because you can't really get them to evaluate at action time.

For the part about removing the state from others, you could probably store the enemy's index in a variable, then have the skill call a common event that removes that state from every enemy unless they're that ID.

For example, in your damage formula, do:
Code:
v[x] = b.index();
where x is the variable you want to store the index in.

Then call a common event that runs this bit of code:
Code:
$gameTroop.aliveMembers().forEach(function(enemy) {
  if (enemy.index() !== $gameVariables.value(x)) { // the variable you stored in your damage formula
    enemy.removeState(y); // The ID of the Third Sight state
  }
});

Here's an example:
Spoiler: Common Event Removing Poison From All Enemies Except Targeted
FOLF9cU.png
Spoiler: Skill Storing The Target's Index In A Variable
CLpHFj7.png
Spoiler: Example GIF
SpicyClearGallowaycow-small.gif
You're awesome, Zevia, and that bit of code looks like it does just the trick.

Memo to self: git gud at JS​

I'm wondering.. If the conditional quality may not be doable, I might be able to jury-rig something together with a custom Element type, and add a State that makes all of the User's attacks infused with that element so long as the state is active, and make the enemy susceptible to just that element with the Third Eye state?

Create an Element Third Eye Sight.
Have State Third Eye Sight (User) make all of the User's attacks add Element Third Eye Sight to the User so long as the State TES(U) is active.
Have State Third Eye Sight (Target) make the target affected by reduced Evasion against to Element Third Eye Sight.

.. A quick skim through the parameters and formula as presented in the hovers for RMMV's database doesn't seem to have any particular anything that would let me affect Evasion, specifically against a single Element type, though.

Is the above even possible without a plugin? Barring that, any plugins that might be useful for making that work? I'm immediately guessing possibly something in Yanfly, but that's mostly because that set seems to be a pretty strong go-to for most needs.
Addendum, tangentially related: Is it possible to stack multiple element types to an Actor's attack? Like, can an Actor have multiple different states enable multiple different Attack Elements simultaneously?

Can an Actor have Attack Element Fire and Water active concurrently, for example, so that their attacks count as both Fire and Water?
Give this Plugin a try. Either copy this into a file and save it as "StateCombos.js" or download it from the post.

Code:
/*:
* @plugindesc Allows for states to affect PARAM, EX-PARAM, and S-PARAM values only if being
* targeted by a user who has a specified state.
* @author Zevia
*
* @help In a state's notetag, put <stateCombo: stat, x, y>, where stat is the
* PARAM, EX-PARAM, or S-PARAM to be affected, x is the percentage to affect it by,
* and y is the state the user must have to apply the stat adjustment
*
* For example, <stateCombo: eva, -50, 4> means that if an Actor or Enemy has this
* state, and someone with state 4 targets them, their evade will be decreased
* by 50%.
*
* Keep in mind that EX-PARAMS are additive and PARAMS and S-PARAMS are
* multiplicative.
*/

(function(module) {
    'use strict';

    module.Zevia = module.Zevia || {};
    var StateCombos = module.Zevia.StateCombos = {};
    var PARAMS = ['mhp', 'mmp', 'atk', 'def', 'mat', 'mdf', 'agi', 'luk'];
    var XPARAMS = ['hit', 'eva', 'cri', 'cev', 'mev', 'mrf', 'cnt', 'hrg', 'mrg', 'trg'];
    var SPARAMS = ['tgr', 'grd', 'rec', 'pha', 'mcr', 'tcr', 'pdr', 'mdr', 'fdr', 'exr'];

    Game_BattlerBase.prototype.comboStates = function() {
        if (!this._comboSubject) { return []; }

        return this.states().filter(function(state) {
            return state.meta.stateCombo;
        }).map(function(state) {
            return state.meta.stateCombo.split(',');
        }).filter(function(combo) {
            return combo.length === 3;
        }).map(function(combos) {
            return {
                param: combos[0].trim().toLowerCase(),
                value: parseInt(combos[1]),
                subjectState: parseInt(combos[2])
            };
        });
    };

    Game_BattlerBase.prototype.comboValue = function(paramList, paramId, baseValue) {
        return this.comboStates().filter(function(trait) {
            return (paramList.indexOf(trait.param) === paramId) && (this._comboSubject.isStateAffected(trait.subjectState));
        }.bind(this)).reduce(function(total, trait) {
            if (baseValue === 0) { return total + (trait.value * 0.01); }
            else { return total * (trait.value * 0.01); }
        }, baseValue);
    };

    StateCombos.applyAction = Game_Action.prototype.apply;
    Game_Action.prototype.apply = function(target) {
        target._comboSubject = this.subject();
        StateCombos.applyAction.call(this, target);
    };

    StateCombos.xparam = Game_BattlerBase.prototype.xparam;
    Game_BattlerBase.prototype.xparam = function(xparamId) {
        return StateCombos.xparam.call(this, xparamId) + this.comboValue(XPARAMS, xparamId, 0);
    };

    StateCombos.paramRate = Game_BattlerBase.prototype.paramRate;
    Game_BattlerBase.prototype.paramRate = function(paramId) {
        return StateCombos.paramRate.call(this, paramId) * this.comboValue(PARAMS, paramId, 1);
    };

    StateCombos.sparam = Game_BattlerBase.prototype.sparam;
    Game_BattlerBase.prototype.sparam = function(sparamId) {
        return StateCombos.sparam.call(this, sparamId) * this.comboValue(SPARAMS, sparamId, 1);
    };

    StateCombos.endTurn = BattleManager.endTurn;
    BattleManager.endTurn = function() {
        $gameTroop.members().concat($gameParty.battleMembers()).forEach(function(member) {
            member._comboSubject = undefined;
        });
        StateCombos.endTurn.call(this);
    };
})(window);

Quick example of how I set it up in my project to test:
Spoiler: Third Eye State
rKaIJJb.png
Spoiler: Enemy With 100% EVA
GvnKzTJ.png
Spoiler: Example Attacks GIF
Harold and Therese both attack and both miss since the bat has 100% evade. Apply State 13 to Bat A and State 14 to Harold, then attack again. Harold's attack lands, but Therese continues to miss.
giphy.gif

EDIT: Added support for S-Params and fixed a math bug.
Dude. You're awesome, and wonderful. Thank you! What do I owe you for this? I absolutely believe in fair value trade, and this is something I wouldn't have gotten on my own -- Not any time soon.

I'm going to sit and continue to be a bit blown away at seeing this manifest so clearly and perfectly. Thank you a thousand times over.

One last quick query, if you happen to have any ideas for it: Is there a way to trigger the formula's effect without it being classified as HP Damage effect? It's purely a visual issue, here -- It shows damage of "0" (occasionally "1") when using the skill. If I could circumvent that, it would be perfect.
It looks like I can bypass having to set it as a damage formula by inserting a static variable that would reference the state.

I think.

I am not entirely sure how I'd set this, though, or if I'm even thinking of it correctly. It looks like it would be set in the JS.. Somewhere.

I'm fine setting it as a static variable to be referenced.. I don't think that'd unduly affect things. If I'm thinking of this correctly, though, it would help if anyone has an idea where I'd define that, as it relates to the suggestion in post 2 of this thread.
I think if you do MP drain or MP damage and change the damage formula to:
Code:
v[x] = b.index(); 0
And change the variance to 0, you should be able to remove any damage popups. The reason you occasionally see 1 is because of the 20% variance that's default to new skills. I believe MP damage doesn't do a popup in the default engine if the value is 0, though.

What do I owe you for this?
Just give me credit when your game eventually releases. I may end up using it in my own project at some point, had a couple ideas of how I might expand it some. I may modify the Plugin so that you can specify a User being a particular class instead of needing a particular state.

Glad you found it helpful!
I think if you do MP drain or MP damage and change the damage formula to:
Code:
v[x] = b.index(); 0
And change the variance to 0, you should be able to remove any damage popups. The reason you occasionally see 1 is because of the 20% variance that's default to new skills. I believe MP damage doesn't do a popup in the default engine if the value is 0, though.

Oh yeah, that did it. Thanks!

Just give me credit when your game eventually releases. I may end up using it in my own project at some point, had a couple ideas of how I might expand it some. I may modify the Plugin so that you can specify a User being a particular class instead of needing a particular state.

Glad you found it helpful!

Awesome, and thank you! I absolutely will. If it winds up helping on your end, I'm glad I could help provide an impetus for inspiration! 🙂

Original thread: https://forums.rpgmakerweb.com/threads/state-dependent-state-effects-probably.104997/