one way would be to create a variable for each gun
then when the player switches to a particular weapon, you have a section that says
currentgun = "machineGun"
-> every 1 second add +1 to "machineGunTime"
then check which one is the biggest at the end of the game.
There's a fancier way with arrays, but this is the easiest way to visually understand what's going on.