How can I make opportunity attacks?

Im using Yanfly Row Formation plugin and I was wondering instead of having melee weapons unable to target back row instead they have a chance of every enemy in a front row to deal ATK damage. Similar to D&D.

-------------C
EX:----A--B-------H1
--------------D-------H2

-Hero 1 has a sword and attacks enemies C and D with no issues, however when they try on B, C+D have a 50% chance to deal their normal attack damage on Hero 1, if it is lethal the initial attack will fail. Similar with Hero 1 attacking A, B+C+D all provoke opportunity attacks.

-Hero 2 however has a spear equipped with is a mid ranged weapon. Therefore attacking B will not trigger C or D, however attacking A will trigger C+D attacks.

Original thread: https://forums.rpgmakerweb.com/threads/how-can-i-make-opportunity-attacks.120409/