How do I play a sound with function SWEP:Reload()

I’m trying to make my swep play a sound when I press ‘R’ so I used the function SWEP:Reload().
[lua]
function SWEP:Reload()
self.EmitSound(“vo/medic_jeers04”)
end
[/lua]
I know there is a way to do this, because I used [lua]PrintMessage(HUD_PRINTCENTER, “You are pressing R!”)[/lua] and it worked perfectly fine.

[editline]08:38PM[/editline]

My error:


weapons/testy/shared.lua:43: bad argument #1 to 'EmitSound' (Entity expected, got string)


You did this:
[lua]self.EmitSound(“vo/medic_jeers04”)[/lua]
You are meant to do this:
[lua]self:EmitSound(“vo/medic_jeers04”)[/lua]
See the difference?

I used that and it doesn’t do anything now. And yeah I see the difference, but neither work :geno:

Shouldn’t it be “vo/medic_jeers04.wav” ?

[editline]08:49PM[/editline]

Or whatever format the sound is?

When I go into the console and type


play vo/medic_jeers04

it plays fine.

Have you tried it in the code?

Yeah I added the .wav and it plays, but if I hold down R it loops over and over again :ohdear:

[lua]SWEP.NextReloadTime = 0;

function SWEP:Reload()
if self.NextReloadTime <= CurTime() then
self:EmitSound(“vo/medic_jeers04.wav”)
self.NextReloadTime = CurTime() + 2 – Can only play sound once every 2 seconds.
end
end[/lua]

Thanks, works :v:
Now to get down to hard-coding this baby :dance: