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().
function SWEP:Reload()
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.


My error:

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

You did this:
You are meant to do this:
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” ?


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.NextReloadTime = CurTime() + 2 – Can only play sound once every 2 seconds.

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