SWEP.PrimaryAttack and Player.DrawViewModel

Ahhh, problems problems problems.

The problem: I can’t use SWEP.PrimaryAttack until roughly 15-30 seconds after SWEP.Initialize. Here’s the SWEP code:

[lua]function SWEP:Initialize()

if CLIENT then return end

self.ZoomedMain = false
timer.Simple(0.1,function() if ValidEntity(self.Owner) then self.DefaultFOV = self.Owner:GetFOV()  end end)

end

function SWEP:Deploy()
self.Weapon:SendWeaponAnim(ACT_VM_SECONDARYATTACK)
timer.Simple(0.5,function() if ValidEntity(self.Weapon) then self.Weapon:SendWeaponAnim( ACT_VM_IDLE ) end end )
return true
end

function SWEP:Holster()

if self.ZoomedMain then

	self.Owner:DrawViewModel(true)
	self.Owner:SetFOV(self.DefaultFOV,self.FOVTime)
	self:EmitSound( self.ZoomOut )
	self.Owner:ConCommand("pp_mat_overlay 0");

end

return true

end

function SWEP:PrimaryAttack()

if !self:CanPrimaryAttack() || self.Owner:GetActiveWeapon() != self.Weapon then return end

self.ZoomedMain = !self.ZoomedMain

if self.ZoomedMain then
	
	timer.Simple(0.45,function()
		self.Owner:SetFOV(self.ZoomFOV,0)
		self.Owner:DrawViewModel(false)
		self.Owner:ConCommand("pp_mat_overlay_texture effects/combine_binocoverlay.vmt");
		self.Owner:ConCommand("pp_mat_overlay 1");
	end)
	self:EmitSound( self.ZoomIn )
	self.Weapon:SendWeaponAnim(ACT_VM_PRIMARYATTACK)
	
else
	
	self.Owner:DrawViewModel(true)
	self.Owner:SetFOV(self.DefaultFOV,0)
	self:EmitSound( self.ZoomOut )
	self.Owner:ConCommand("pp_mat_overlay 0");
	self.Weapon:SendWeaponAnim(ACT_VM_SECONDARYATTACK)
end

self:SetNextPrimaryFire( CurTime() + 0.5 )

end[/lua]

I’ve tried things like setting SWEP:NextPrimaryFire(CurTime()), however I consistently get the following error:



weapons\weapon_binoculars\shared.lua:125: attempt to call method 'DrawViewModel' (a nil value)
Timer Error: weapons\weapon_binoculars\shared.lua:116: attempt to call method 'DrawViewModel' (a nil value)


Those lines are the self.Owner:DrawViewModel functions in the SWEP.PrimaryAttack. It’s almost as if the SWEP has to take ten seconds to make sure it can use the DrawViewModel function. Any thoughts as to how to fix this? (soon rather than later, preferably)

Try adding:

if CLIENT then

drawviewmodel

end

to all your drawviewmodels, but only if your experiencing this error in multiplayer, if its singleplayer, I’m not quite sure.