Calculate attack in battle and use that calculation to attack

I Want to make the combat random.
What I did was make a random common event that basically says:

Set User Attack Variable random (1-20)
Show text: "You got \V[attack variable]."
Set Enemy Defense Variable random (1-20)
Show text: "Your opponent got \v[enemy defense variable]."

Attack Variable - Enemy Defense Variable
Attack Variable + Attack [Stat]

I want to do all that before the attack, which is the normal attack skill. It's it at all possible?

I know I can set the formula to be the variable and I know how to do that, but I want to set the variable before the attack.

I've moved this thread to MV Support. Thank you.

Put that event inside of a troop event. You can set it to run once at the start of battle or once before every turn. Use Yanfly’s base troop events plugin to copy it to all troops.

Original thread: https://forums.rpgmakerweb.com/threads/calculate-attack-in-battle-and-use-that-calculation-to-attack.128191/