• Why does the sound of my weapon skip?
    11 replies, posted
Hi, So I made some gun, and it skips sounds like if I shoot with a 30 round burst, it will go: ShotShotShotShotShotShotNothingNothingNothingNothingShotShotShotShotShotNothingNothingNothingNothingShotShotShotShotShotShotShotNothingNothingNothingNothing I have no idea why D: Here is my code for one of the weapons: [CODE]//General Settings\\ SWEP.Category = "WWII TTT Weapons" SWEP.Kind = WEAPON_HEAVY SWEP.HoldType = "ar2" SWEP.Base = "weapon_tttbase" SWEP.AutoSpawnable = true SWEP.Spawnable = true SWEP.AdminSpawnable = true SWEP.AutoSwitchTo = false SWEP.AutoSwitchFrom = false SWEP.Icon = "VGUI/ttt/weapon_bk_mp44" //Serverside Settings\\ if ( SERVER ) then AddCSLuaFile( "shared.lua" ) resource.AddFile("materials/VGUI/ttt/weapon_bk_mp44.vmt") end //Clientside Settings\\ if ( CLIENT ) then SWEP.PrintName = "MP44" SWEP.Author = "Bakht" SWEP.ViewModelFOV = 50 SWEP.Slot = 2 end //Sounds and Models\\ SWEP.ViewModel = "models/weapons/v_mp44.mdl" SWEP.WorldModel = "models/weapons/w_mp44.mdl" local FireSound = Sound ("weapons/mp44_shoot.wav"); local ReloadSound = Sound ("weapons/mp44_worldreload.wav"); SWEP.IronSightsPos = Vector (-4.9, -10, 3.1) SWEP.IronSightsAng = Vector (-4.9, -10, 3.1) SWEP.ViewModelFlip = false SWEP.Weight = 5 //Damage Statistics\\ SWEP.Primary.Recoil = 3.5 SWEP.Primary.Damage = 52 SWEP.Primary.NumShots = 1 SWEP.Primary.Cone = 0.004 SWEP.Primary.ClipSize = 30 SWEP.Primary.Delay = 1.5 SWEP.Primary.DefaultClip = 30 SWEP.Primary.Automatic = true SWEP.Primary.Ammo = "smg1" SWEP.Secondary.Automatic = true SWEP.Secondary.Ammo = "none" SWEP.AmmoEnt = "item_ammo_smg1_ttt" //Functions\\ function SWEP:Reload() if (self.Weapon:Clip1() < 30) then if self.Owner:GetAmmoCount(self.Primary.Ammo) > 0 then self.Weapon:EmitSound( ReloadSound ) end self.Weapon:DefaultReload( ACT_VM_RELOAD ); self:SetIronsights( false ) end end 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( FireSound ) self:ShootBullet( self.Primary.Damage, self.Primary.Recoil, self.Primary.NumShots, self.Primary.Cone ) self:TakePrimaryAmmo( 1 ) if ( self.Owner:IsNPC() ) then return end self.Owner:ViewPunch( Angle( math.Rand(-0.2,-0.1) * self.Primary.Recoil, math.Rand(-0.1,0.1) *self.Primary.Recoil, 0 ) ) if ( (game.SinglePlayer() && SERVER) || CLIENT ) then self.Weapon:SetNetworkedFloat( "LastShootTime", CurTime() ) end end [/CODE]
Playing raw sound files will cause this... Only a certain amount of sounds can be played on a single entity... I think using sound.Play could fix it not sure... Or otherwise you could make a soundscript for it and use that instead (Weapon.Pistol.Single etc) soundscripts will stop the current soundscript being run on a entity and play a new one.. This is a good method for automatic weapons I dont know how though...
[QUOTE=LordiAnders;43725510]Playing raw sound files will cause this... Only a certain amount of sounds can be played on a single entity... I think using sound.Play could fix it not sure... Or otherwise you could make a soundscript for it and use that instead (Weapon.Pistol.Single etc) soundscripts will stop the current soundscript being run on a entity and play a new one.. This is a good method for automatic weapons I dont know how though...[/QUOTE] Thanks, but is there any surefire way to fix this?
Try [URL="http://wiki.garrysmod.com/page/sound/Play"]sound.Play[/URL] just to start with Try replace "self.Weapon:EmitSound( FireSound )" with "sound.Play(FireSound,self.Owner:GetShootPos())" Its not really the most clever way of doing it... But i assume the sounds wont overlap when using this If its too harsh for you to bear ill find a way of adding soundscripts so you can use that instead
I wouldn't use sound.Play, since that would make the sound client side only. Instead, you could try adding a sound script like this: [code]sound.Add({ name = "my_weapon_sound", channel = CHAN_WEAPON, -- Make sure to use the correct channel. volume = 1.0, soundlevel = 145, -- https://developer.valvesoftware.com/wiki/Soundscripts#SoundLevel pitchstart = 100, pitchend = 100, sound = "mysound.wav" -- This is relative to sound/ so no need to prefix. });[/code]
[QUOTE=Walrus Viking;43727663]I wouldn't use sound.Play, since that would make the sound client side only. Instead, you could try adding a sound script like this: [code]sound.Add({ name = "my_weapon_sound", channel = CHAN_WEAPON, -- Make sure to use the correct channel. volume = 1.0, soundlevel = 145, -- https://developer.valvesoftware.com/wiki/Soundscripts#SoundLevel pitchstart = 100, pitchend = 100, sound = "mysound.wav" -- This is relative to sound/ so no need to prefix. });[/code][/QUOTE] Hey, thanks for that, where would I put that script, and what would I put for the weapon sound? Just the regular SWEP.Primary.Sound = Sound(my_weapon_sound)?
[QUOTE=bakht;43728569]Hey, thanks for that, where would I put that script, and what would I put for the weapon sound? Just the regular SWEP.Primary.Sound = Sound(my_weapon_sound)?[/QUOTE] You could put that script in the shared file for the weapon, and to assign the sound to it: [code]SWEP.Primary.Sound = Sound( "my_weapon_sound" );[/code]
[QUOTE=Walrus Viking;43729474]You could put that script in the shared file for the weapon, and to assign the sound to it: [code]SWEP.Primary.Sound = Sound( "my_weapon_sound" );[/code][/QUOTE] Ok then, but what about the reload sound? Would I just make another script, but then if I do need to do that, how would I make it happen when the weapon reloads?
Using SWEP:Reload()
So would this be correct?[CODE] //General Settings\\ SWEP.Category = "WWII TTT Weapons" SWEP.Kind = WEAPON_HEAVY SWEP.HoldType = "ar2" SWEP.Base = "weapon_tttbase" SWEP.AutoSpawnable = true SWEP.Spawnable = true SWEP.AdminSpawnable = true SWEP.AutoSwitchTo = false SWEP.AutoSwitchFrom = false SWEP.Icon = "VGUI/ttt/weapon_bk_mp44" //Serverside Settings\\ if ( SERVER ) then AddCSLuaFile( "shared.lua" ) resource.AddFile("materials/VGUI/ttt/weapon_bk_mp44.vmt") end //Clientside Settings\\ if ( CLIENT ) then SWEP.PrintName = "MP44" SWEP.Author = "Bakht" SWEP.ViewModelFOV = 50 SWEP.Slot = 2 end //Sounds and Models\\ SWEP.ViewModel = "models/weapons/v_mp44.mdl" SWEP.WorldModel = "models/weapons/w_mp44.mdl" local FireSound = Sound ("weapons/mp44_shoot.wav"); local ReloadSound = Sound ("weapons/mp44_worldreload.wav"); SWEP.IronSightsPos = Vector (-4.9, -10, 3.1) SWEP.IronSightsAng = Vector (-4.9, -10, 3.1) SWEP.ViewModelFlip = false SWEP.Weight = 5 //Damage Statistics\\ SWEP.Primary.Recoil = 3.5 SWEP.Primary.Damage = 52 SWEP.Primary.NumShots = 1 SWEP.Primary.Cone = 0.004 SWEP.Primary.ClipSize = 30 SWEP.Primary.Delay = 1.5 SWEP.Primary.DefaultClip = 30 SWEP.Primary.Automatic = true SWEP.Primary.Ammo = "smg1" SWEP.Secondary.Automatic = true SWEP.Secondary.Ammo = "none" SWEP.AmmoEnt = "item_ammo_smg1_ttt" SWEP.Primary.Sound = Sound( "Mp44.Single" ); sound.Add({ name = "Mp44.Single", channel = CHAN_WEAPON, -- Make sure to use the correct channel. volume = 1.0, soundlevel = 145, -- [url]https://developer.valvesoftware.com/wiki/Soundscripts#SoundLevel[/url] pitchstart = 100, pitchend = 100, sound = "weapons/mp44_shoot.wav" -- This is relative to sound/ so no need to prefix. }); //Functions\\ function SWEP:Reload() if (self.Weapon:Clip1() < 30) then if self.Owner:GetAmmoCount(self.Primary.Ammo) > 0 then self.Weapon:EmitSound( ReloadSound ) end self.Weapon:DefaultReload( ACT_VM_RELOAD ); self:SetIronsights( false ) end end[/CODE]
[QUOTE=Walrus Viking;43727663]I wouldn't use sound.Play, since that would make the sound client side only. Instead, you could try adding a sound script like this: [code]sound.Add({ name = "my_weapon_sound", channel = CHAN_WEAPON, -- Make sure to use the correct channel. volume = 1.0, soundlevel = 145, -- https://developer.valvesoftware.com/wiki/Soundscripts#SoundLevel pitchstart = 100, pitchend = 100, sound = "mysound.wav" -- This is relative to sound/ so no need to prefix. });[/code][/QUOTE] This is the exact solution anyone with this problem should use, it makes your sound use the sound channels which behave differently, for example the weapon channel uses the 'last in, first played' rule, which means that any new sounds that get played overwrite previous sounds, which means when you play say, 5 shot sounds really fast, the latest shot sound is the one that is played, whereas by default, the engine won't play a new sound while another sound is playing.
Thanks my friends, you have helped me a lot :D
Sorry, you need to Log In to post a reply to this thread.