SecondaryAttack() called multiple times on the client?

Hi,

There’s this really odd problem with my SWEP. Basically, on the server SecondaryAttack() is called only once (as it should), but on the client it gets called multiple times.

Here’s how I’ve defined my SWEP’s secondary attack variables.



--Secondary fire.
SWEP.Secondary.ClipSize		= -1
SWEP.Secondary.DefaultClip	= -1
SWEP.Secondary.Automatic	= false
SWEP.Secondary.Ammo			= "none"


Here’s my secondary attack function.



--[[ SecondaryAttack()
Activates when +attack2 is pressed. --]]
function SWEP:SecondaryAttack()
	if( self.Weapon:GetNextSecondaryFire() > CurTime() ) then return end
	
	print( "SWEP:SecondaryAttack()" )
	
	self.Weapon:SetNextSecondaryFire( CurTime() + 0.2 )
end


So, when I press right click ONCE on the client, then the server prints the line only once to the console, yet on the client it’s printed twice, thrice and sometimes even four times in a row. Any ideas?

This guy has the same problem as you, it seems. In that thread I ran his code and verified that secondary fire only runs once per mouse click. This is puzzling.

There is a function for that, try:

IsFirstTimePredicted() and check if its true.

Thanks, IsFirstTimePredicted() worked like a charm.