Firing sound doesn't always play when I shoot a gun in multiplayer

That’s basically it.

Don’t ask me what base I’m using, I make my own sweps from scratch.
If you must know, the script that emits the sound is this:

[lua]function SWEP:PrimaryAttack()
if not self:CanPrimaryAttack() then return end
self.Weapon:EmitSound( self.Primary.Sound )
self.PlayOnce = false
self.Weapon:SetNextPrimaryFire(CurTime() + self.Primary.Delay)

self:ShootBullets(self.Primary.Damage, self.Primary.NumShots, self.Primary.Cone)
self:TakePrimaryAmmo(1)

end[/lua]

The sound plays most of the time, but often it doesn’t and it’s very jarring. I’ve looked at other sweps and this is basically the same code they use, so I’m absolutely puzzled.

Try it with a different sound and see if it still jams. (If it does, we know the problem is the gun, not the sound)

Oh god this. It only seems to happen when you move (for me, at least) , anyway, and it happens to most of the guns I have. I have no idea why it happens, though.

It happens with all my sweps and they all have different noises.

[lua]
function SWEP:PrimaryAttack()
if not self:CanPrimaryAttack() then return end
self.Weapon:EmitSound( self.Primary.Sound )
self.PlayOnce = false
self.Weapon:SetNextPrimaryFire(CurTime() + self.Primary.Delay)

self:ShootBullets(self.Primary.Damage, self.Primary.NumShots, self.Primary.Cone)
self:TakePrimaryAmmo = 1
end
[/lua]

This is what my friend said.

Did he change anything?

You need to predict it.

[lua]
function SWEP:PrimaryAttack()
if ( !self:CanPrimaryAttack() ) then return end

self.Weapon:SetNextPrimaryFire( CurTime() + self.Primary.Delay )

self.Weapon:ShootBullet( sself.Primary.Damage, self.Primary.NumShots, self.Primary.Cone )
self.Weapon:TakePrimaryAmmo( 1 )

if IsFirstTimePredicted() then --Predict that motha' fucka'
	self.Weapon:EmitSound( self.Primary.Sound, 100, math.random(95,105) )
end

end
[/lua]

No dice. It’s still cutting out.

It’s probably the sound then.

It’s not the sounds.
They’re CSS sounds.

How about this? Click ‘view plain’ if the whitespacing is fucked up.

[lua]
function SWEP:PrimaryAttack()
self.Weapon:SetNextSecondaryFire(CurTime() + self.Primary.Delay);
self.Weapon:SetNextPrimaryFire(CurTime() + self.Primary.Delay);

if(!self:CanPrimaryAttack()) then return; end

self.Weapon:EmitSound(self.Primary.Sound);

self:ShootBullet(self.Primary.Damage, self.Primary.Recoil, self.Primary.NumShots, self.Primary.Cone);

self:TakePrimaryAmmo(1);

if(self.Owner:IsNPC()) then return; end -- Skip the following lines for NPCs

self.Owner:ViewPunch(Angle(math.Rand(-0.2, -0.1) * self.Primary.Recoil, math.Rand(-0.1, 0.1) * self.Primary.Recoil, 0 )); -- View punch, not necessary unless you want to

if((SinglePlayer() && SERVER) || CLIENT) then self.Weapon:SetNetworkedFloat("LastShootTime", CurTime()); end -- This is what you're after

end
[/lua]

[lua]
self:TakePrimaryAmmo = 1
[/lua]

Erm, I don’t quite think that is correct.

Lol me either but that’s what he said.

You’re probably using “weapons/smg1_single.wav” or whatever. Try “Weapon_SMG1.Single”

^That is the problem I have had before. I was using
[lua]SWEP.Primary.Sound = Sound( “weapons/deagle-1.wav” )[/lua]
instead of
[lua]SWEP.Primary.Sound = Sound( “Weapon_Deagle.Single” )[/lua]

and the sounds didn’t play all the time, and they were crackly sometimes.

OP, post the segment of the SWEP.Primary.Sound you’re using.

[editline]01:11AM[/editline]

^That is the problem I have had before. I was using
[lua]SWEP.Primary.Sound = Sound( “weapons/deagle-1.wav” )[/lua]
instead of
[lua]SWEP.Primary.Sound = Sound( “Weapon_Deagle.Single” )[/lua]

and the sounds didn’t play all the time, and they were crackly sometimes.

OP, post the segment of the SWEP.Primary.Sound you’re using.

Is there a list of those alternate names?