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:
[CODE] //Custom Taunt Delay Variables
local t_delay_p1_b1 = -1.5 //Boom Headshot!
util.AddNetworkString("send_p1_B1")
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
ply:EmitSound(taunt,ply:GetPos(),100)
print("Playing sound:",taunt," Size:",tsound," Old Time:",curTime," New Time:",ply.LastTaunt) //Debugging Console Print
end
else
print("Wait until the taunt is finished playing.")
end
end )[/CODE]
** 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:
[lua]
ply:EmitSound(taunt,ply:GetPos(),100)
[/lua]
Which would attempt to play the taunt at the volume of the players position with 100% pitch. It should be:
[Lua]
ply:EmitSound( taunt, 100, 100, 1, CHAN_AUTO )
[/lua]
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.
[QUOTE=meharryp;46229310]
Your also using , instead of .. to join your strings.[/QUOTE]
While it may not be best practice I believe you can concatenate with , inside of print (it concatenates its arguments).
[QUOTE=meharryp;46229310]You did this:
[lua]
ply:EmitSound(taunt,ply:GetPos(),100)
[/lua]
Which would attempt to play the taunt at the volume of the players position with 100% pitch. It should be:
[Lua]
ply:EmitSound( taunt, 100, 100, 1, CHAN_AUTO )
[/lua]
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.[/QUOTE]
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
[url]http://wiki.garrysmod.com/page/Global/EmitSound[/url]
with
[url]http://wiki.garrysmod.com/page/Entity/EmitSound[/url]
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.
[QUOTE=DEFCON1;46229628]You seem to confuse
[url]http://wiki.garrysmod.com/page/Global/EmitSound[/url]
with
[url]http://wiki.garrysmod.com/page/Entity/EmitSound[/url]
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.[/QUOTE]
Well thanks, cause when I went to the wiki prior posting this thread this part:
[QUOTE] number soundLevel=75
A modifier for the distance this sound will reach, acceptable range is 0 to 511. 100 means no adjustment to the level.[/QUOTE]
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 :)
[editline]14th October 2014[/editline]
[QUOTE=VashBaldeus;46225955]
** I came up with "t_delay_p1_b1" variable after I noticed that SoundDuration() gave a random delay time(sometimes longer & sometimes shorter)[/QUOTE]
I believe the best way is to manually store the lenght of each sounds in a table, like:
[code]
local tauntsLenght =
{
["taunts/props/1.wav"] = 12, -- seconds
["taunts/props/2.wav"] = 8,
}
[/code]
And then use this table like so:
[code]ply.LastTaunt = CurTime() + ( tauntsLenght[ taunt ] or 5 )[/code]
[QUOTE=VashBaldeus;46229638]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![/QUOTE]
My bad, I was in the middle of editing it.
[QUOTE=DEFCON1;46229641]Just do ply:EmitSound(taunt) and it should be good with the defaults parameters :)
[editline]14th October 2014[/editline]
I believe the best way is to manually store the lenght of each sounds in a table, like:
[code]
local tauntsLenght =
{
["taunts/props/1.wav"] = 12, -- seconds
["taunts/props/2.wav"] = 8,
}
[/code]
And then use this table like so:
[code]ply.LastTaunt = CurTime() + ( tauntsLenght[ taunt ] or 5 )[/code][/QUOTE]
Thanks, this solves me a great headache more or less :)
[QUOTE=DEFCON1;46229628]You seem to confuse
[url]http://wiki.garrysmod.com/page/Global/EmitSound[/url]
with
[url]http://wiki.garrysmod.com/page/Entity/EmitSound[/url]
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.[/QUOTE]
When I did:
[code]ply.EmitSound(taunt,100)[/code]
It played the sound but with an echo and more or less with out consideration of the other player locations...
[QUOTE=DEFCON1;46229641]Just do ply:EmitSound(taunt) and it should be good with the defaults parameters[/QUOTE]
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
[QUOTE=meharryp;46230898]Because its ply:EmitSound not ply.EmitSound[/QUOTE]
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 :)
Sorry, you need to Log In to post a reply to this thread.