Weapon not emitting sound with Entity:EmitSound()


I have tried several different ways of writing this without being able to get it to work, and I have been scouring the wiki. What I have is a TTT SWEP that selects a target, and switches places with and kills the target player. I am attempting to make it play a sound when it successfully happens.

if SERVER then 

         self:EmitSound("garrysmod/balloon_pop_cute.wav", 511, 100, 1, CHAN_AUTO)

         self:GetOwner():PrintMessage( HUD_PRINTTALK, "You killed " .. self.targEnt:Nick() .. " and switched places with him.")


This is directly after the player is killed. If needed I can post the whole function, or file. Just trying to save space.

No sound is played, but everything else works fine. There are no LUA errors in console. Thinking maybe I am calling EmitSound the wrong way or something is wrong with my arguments. It’s also my understanding EmitSound is shared, so I should be able to call it from SERVER.

Where is your sound file located? Should be relative to the sound folder.

And post the full code please.

You’re using a sound level of “511”, which is out of range for the sound engine. 75 is common level (voice lines, physics impacts). Try 150.

The wiki says up to 511 is allowed?

It’s not wrong, but the way the argument works makes playing a sound at 511 useless. From what I’ve experienced, playing the sound at a level higher than 180, the radius is no longer a circle, it starts to become a taurus, where only a ring around the center of the origin can hear the sound.

Navigated from root folder, sound is in “sound/garrysmod/” so the absolute pathname looks like “D:/Program Files (x86)/Steam/Steamapps/Common/GarrysMod/garrysmod/sound/garrysmod/”

I used 511 because according to the wiki this is the max volume and at first was thinking it was a volume/dB issue with the sound just being quiet. I’ll try again with a lower value.

Here’s the full code: http://pastebin.com/ziTSv4Dz

Keep in mind still toying with it a bunch. Codes not clean by any means.

Does the message pop up that says you killed them and switched places with them?
Is the server sending the sound file to the client?
Does the client console say that the file is probably missing from the disk when you fire the weapon?

[LUA]self.Weapon:EmitSound(“soundpath”)[/LUA] I use on Swep

“self” refers in weapons both on the SWEP table and on the weapon entity.
Using “self.Weapon” instead of “self” wouldn’t make any difference especially in this case.

I did not even think to check if the entire code segment was running properly. I’ll check.

The server does not, as I am testing locally and already have the sound file. Unless I need to for caching or some other reason.

No missing sound error. I’ll recheck to be %100 sure.

[editline]12th November 2016[/editline]

Console output from using SWEP

Current closest target is Bot03. They are 417 units away.
You killed Bot03 and switched places with him.
Something went very wrong!
Something went wrong! Make sure you have a target selected!

I already knew something is screwy here that I have to fix, but it is running the kill message.

function SWEP:PrimaryAttack()

self.Weapon:SetNextSecondaryFire( CurTime() + self.Primary.Delay )
self.Weapon:SetNextPrimaryFire( CurTime() + self.Primary.Delay )

if ( !self:CanPrimaryAttack() ) then return end

// Play shoot sound
--self.Weapon:EmitSound( "npc/sniper/echo1.wav", 75, 100, 1, CHAN_AUTO )

// Remove 1 bullet from our clip
self:TakePrimaryAmmo( 1 )

Just a little example