Thorns state/plugin?

I've looked around a bit but I'm not having much luck in finding a thorns state or plugin, anyone know one?

For those that don't know: thorns is an ability that, when active, deals damage to anyone attacking the one with the effect.
I believe this is what you are looking for. http://yanfly.moe/2015/12/26/yep-51-weapon-unleash/ 
I wanted the ability to do that as well, so I've been looking into it, I found one method so far.

I put

if (b.isStateAffected(30)) {a.gainHp(-3)};

before the damage calculation of my physical attacks.

30 is the state (doesn't do anything really, just sits there to be detected)

You can have multiple ranks by checking for different states.

like this:

if (b.isStateAffected(30)) {a.gainHp(-3)}; if (b.isStateAffected(31)) {a.gainHp(-6)}; if (b.isStateAffected(32)) {a.gainHp(-9)};

Hope that gives you some ideas.

Edit:

Also, if the attack misses the attacker doesn't take damage.
Looking at it, I don't see how I would use this to do what I want, i asked about the possibility on the comments there, but nothing so far.

I wanted the ability to do that as well, so I've been looking into it, I found one method so far.

I put

if (b.isStateAffected(30)) {a.gainHp(-3)};

before the damage calculation of my physical attacks.

30 is the state (doesn't do anything really, just sits there to be detected)

You can have multiple ranks by checking for different states.

like this:

if (b.isStateAffected(30)) {a.gainHp(-3)}; if (b.isStateAffected(31)) {a.gainHp(-6)}; if (b.isStateAffected(32)) {a.gainHp(-9)};

Hope that gives you some ideas.

Edit:

Also, if the attack misses the attacker doesn't take damage.
I will use this as a backup in the event that I cannot find a simpler way ;D ( I have a lot of different attacks and putting this in each one would be a long process xD)

Original thread: https://forums.rpgmakerweb.com/threads/thorns-state-plugin.54514/