Update: I forgot I made this thread.
I still don’t know why it only happens in srcds.
Edit: Title is a lie, should be “SendWeaponAnim randomly fails on dedicated servers”
Observe the following code:
[lua]SWEP.PrintName = “reload anim lol”
SWEP.Spawnable = true
SWEP.ViewModel = “models/weapons/v_smg1.mdl”
SWEP.WorldModel = “models/weapons/w_smg1.mdl”
if self.Reloading then return end
self.Reloading = true
if CLIENT then chat.AddText("reloading") end self:EmitSound("Weapon_SMG1.Reload") self:SendWeaponAnim(ACT_VM_RELOAD) self.Owner:SetAnimation(PLAYER_RELOAD) timer.Simple(self:SequenceDuration(), function() if self:IsValid() then if CLIENT then chat.AddText("done (" .. math.Round(CurTime(), 0) .. ")") end self.Reloading = false end end)
In singleplayer or on a listen server, this works fine. Flawlessly. I can reload forever with no problems or animation glitches.
On a dedicated server on my own machine, when I reload the weapon one of three things will occasionally but not always happen:
- swep:EmitSound() has no effect
- swep:SendWeaponAnim() has no effect
- swep:SendWeaponAnim() causes the viewmodel to “twitch”, where it starts the reload animation and immediately stops
Video: Did my best to record it but the code above glitches very rarely compared to the SWEP I was working on originally. Like, 20-30 reloads work fine and then the next 3 fuck up kind of rare, and “the twitch” only seemed to show up when I wasn’t recording.
As you can see from the chat spam, SWEP:Reload() is being called, but occasionally the reload animation simply doesn’t work:
Is there something I should know here? Is this just some inexplicable fucking problem with dedicated servers, like SoundDuration() returning twice the real value?