For a new weapon, I wanted to play a custom sound when you use it.
The function gets triggered, but the sound doesn't get played.
I have tried these three code snippets, but none of them worked:
[CODE]self:EmitSound("randomdamage_sound/shhh.wav")[/CODE]
[CODE]sound.Add{
name = 'soundsettings',
channel = CHAN_AUTO,
pitch = 100,
level = 500,
volume = 1.0,
sound = 'randomdamage_sound/shhh.wav'
}
local sounddata = Sound('soundsettings')
sound.Play(sounddata, Vector(0,0,0))[/CODE]
[CODE]sounddata = CreateSound(self.Owner, "randomdamage_sound/shhh.wav")
sounddata:Play()[/CODE]
In some cases you may need to pre-cache the sound. The API call for that is on wiki.garrysmod.com
Thank you very much!
I have been pretty sure I've tried this, but now it's working with:
[CODE]function SWEP:Initialize()
util.PrecacheSound("randomdamage_sound/shhh.wav")
end[/CODE]
To play the sound I'm using:
[CODE]sound.Add{
name = 'soundsettings',
channel = CHAN_AUTO,
pitch = 100,
level = 500,
volume = 1.0,
sound = 'randomdamage_sound/shhh.wav'
}
local sounddata = Sound('soundsettings')
sound.Play(sounddata, Vector(0,0,0))[/CODE]
[QUOTE=c0r3;47645711]Thank you very much!
I have been pretty sure I've tried this, but now it's working with:
[CODE]function SWEP:Initialize()
util.PrecacheSound("randomdamage_sound/shhh.wav")
end[/CODE]
To play the sound I'm using:
[CODE]sound.Add{
name = 'soundsettings',
channel = CHAN_AUTO,
pitch = 100,
level = 500,
volume = 1.0,
sound = 'randomdamage_sound/shhh.wav'
}
local sounddata = Sound('soundsettings')
sound.Play(sounddata, Vector(0,0,0))[/CODE][/QUOTE]
FYI, [IMG]http://wiki.garrysmod.com/favicon.ico[/IMG][URL="http://wiki.garrysmod.com/page/Global/Sound"]Global.Sound[/URL] automatically precaches the sound, so you don't need to do it twice.
Sorry, you need to Log In to post a reply to this thread.