It's possible to create a spell that add a state by contact?

What i mean is: The mage uses a ligthing barrier spells, that when the enemy attacks the mage, the enemy may be paralized. I think ist possible with some yanfly script, am i right?
For RPG Maker MV, try Yanfly's Buffs & States Core with this notetag on your mage's lightning barrier state:
JavaScript:
<Custom React Effect>
// Will trigger when state bearer gets hit
// 40% chance to add...
var chance = 0.4;
// ...state 8 to attacker
var stateId = 8;
if (Math.random() < chance) {
  attacker.addState(stateId);
}
</Custom React Effect>
You can edit the values as needed~ 🙏

[Edit: correction! random < chance, not random > chance. 😴]

I've moved this thread to Plug-In Requests. Thank you.

@caethyril Worked perfectly thanks!😤
@tekiro Great! I just noticed a small error though, the check should be Math.random() < chance, e.g. "is a random number in [0, 1) less than 0.4" => 40% chance. I've edited my original post with a corrected version! 😮‍💨

Happy RPG Making~ 😂

Original thread: https://forums.rpgmakerweb.com/threads/its-possible-to-create-a-spell-that-add-a-state-by-contact.118735/