• What can I use serverside that is similar to LocalPlayer() clientside?
    9 replies, posted
Uh, question, is there some sort of version of LocalPlayer() I can use serverside? This is kind of a follow-up to a question I asked on Problems That Don't Need Their Own Thread about emitting a sound every 3 seconds, but it can only be done clientside, so I can emit a sound from the player without using player.GetByID(). Entity:EmitSound wiki page: "Plays a sound on an entity. If run clientside, the sound will only be heard locally." So, because GM:Think() has no arguments for a local player, what could I use to emit a sound clientside but make it be heard by all players serverside? I'm thinking net messages are the only answer, but I don't want to send one every 10 seconds(unless that's okay to do) [code]--cl_init.lua local threshold = 10.0 local _lastFired = 0 hook.Add("Think", "SomeName", function() if CurTime() - _lastFired >= threshold then _lastFired = CurTime() LocalPlayer():EmitSound( table.Random( combrand ), 75, 100 ) end end) [/code] AKA me wanting to use this code serverside but I don't know what to use to emit the sound from the local player because localplayer() can't be used serverside
[QUOTE=A Fghtr Pilot;47845557]Uh, question, is there some sort of version of LocalPlayer() I can use serverside? This is kind of a follow-up to a question I asked on Problems That Don't Need Their Own Thread about emitting a sound every 3 seconds, but it can only be done clientside, so I can emit a sound from the player without using player.GetByID(). Entity:EmitSound wiki page: "Plays a sound on an entity. If run clientside, the sound will only be heard locally." So, because GM:Think() has no arguments for a local player, what could I use to emit a sound clientside but make it be heard by all players serverside? I'm thinking net messages are the only answer, but I don't want to send one every 10 seconds(unless that's okay to do) [code]--cl_init.lua local threshold = 10.0 local _lastFired = 0 hook.Add("Think", "SomeName", function() if CurTime() - _lastFired >= threshold then _lastFired = CurTime() LocalPlayer():EmitSound( table.Random( combrand ), 75, 100 ) end end) [/code] AKA me wanting to use this code serverside but I don't know what to use to emit the sound from the local player because localplayer() can't be used serverside[/QUOTE] You just asked this question, why make a new thread for it? In any case, I'm not sure what you want to do. Do you want to emit the sound from all players? In which case, a simple loop of player.GetAll(). If you want to play it on a specific player, just get the player from their ID that you've saved somewhere (or better yet, just save the reference to the player). You asked if there was a version of LocalPlayer() serverside, which makes me wonder if you understand the different realms. Clientside has a LocalPlayer() function because, although there are all the players locally aswell, you are controlling one of them, which makes it special. Serverside however doesn't control a specific player, it controls all of them. If there was a LocalPlayer(), what would it even point to?
[QUOTE=James xX;47845602]You just asked this question, why make a new thread for it? In any case, I'm not sure what you want to do. Do you want to emit the sound from all players? In which case, a simple loop of player.GetAll(). If you want to play it on a specific player, just get the player from their ID that you've saved somewhere (or better yet, just save the reference to the player)[/QUOTE] I want to play the sound from a specific player not through player.GetByID(), but from the local player. Problem is, if I emit the sound clientside, others can't hear it.
Having trouble understanding what you want, but look into [url]http://wiki.garrysmod.com/page/sound/Play[/url]
[QUOTE=smithy285;47845609]Having trouble understanding what you want, but look into [url]http://wiki.garrysmod.com/page/sound/Play[/url][/QUOTE] Oh! sound.Play should work perfectly. If you have trouble understanding what I need, I basically want to emit a sound from the local player(which can only be done clientside), but I want the sound to be heard by all players.(because EmitSound, if used clientside, can only be heard locally)
[QUOTE=A Fghtr Pilot;47845608]I want to play the sound from a specific player not through player.GetByID(), but from the local player. Problem is, if I emit the sound clientside, others can't hear it.[/QUOTE] There is no "local player" serverside. And why don't you want to use player.GetByID()?
[QUOTE=James xX;47845613]There is no "local player" serverside. And why don't you want to use player.GetByID()?[/QUOTE] Well, would it be possible to create a table of players serverside using player.GetAll() then select one to play a sound?
[CODE]local threshold = 10.0 local _lastFired = 0 hook.Add("Think", "SomeName", function() for _, ply in pairs(player.GetAll()) do if CurTime() - _lastFired >= threshold then _lastFired = CurTime() ply:EmitSound( table.Random( combrand ), 75, 100 ) end end end)[/CODE] There you go. Maybe it won't do exactly as you want. You probably should have threshold and _lastFired assigned to the players.
Wait, could I use PlayerTick instead of Think? That has an argument for players.
Try it
Sorry, you need to Log In to post a reply to this thread.