General > Developers Corner

Music Intro to server help

(1/2) > >>

joe c-j:
Hi I'm a noob Lua scripter so was wondering if anyone would help me. What i would like on my server is to have it play a music file whenever someone new joins. If someone could post a lua script and location to put it so my server would do that i would be most grateful. And if there is another way to do that could you post that as well. Thanks in anticipation.

jay209015:
Not tested, but should work. Save as something.lua, and place it in your <server>/garrysmod/lua/autorun directory.


--- Code: ---OnJoinSound = "music/hl2_song20_submix0.mp3" // Sound file relative to the sound directory
function PlaySoundOnJoin(ply)
for k,v in pairs(player.GetAll()) do
v:SendLua("surface.PlaySound(\"OnJoinSound\"");
end
end
hook.Add("PlayerInitialSpawn", "PlaySoundOnJoinHook", PlaySoundOnJoin)
--- End code ---

Enjoy!

Megiddo:
"whenever someone new joins". What do you mean by that?

jay209015:
Yeah I thought about that too when writing this scripts.
By "new" do you mean:
     -First time a specifc player has joined the server ever?
     -Or just whenever a player joins the server regardless if they've been there before?

JamminR:
Also, did he mean it to play to all players, or just the one joining?
If I'm joining a server and have to hear music playing, annoying, but, once when joining ok.
Everytime any other player joins? Yuck.

Navigation

[0] Message Index

[#] Next page

Go to full version