State based immunity to skill types

Hello,

I am trying to find the best way to have a state grant immunity to skills of a specific type.

To explain; I have a skill type called "gaze" that primarily exists to cause harmful states. I already have it that being "blind" makes you unable to use gaze skills so I thought it would a fun feature to have being blind also make you immune to them. Trouble is how to go about doing that?

Since most of them don't do damage slapping an if b.stateaffected() wouldn't work (unless there's a way to have the skill fail outright in the damage formula).

My current thought is to make all of them apply alternate gaze only versions of states instead of the normal ones and have the blind state grant immunity to those; but that's cumbersome and means every item that heals or prevents a state also needs to heal/prevent its gaze counterpart and if I ever miss one it'll cause issues.

So, I'm hoping someone can point out a more elegant solution.
Have you tried adding to the Blind state: Resist "Gaze" state.

I've not tried something like that yet but it should work.
You'd need a plugin that can put notetags in your blind state.

You can use my Eval Tags plugin, linked in my signature, or if you're using VisuStella stuff you'd use their Battle Core.

Using my Eval Tags:
Code:
<Action Targeted Eval>
if (this._action.isSkill() && this._action.item().stypeId == 3)
{
    target.discardStates = [];

    this._action.item().effects.forEach(effect =>
    {
        if (effect.code == Game_Action.EFFECT_ADD_STATE)
        {
            if (!target.isStateAffected(effect.dataId)) 
                target.discardStates.push(effect.dataId);
        }
    }
}
</Action Targeted Eval>

<Action Finish Eval>
if (target.discardStates)
{
    target.discardStates.forEach(state => target.removeState(state));
   delete target.discardStates;
}
</Action Finish Eval>

replace stypeId == 3 with the skill type ID you're resisting.

Have you tried adding to the Blind state: Resist "Gaze" state.
The OP addressed this:
My current thought is to make all of them apply alternate gaze only versions of states instead of the normal ones and have the blind state grant immunity to those; but that's cumbersome

The point is other skill types or items can also inflict those states, so blanket resist is undesirable.
You'd need a plugin that can put notetags in your blind state.

You can use my Eval Tags plugin, linked in my signature, or if you're using VisuStella stuff you'd use their Battle Core.

Using my Eval Tags:
Code:
<Action Targeted Eval>
if (this._action.isSkill() && this._action.item().stypeId == 3)
{
    target.discardStates = [];

    this._action.item().effects.forEach(effect =>
    {
        if (effect.code == Game_Action.EFFECT_ADD_STATE)
        {
            if (!target.isStateAffected(effect.dataId))
                target.discardStates.push(effect.dataId);
        }
    }
}
</Action Targeted Eval>

<Action Finish Eval>
if (target.discardStates)
{
    target.discardStates.forEach(state => target.removeState(state));
   delete target.discardStates;
}
</Action Finish Eval>

replace stypeId == 3 with the skill type ID you're resisting.
Thanks, I can put your plug-in back in since you fixed that NaN error I reported before.

I'm not using VS's battle core because it does a number of things I don't want and actively breaks another plug-in I'm using. I'll give this code a shot.

Update: Welp, it's not working, and I don't know why. I replaced stypeId == 3 with 4 which is my Gaze skill type but it's not doing anything.
Welp, it's not working, and I don't know why. I replaced stypeId == 3 with 4 which is my Gaze skill type but it's not doing anything.
if it doesnt work, you could take another approach. with the same plugin, you can have each gaze skill apply the state through a <Action Finish Eval> tag, but only if the target isnt blind
if it doesnt work, you could take another approach. with the same plugin, you can have each gaze skill apply the state through a <Action Finish Eval> tag, but only if the target isnt blind
Possibly, but I would need help writing the code for that. I really don't understand code enough to make heads or tails of what Turan posted.
Did it not work?
Did it not work?
No it didn't. I have it in the note for Blind but it does nothing. Not even an error.
Just to double check before I start trying to construct a test environment - you've tested it with this being the only active plugin in your project?
Possibly, but I would need help writing the code for that
Code:
<Action Finish Eval>
if (Math.random() < target.stateRate(x) * .5 && !target.isStateAffected(y))
    target.addState(x);
</Action Finish Eval>
you'd put some variation of this into the notebox for each gaze skill.
replace the x's for the id of the state youre trying to apply, y for your blind state's id, and change or remove the .5 to adjust the success rate for the state's application
Just to double check before I start trying to construct a test environment - you've tested it with this being the only active plugin in your project?
Yes; just now I removed all the other plugins; made an enemy with only a gaze attack that causes state 1 and an item to cause self blindness at +1000 speed.

Actor used item to become blind; got hit with gaze and died.
Code:
<Action Finish Eval>
if (Math.random() < target.stateRate(x) * .5 && !target.isStateAffected(y))
    target.addState(x);
</Action Finish Eval>
you'd put some variation of this into the notebox for each gaze skill.
replace the x's for the id of the state youre trying to apply, y for your blind state's id, and change or remove the .5 to adjust the success rate for the state's application
Testing this one; using the notepad to apply the state instead of the effects box (which I assume is how I meant to do this) resulted in a skill that did nothing regardless of whether the target was blind or not.

So; at this point I'm thinking it's not reading the noteboxes at all?

Except that can't be true because the notepad commands for other plugins are working fine.
I had to correct a few lines. Install the newest version of the plugin from its thread to make sure everything is compatible. This works in my test project.


Code:
<Action Targeted Eval>
if (BattleManager._action.isSkill() && BattleManager._action.item().stypeId == 2)
{
    target.discardStates = [];

    BattleManager._action.item().effects.forEach(effect =>
    {
        if (effect.code == Game_Action.EFFECT_ADD_STATE)
        {
            if (!target.isStateAffected(effect.dataId))
                target.discardStates.push(effect.dataId);
        }
    });
}
</Action Targeted Eval>

<Action Finish Eval>
if (target.discardStates)
{
    target.discardStates.forEach(state => target.removeState(state));
   delete target.discardStates;
}
</Action Finish Eval>
I had to correct a few lines. Install the newest version of the plugin from its thread to make sure everything is compatible. This works in my test project.


Code:
<Action Targeted Eval>
if (BattleManager._action.isSkill() && BattleManager._action.item().stypeId == 2)
{
    target.discardStates = [];

    BattleManager._action.item().effects.forEach(effect =>
    {
        if (effect.code == Game_Action.EFFECT_ADD_STATE)
        {
            if (!target.isStateAffected(effect.dataId))
                target.discardStates.push(effect.dataId);
        }
    });
}
</Action Targeted Eval>

<Action Finish Eval>
if (target.discardStates)
{
    target.discardStates.forEach(state => target.removeState(state));
   delete target.discardStates;
}
</Action Finish Eval>
Installed the newest version (1.6) and updated the code in the state notepad. Did not work.

I then made a brand new project; put in only your plugin added this code to blind and tested it for skill type 2; also did not work.

I am at a loss for what I'm doing wrong.


Okay; it does work. But not in the way I expected. It still applies the state (and gives the apply message) and then removes it. This means that if the state is Death the actor still ends up dead; likewise it'll still give the player the false idea that the state is being applied even though it's not.

Yeah; testing in the brand new project yielded the following: Says the target is poisoned when they aren't but Death still happens and the actor is dead after resolution.
Did you change the stypeId to 4 for your project again?
Did you change the stypeId to 4 for your project again?
I did; the situation was more complex than it seemed at first and I've edited my prior post to reflect that.
Directly applying the death state is generally not good practice. There are a number of things that go wrong when you do that - it's not registered as a kill, the target usually doesn't collapse, etc. It's better to deal damage equal to the target's HP.

That being said, you can always do what @Robro33 said above. There's no way the target can modify an incoming action, so you can put it into the attacking skill instead. Convert the percentages of your add state effects into decimals and put it into an after eval.

Code:
<Action After Eval>
// 90% to apply state 3 if the target does not have state 15 (whatever blind is)
if (Math.random() < .9 && !target.isStateAffected(15))
    target.addState(3);
</Action After Eval>
Directly applying the death state is generally not good practice. There are a number of things that go wrong when you do that - it's not registered as a kill, the target usually doesn't collapse, etc. It's better to deal damage equal to the target's HP.

That being said, you can always do what @Robro33 said above. There's no way the target can modify an incoming action, so you can put it into the attacking skill instead. Convert the percentages of your add state effects into decimals and put it into an after eval.

Code:
<Action After Eval>
// 90% to apply state 3 if the target does not have state 15 (whatever blind is)
if (Math.random() < .9 && !target.isStateAffected(15))
    target.addState(3);
</Action After Eval>

Thank you for your help.

I tested this code and it works...except that it doesn't display the "State applied" text when it succeeds. It also totally bypasses immunity to the state being granted by armor.

So; after all of that I think I am stuck doing what I was thinking I would have to do in the OP. Make a second copy of each state for the Gaze version. See; I'm aiming for blind to make you immune to all gaze attacks, but you could still be immune to the states they apply through other means; (ex a Gaze that causes Stun would be avoided by being either Blind *or* immune to stun.) And that may be beyond what I can expect to pull off with some simple JS code.

That; or I abandon the idea completely. It was meant to be a fun easter egg more than anything. I don't expect players to run around blinding themselves when facing down Basilisks (since blind is still a harmful status). But if it happens; hey fun quirk found.
It also totally bypasses immunity to the state being granted by armor.
That shouldn't be possible unless you have other plugins modifying the process.

The first thing that the addState() method does is check isStateAddable(), and that looks whether the target has State Resist for that state ID.
That shouldn't be possible unless you have other plugins modifying the process.

The first thing that the addState() method does is check isStateAddable(), and that looks whether the target has State Resist for that state ID.
I've tested it twice and it's applying the state even while equipped with an armor with state resist for that same state.

And there's no telling what of all I have running could be causing it at this point. I can post my plugin list if you'd like to try and figure it out for your own curiosity but at this point, I'm thinking I'm putting in a lot of effort and hours into something that most players may never even see; it's a fun idea but misplaced effort I think now.

But again, thank you for your time and talent.

edit: The offending plugin is VZ Items and equips core; that's the one causing the bypass but I have no idea how to fix that or if I even should since even without it add.state doesn't display the message I have for when an actor is afflicted with the state.

Original thread: https://forums.rpgmakerweb.com/threads/state-based-immunity-to-skill-types.169568/