[SOLVED]Apply a state when attacked.

Hi, can anyone help me out?

I'm trying to make an Ice Armor, where if the wearer gets attacked each time, there is a 50% chance that the attacker gets applied with the Frozen state (they can't act nor move.)

Also, the attack can miss but the attacker can still get frozen. (it's a separate instance.)

Anyway to do this? Help us much appreciated, thanks!
BattleManager.actor() will give you the last active actor
BattleManager.actor.lastTargetIndex() will give you the enemy index from the troop that was just targetted.

send the attack through a common event grabbing those objects, check for armor, and process accordingly
You could set it up as an counter hit. Try using Yanfly's Counter Control plugin to get more control on how to set it up. You'll be able to change the counter hit skill to something that will inflict the state, have the counter hit tied to a piece of armor and you can change the counter hit rate to 50% when wearing that armor.
I like @Uzuki's Counter Control approach.

Alternatively, you could use another Yanfly script, Buffs & States Core, which will give you a little more control over the mechanics of how it works, but also will require a bit more effort. I would probably use a <Custom Deselect Effect> notetag for this kind of effect, and use the ".addState(x)" method to apply the Frozen state (I believe the syntax would be user.addState(x) where x is the State ID of Frozen, but I'm not 100% sure). Depending on whether this effect should apply to only members from the other party, whether it only applies to attacks not magic, etc., you can use additional scripting.
I like @Uzuki's Counter Control approach.

Alternatively, you could use another Yanfly script, Buffs & States Core, which will give you a little more control over the mechanics of how it works, but also will require a bit more effort. I would probably use a <Custom Deselect Effect> notetag for this kind of effect, and use the ".addState(x)" method to apply the Frozen state (I believe the syntax would be user.addState(x) where x is the State ID of Frozen, but I'm not 100% sure). Depending on whether this effect should apply to only members from the other party, whether it only applies to attacks not magic, etc., you can use additional scripting.

Almost there, I just need to know how to set rate of getting frozen.
What I did was (using Yanflys buff and states core) add this code to the notetag of State#23, where State#15 is the actual frozen State:

<Custom Deselect Effect>
a.addState(15);
</Custom Deselect Effect>


Then using Yanfly auto passive state:

added this to the notetag of armor#1:
<Passive State: 23>

The only problem is, the attacker gets frozen 100% every time it attacks regardless whether the attack hits or not (as intended), which is so OP! haha.

So if i'm missing anything please help me again, much app.

Edit: Hey I think i've done it?

Modifying the code to this, seems to make it work.

<Custom Deselect Effect>

value = (Math.randomInt(4) + 1);

if (value <= 2)

{

a.addState(15);

}

</Custom Deselect Effect>

Now it seems to freeze the enemy 50% of the time, just like I wanted.

But if you guys have any any suggestions on how to improve this, it's still greatly appreciated. Other than that, this thread is pretty much solved.

BTW here is a video of the results:

I think you could do something like:

if (Math.random() < 0.20) {
a.addState(15);
}

This would give you a 20% chance to inflict the state since Math.random() will choose a random decimal value between 0.000 and 1.000. Let me know if it doesn't work.
I think you could do something like:

if (Math.random() < 0.20) {
a.addState(15);
}

This would give you a 20% chance to inflict the state since Math.random() will choose a random decimal value between 0.000 and 1.000. Let me know if it doesn't work.

Yep it works! I even tried changing 0.20 to 0.50 to see if it has a chance to freeze the Rat by 50% and it still does, thank you very much.

Edit: Problem Solved, thank you very much!
To add, this armor is really fun, lol.

Original thread: https://forums.rpgmakerweb.com/threads/solved-apply-a-state-when-attacked.103062/