ply.EmitSound() creating a fade effect...

I created a Derma Menu that when a player access it he can play a sound for everyone to hear.(making a taunt menu for Prop Hunt)
But I failed in creating a server side ply.EmitSound() that will create a fade effect as other players go further from the player who initialized the taunt.
Basically the taunt should play on the Player1 last location or will follow the player as he moves as long as it’s playing, while others who hear the taunt will get it in a lower volume as they go further away from Player1.

Here’s an example of my server side code:

	//Custom Taunt Delay Variables
	local t_delay_p1_b1		=	-1.5	//Boom Headshot!
	net.Receive( "send_p1_B1", function( _, ply )
		local taunt = net.ReadString()
		local tsound = SoundDuration(taunt)
		local curTime = CurTime()
		if curTime - ( ply.LastTaunt or 0 ) >= TAUNT_DELAY then
			ply.LastTaunt = CurTime() + t_delay_p1_b1
			for _, ply in pairs( player.GetAll() ) do
				print("Playing sound:",taunt,"	Size:",tsound,"	Old Time:",curTime,"	New Time:",ply.LastTaunt) //Debugging Console Print
			print("Wait until the taunt is finished playing.") 
	end )

** I came up with “t_delay_p1_b1” variable after I noticed that SoundDuration() gave a random delay time(sometimes longer & sometimes shorter), if you can give me a hint how to make it more simple I am all ears.

So any tips on how can I create such an effect?

Appreciate the help!
//Vash Baldeus

You did this:
Which would attempt to play the taunt at the volume of the players position with 100% pitch. It should be:
ply:EmitSound( taunt, 100, 100, 1, CHAN_AUTO )
Which plays the taunt up to 100 hammer units, at normal pitch, full volume, on any free channel.

[editline]14th October 2014[/editline]

Your also using , instead of … to join your strings.

While it may not be best practice I believe you can concatenate with , inside of print (it concatenates its arguments).

So if understood you correctly it should play the sound to everyone corresponding to Player1 position who started the taunt, meaning the further they go away from Player1 the lower the sound of the taunt?

You seem to confuse


If you read carefully, it says the soundLevel parameter is what need to be modified in your case, most things use 75 as soundLevel, this will make the sound fade realistically with distance.

Well thanks, cause when I went to the wiki prior posting this thread this part:

confused me… most likely didn’t understood it properly…

Thanks allot for the explanation!

Just do ply:EmitSound(taunt) and it should be good with the defaults parameters :slight_smile:

[editline]14th October 2014[/editline]

I believe the best way is to manually store the lenght of each sounds in a table, like:

local tauntsLenght =
  ["taunts/props/1.wav"] = 12, -- seconds
  ["taunts/props/2.wav"] = 8,

And then use this table like so:

ply.LastTaunt = CurTime() + ( tauntsLenght[ taunt ] or 5 )

My bad, I was in the middle of editing it.

Thanks, this solves me a great headache more or less :slight_smile:

When I did:


It played the sound but with an echo and more or less with out consideration of the other player locations…

With ply:EmitSound(taunt, 100) you are setting soundLevel to 100, which is why it doesn’t fade out realistically, the default value is 75, so leave it as it is

Because its ply:EmitSound not ply.EmitSound

If ply.EmitSound is used, self needs to be passed in as the first var, ie ply, otherwise the vars will shift…

ply.EmitSound( ply, … ) will be the same as ply:EmitSound( … )

Thank you everyone for the help, I found the issue and fixed it now it works :slight_smile: