Attacking a battler with a state to inflict state

Posting this in a separate thread as I remember this was the prefered way back in the day (not sure if things are different now)

How can I make it so that when a party member attacks an enemy with a certain state (or vise versa) to have a chance to get a certain state or another effect themself.

My main concept is that I want to make a shield that can either damage the enemy, inflict some bad state or something like that. An example would be Shiver Armor in Diablo II.
For a 100% chance, just add this in front of the damage formula:
Code:
if (b.isStateAffected(16)) b.addState(21);
Those numbers being the States as they're listed in the database, so check your project which ones they should be.

If it's a chance for different things to happen, I'd just inflict an invisible state with the skill, have the skill link to a common event that checks each enemy whether they have the state + skill state, and if so run the chances for stuff to happen.
formula can have % chances too using Math.randomInt(100)+1 < X as part of an "if" formula.
i prefer < (less then) so that X is the % chance you want instead of > (greater than) which would make X be the % chance to fail
For a 100% chance, just add this in front of the damage formula:
Code:
if (b.isStateAffected(16)) b.addState(21);
Those numbers being the States as they're listed in the database, so check your project which ones they should be.

If it's a chance for different things to happen, I'd just inflict an invisible state with the skill, have the skill link to a common event that checks each enemy whether they have the state + skill state, and if so run the chances for stuff to happen.

Do I need to add these in all attacking skills for all of the states that will be able to pass a state if a battler is under attack? 😮

Original thread: https://forums.rpgmakerweb.com/threads/attacking-a-battler-with-a-state-to-inflict-state.126578/