How can I get two sounds to be able to play at once?

I was working on a swep where you could right click to play music and left click to shoot. But if I shoot while the music is playing it stops the music. Anyone know a way to play 2 sounds at once?

Can you show us the code for the sounds?

Well I just decided to make a new swep that doesn’t have a main fire sound. But I recreated the problem I was having here. As you can see, if I right click to play the music and then left click to play the gunshot sound it stops the music.


local FireSound = Sound("NPC_Combine.GrenadeLaunch")
local FireSound2 = Sound("weapons/happy.wav")

function SWEP:PrimaryAttack()
self:ThrowBarrel ( model_file )
self.Weapon:SetNextPrimaryFire( CurTime() + 0.2 )
end


function SWEP:SecondaryAttack()
self:EmitSound( FireSound2 )
end

I think entities are bound to playing 1 song at a time. You could try emitting 1 sound on the gun and the other on the player.

PrimaryAttack isn’t creating its own sound? In any case, it sounds like you are overlapping sound channels. You have to realize that the entity (in this case the weapon) is emitting a sound. If you attempt to make that same entity emit another sound before the first sound is over, it will cause the first sound to stop.

You could try to do something like this (but I didn’t test it so dont take me on my word). This is also assuming the shooting sounds eventually end on their own (and don’t loop)



local FireSound = Sound("NPC_Combine.GrenadeLaunch")
local FireSound2 = Sound("weapons/happy.wav")

function SWEP:PrimaryAttack()
self:ThrowBarrel ( model_file )
local PrimaryAttackSound = CreateSound(self.Weapon, FireSound)
PrimaryAttackSound:Play()

self.Weapon:SetNextPrimaryFire( CurTime() + 0.2 )
end

function SWEP:SecondaryAttack()
local SecondaryAttackSound = CreateSound(self.Weapon, FireSound2)
SecondaryAttackSound:Play()
end


Yeah I guess that was my question. If an entity can emit 2 sounds at once and that’s a no.

Thanks