SendWeaponAnim() Not working consistently

I’m trying to make a swep capable of reloading even if it has a full magazine already. (If someone knows how to force a reload even with a full mag, please let me know because it will make all my problems go away)

I’m doing this by doing self:SendWeaponAnim( ACT_VM_RELOAD ) which works very well about 50% of the time. The other 50% the animation plays for like 4 frames of animation before toggling to idle abruptly.

I’ve tried doing things like sending ACT_VM_IDLE just before reloading, as well as waiting in a timer for a very small time after sending idle before reloading and neither seemed to work.

If anyone has any ideas I would love to hear them.


function SWEP:Reload()
	if not IsFirstTimePredicted() then return end
	
	//Prevents reloading while reloading
	if self.reloadLock then return end

	
	if( self:Clip1() >= self:GetMaxClip1() or self:Clip1() == 0 ) then

		self.reloadLock = true

		local seq = self:LookupSequence( "reload" )
		local dur = self:SequenceDuration( seq )

		self:SetNextPrimaryFire( CurTime() + dur )

		timer.Simple( dur, function()
			if not IsValid( self ) then return end
			self.reloadLock = nil

			//Interface with renegade hud to show ammo count
			timerLen = 5
			timer.Create( "RenHUDAmmoSideTimer", timerLen, 1, function() end)

		end )

		if CLIENT then
			self:SendWeaponAnim( ACT_VM_RELOAD )
		end

		

	else
		self:DefaultReload( ACT_VM_RELOAD )
	end

	self:EmitSound( "rifl/rifle_reload.wav", _, _, _, CHAN_WEAPON )

end

You shouldn’t use SendWeaponAnim when not IsFirstTimePredicted

I’ve just solved this, actually! It’s far worse than I could have possibly imagined. I was calling it clientside but it looks like the winning move is to call it serverside.

Unfortunately it looks like you can’t call it twice in a row with the same animation so you have to call another animation, ACT_VM_IDLE in my case, then immediately call it with the actual animation you want. But, this won’t work because it just ignores the first animation you send it if they’re that close so you have to put the second animation call inside a timer.Simple with a time of 0 to get it to run on the next tick which is exactly what you need.

For anyone searching for this problem in the future, here’s the exact code I’m using inside of my SWEP:Reload() function:



if SERVER then
	self:SendWeaponAnim( ACT_VM_IDLE )

	timer.Simple( 0, function() 
		self:SendWeaponAnim( ACT_VM_RELOAD )
	end)
end