Need help with a skill that sets a trap to protect an ally

So, in my game there's a skill called Beartrap. When used on an ally, it applies a Beartrap state to them, which ideally would cause the next enemy that attacks that ally to take damage and get Stunned. Unfortunately I'm not sure how do do this. Can anyone help me?

Original thread: https://forums.rpgmakerweb.com/threads/need-help-with-a-skill-that-sets-a-trap-to-protect-an-ally.141545/