how do i make it so that when as player presses a button it emits a sound for everyone?
hook.Add( "KeyPress", "keypress_use_hi", function(ply, key )
if ( key == IN_ATTACK2 ) then
Entity(ply):EmitSound("items/ammo_pickup.wav")
end
end )
currently im the only person it works for (only when i do it everyone can hear it)
and how can i define another key instead of attack2 (i want to use a key that isnt already in use)
It looks like that code should work for everyone if you put it in a serverside file.
Also, ply is already an entity, so Entity(ply) is not needed.
i have that code in if SERVER then
Throw some print statements around. Print out ply and key before you run your if statement. What do they return? Are they even printing?
i managed to fix the issue for anyone following this the solution was the following code
if SERVER then util.AddNetworkString("stringname")
net.Receive("stringname",function(len,ply)
ply:EmitSOund("items/ammo_pickup.wav")
end)
end
if CLIENT then
hook.Add( "KeyPress", "keypress_use_hi", function(ply, key )
if ( key == IN_ATTACK2 ) then
net.Start("stringname")
net.SendToServer()
end
end )
That code would throw out an error, since you are using a capital O in ply:EmitSOund
i just quickly manually typed it here thanks for pointing it out
What's the point in having the client send a net message, when we already have a perfectly working and capable function to hook off of?
Im confused sorry still new to lua can you show how you would have done it?
What OP has should already work. There's nothing wrong with it, from what I can tell, so using net messages aren't needed. KeyPress is both a client and a server function.
the reason i used the net messages was because the not all clients were hearing the emit
Why make it so complicated?
EmitSound will only play for the entity supplied (in your case, the person who pressed it). You need to run through every player, preferrably not EmitSound. You can broadcast a surface.PlaySound to all players.
hook.Add( "KeyPress", "keypress_use_taunt1", function( ply, key )
if ( key == IN_ATTACK2 ) then
ply:EmitSound("items/ammo_pickup.wav")
end
end )
Sorry, you need to Log In to post a reply to this thread.