Shoot in melee

How to make it so that when player 1 is near to the player 2, you can shoot at him
and not for the player to start melee fight with firearms