Called when primary attack button ( +attack ) is pressed.
Since this is a .
When in singleplayer, this function is only called in the server realm. When in multiplayer, the hook will be called on both the server and the client in order to allow for Prediction.
You can force the hook to always be called on client like this:
Note that due to prediction, in multiplayer SWEP:PrimaryAttack is called multiple times per one "shot" with the gun. To work around that, use IsFirstTimePredicted.
This is how it is defined in weapon_base