• EmitSound playing clientside
    14 replies, posted
I've been trying to emit a sound globally to the server, much like a taunt from prophunt. However every time I the function is called, it produces the sound client side instead of serverside. I did some reading on [URL="http://wiki.garrysmod.com/page/Entity/EmitSound"]Entity:EmitSound()[/URL] and it says that: [QUOTE]Plays a sound on an entity. If run clientside, the sound will only be heard locally.[/QUOTE] It is apparent that I emitting the sound over clientside instead of serverside. Below is an excerpt from my code [CODE]function TauntFunc() local ply = LocalPlayer() if( CurTime() - LastTaunt > RepeatRate) then if not ply:Alive() then return end repeat rand_taunt = table.Random(TAUNTS) until rand_taunt != recent recent = rand_taunt self.Weapon:EmitSound(rand_taunt, loudness) temp = GetConVarNumber("dance_enable") LastTaunt = CurTime() if (temp == 0)then return else ply:ConCommand(table.Random(ACT)) end end end concommand.Add("Taunt", TauntFunc)[/CODE] I assume that LocalPlayer() is causing emitsound to play only on the client side, however what should I use to get the player who calls the function/command?
[code] If ( SERVER ) then [/code] ?
[QUOTE=Duinrahaic;46859873]I've been trying to emit a sound globally to the server, much like a taunt from prophunt. However every time I the function is called, it produces the sound client side instead of serverside. I did some reading on [URL="http://wiki.garrysmod.com/page/Entity/EmitSound"]Entity:EmitSound()[/URL] and it says that: It is apparent that I emitting the sound over clientside instead of serverside. Below is an excerpt from my code [CODE]function TauntFunc() local ply = LocalPlayer() if( CurTime() - LastTaunt > RepeatRate) then if not ply:Alive() then return end repeat rand_taunt = table.Random(TAUNTS) until rand_taunt != recent recent = rand_taunt self.Weapon:EmitSound(rand_taunt, loudness) temp = GetConVarNumber("dance_enable") LastTaunt = CurTime() if (temp == 0)then return else ply:ConCommand(table.Random(ACT)) end end end concommand.Add("Taunt", TauntFunc)[/CODE] I assume that LocalPlayer() is causing emitsound to play only on the client side, however what should I use to get the player who calls the function/command?[/QUOTE] [CODE]if SERVER then function TauntFunc(ply) ply.LastTaunt = ply.LastTaunt or 0 if( CurTime() - ply.LastTaunt > RepeatRate) then if not ply:Alive() then return end repeat rand_taunt = table.Random(TAUNTS) until rand_taunt != recent recent = rand_taunt -- That seems invalid -- self.Weapon:EmitSound(rand_taunt, loudness) temp = GetConVarNumber("dance_enable") ply.LastTaunt = CurTime() if (temp == 0)then return else ply:ConCommand(table.Random(ACT)) end end end concommand.Add("Taunt", TauntFunc) end[/CODE]
[QUOTE=Dear_Matt;46860102][CODE] -- That seems invalid -- self.Weapon:EmitSound(rand_taunt, loudness) [/CODE][/QUOTE] Oh thanks for pointing that out, I was fiddling with the code. However I will return with if(Server)then and see if it works!
That seems to be wrong... [url]http://wiki.garrysmod.com/page/Entity/EmitSound[/url] Ent:EmitSound when applied on the server will be localized to the entity ( meaning people around the entity hear the sound; but not global ). If you want a sound heard at the same sound-level use surface.PlaySound ( clientside; network from server the string sound OR index in a shared table of sounds )
[CODE]if SERVER then function TauntFunc(ply) --taunting ply.LastTaunt = ply.LastTaunt or 0 if( CurTime() - ply.LastTaunt > RepeatRate) then if not ply:Alive() then return end repeat rand_taunt = table.Random(TAUNTS) until rand_taunt != recent recent = rand_taunt ply:EmitSound(rand_taunt, loudness) --dancing temp = GetConVarNumber("dance_enable") ply.LastTaunt = CurTime() if (temp == 0)then return else ply:ConCommand(table.Random(ACT)) end end end concommand.Add("Taunt", TauntFunc) end [/CODE] Corrected an error as stated above and changed the entity to ply (player) however the sound is still only emiting on the client side. [editline]5th January 2015[/editline] [QUOTE=Acecool;46862031]That seems to be wrong... [url]http://wiki.garrysmod.com/page/Entity/EmitSound[/url] Ent:EmitSound when applied on the server will be localized to the entity ( meaning people around the entity hear the sound; but not global ). If you want a sound heard at the same sound-level use surface.PlaySound ( clientside; network from server the string sound OR index in a shared table of sounds )[/QUOTE] If I understand what you are saying, you describing a local area sound, and serverwide (global) sound I want it to be localized to the entity, similar to the taunting in prop hunt. In which this code is similar to the function GM:ShowSpare1 in their github [CODE]function GM:ShowSpare1(pl) if GAMEMODE:InRound() && pl:Alive() && (pl:Team() == TEAM_HUNTERS || pl:Team() == TEAM_PROPS) && pl.last_taunt_time + TAUNT_DELAY <= CurTime() && #PROP_TAUNTS > 1 && #HUNTER_TAUNTS > 1 then -- Select random taunt until it doesn't equal the last taunt. repeat if pl:Team() == TEAM_HUNTERS then rand_taunt = table.Random(HUNTER_TAUNTS) else rand_taunt = table.Random(PROP_TAUNTS) end until rand_taunt != pl.last_taunt pl.last_taunt_time = CurTime() pl.last_taunt = rand_taunt pl:EmitSound(rand_taunt, 100) end end[/CODE]
You could also use [URL="http://wiki.garrysmod.com/page/sound/Play"]sound.Play[/URL], and get the ent's position..
Yes, ply:EmitSound is "local" when called on the server. Calling ply:EmitSound on the server will have the player attempt to lipsync the audio and player it over x distance. The entire server / mapwide will NOT hear the sound, only those within x distance. For map-wide you'd use surface.PlaySound ( after networking data to client and running that on client )
[QUOTE=Acecool;46866360]Yes, ply:EmitSound is "local" when called on the server. Calling ply:EmitSound on the server will have the player attempt to lipsync the audio and player it over x distance. The entire server / mapwide will NOT hear the sound, only those within x distance. For map-wide you'd use surface.PlaySound ( after networking data to client and running that on client )[/QUOTE] I was just suggesting that becauee he mentioned it to be like prop hunt.
[QUOTE=Acecool;46866360]Yes, ply:EmitSound is "local" when called on the server. Calling ply:EmitSound on the server will have the player attempt to lipsync the audio and player it over x distance. The entire server / mapwide will NOT hear the sound, only those within x distance. For map-wide you'd use surface.PlaySound ( after networking data to client and running that on client )[/QUOTE] EmitSound is what I want since it only emits in a range of "x", which would be the variable loudness (loudness = 100 in my code). So where could I have possibly gone wrong in my code that the audio is only audible to the client, and not the other players? Below is what I have so far: [CODE]if (SERVER) then function TauntFunc(ply) --taunting ply.LastTaunt = ply.LastTaunt or 0 if( CurTime() - ply.LastTaunt > RepeatRate) then if not ply:Alive() then return end repeat rand_taunt = table.Random(TAUNTS) until rand_taunt != recent recent = rand_taunt ply:EmitSound(rand_taunt, loudness) --dancing temp = GetConVarNumber("dance_enable") ply.LastTaunt = CurTime() if (temp == 0)then return else ply:ConCommand(table.Random(ACT)) end end end concommand.Add("Taunt", TauntFunc) end[/CODE]
[QUOTE=Exploderguy;46864859]You could also use [URL="http://wiki.garrysmod.com/page/sound/Play"]sound.Play[/URL], and get the ent's position..[/QUOTE] I want it to stay with the player, doesn't sound.Play leave it in the location it is called at?
[QUOTE=Duinrahaic;46870030]I want it to stay with the player, doesn't sound.Play leave it in the location it is called at?[/QUOTE] It does, it sort of depends how long the sound goes for, also, is this file run serverside?
Yes, this file will be ran server side.
EmitSound will follow the player. Additionally if you use CreateSound on an entity, then those will follow the entity as well.
Thanks for all the help! Managed to go full circle until it magically worked. Lol
Sorry, you need to Log In to post a reply to this thread.