SendWeaponAnim Problem

I’ve been having a problem with the shooting animation on a swep that I’ve been working on. Most of the time the animation wouldn’t play at all, however it would occasionally play one or two frames then stop. After toying around with it, I realized that when I removed SetNextPrimaryFire(), the animation was able to fully play through.

To fix this, I tried:



function SWEP:PrimaryAttack()

	if not (CurTime() >= self:GetNetworkedFloat("LastShot") + (60 / self.RPM)) then return end 
	self:SetNetworkedFloat("LastShot", CurTime())
	self:EmitSound(self.Sound)
	self:SendWeaponAnim( ACT_VM_PRIMARYATTACK )
	--blah blah blah
end


However, it turns out that SetNetworkedFloat() does the same exact thing! HOW DO I GET AROUND THIS!?

are you just setting that networked var for debugging purposes?
I really don’t see any reason to have the time of the last shot transferred to all clients (which is what networked vars are for)

Use self.LastShot instead:
[lua]function SWEP:PrimaryAttack()

if not (CurTime() >= self.LastShot + (60 / self.RPM)) then return end 
self.LastShot = CurTime()
self:EmitSound(self.Sound)
self:SendWeaponAnim( ACT_VM_PRIMARYATTACK )
--blah blah blah

end[/lua]

In another step you could get rid of that long line as well, while optimizing the code a bit:
[lua]function SWEP:PrimaryAttack()
if CurTime() < self.NextShot then return end

self.NextShot = CurTime() + 60 / self.RPM
self:EmitSound(self.Sound)
self:SendWeaponAnim( ACT_VM_PRIMARYATTACK )
--blah blah blah

end[/lua]

oh and make sure you do “self.NextShot=0” in SWEP:Initialize()

Thanks, don’t know what I was thinking with the networked variable now that I think of it, haha.

EDIT:
That fucks it up also, what is going on?!

maybe your animation is broken? did you try running it with lua_run?

Is your SWEP set to automatic fire?

[lua]
SWEP.Primary.Automatic = false
[/lua]

It’s not the animation, and the swep isn’t automatic.