Counter-Attack Affected by Stats

Heya, guys!

I was working on a game, and I was wondering....

So, when I counter-attack, I already figured out how to make it so that the character still takes damage. But, I was wondering how to make it affected by stats, such as AGI. For example, if somebody has more than 5 AGI points than an enemy, then he would automatically counter the enemy's attack. It would make AGI have so much more purpose than just...being there. My game doesn't even have proper turns, as I am using a TBS. I've looked all over with little success.

Thanks for your time.

ATM
Well, item_cnt determines the counter rate, so...

Code:
class Game_Battler < Game_BattlerBase
  def item_cnt(user, item)
    return 0 unless item.physical?          # Hit type is not physical
    return 0 unless opposite?(user)         # No counterattack on allies
    return 1 if user.agi > self.agi + 5 # If attack has more than 5 points than the attacked
    return cnt                              # Return counterattack rate
  end

end
Thanks, man! I'll test to see if this works!
Code:
return 1 if user.agi > self.agi + 5
The user represents the attacker there, while self is the target. Well, as far as I can remember, but I haven't worked with default scripts for a long time by now, so I might be wrong.
But if I'm not, than that condition will make the opposite, kinda. It will make the target always counterattack if the attacker has at least 5 points more AGI than the target, which would be rather weird, I guess. 😀
The correct one should be:
Code:
return 1 if self.agi > user.agi + 5

Original thread: https://forums.rpgmakerweb.com/threads/counter-attack-affected-by-stats.94028/