How to get Entity:EmitSound to work on newly connected players(serverside)
2 replies, posted
I have an entity which plays a song at the start of the server. My plan is to make a loop out of this or something. However, a problem is that newly connected players are not able to heard it. I know that it works when the entity is just spawned and the player is in the server. I want it to be played server side. Is there any way around this?
Entity
init.lua
sound.Add( {
name = "my_soul_your_beats",
channel = CHAN_AUTO,
volume = 1.0,
level = 80,
pitch = { 95, 110 },
sound = "mysoulyourbeats.wav"
} )
function ENT:Initialize()
self:SetModel( "models/Combine_Helicopter/helicopter_bomb01.mdl" )
self:PhysicsInit( SOLID_VPHYSICS )
self:SetMoveType( MOVETYPE_FLY )
self:SetSolid( SOLID_VPHYSICS )
self:EmitSound( "my_soul_your_beats" )
local phys = self:GetPhysicsObject()
if phys:IsValid() then
phys:Wake()
end
end
If i'm understanding you right, the way you are doing it is very weird and ghetto
I think this should work? if not this would be the right direction to go (I haven't tested)
sound.Add( {
name = "my_soul_your_beats",
channel = CHAN_AUTO,
volume = 1.0,
level = 80,
pitch = { 95, 110 },
sound = "mysoulyourbeats.wav"
} )
hook.Add("PlayerSpawn", "playSong1OnJoin", function(ply)
print(ply)
if (CLIENT) then
ply:EmitSound( "my_soul_your_beats", 80, 100, 1, CHAN_AUTO )
end
end)
I want the song to play on the entity on the server side. This way when the player walk towards it, then it gets louder. I only want players within its proximity to hear it. Your code plays it client side.
Sorry, you need to Log In to post a reply to this thread.