Ulysses

General => Developers Corner => Topic started by: joe c-j on August 16, 2008, 11:03:25 AM

Title: Music Intro to server help
Post by: joe c-j on August 16, 2008, 11:03:25 AM
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.
Title: Re: Music Intro to server help
Post by: jay209015 on August 16, 2008, 02:03:36 PM
Not tested, but should work. Save as something.lua, and place it in your <server>/garrysmod/lua/autorun directory.

Code: [Select]
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)

Enjoy!
Title: Re: Music Intro to server help
Post by: Megiddo on August 16, 2008, 03:48:20 PM
"whenever someone new joins". What do you mean by that?
Title: Re: Music Intro to server help
Post by: jay209015 on August 16, 2008, 09:17:02 PM
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?
Title: Re: Music Intro to server help
Post by: JamminR on August 16, 2008, 09:49:20 PM
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.
Title: Re: Music Intro to server help
Post by: joe c-j on August 17, 2008, 05:46:55 PM
sorry for not being specific enough and thanks for your help so far...to answer your questions i was hoping that it would play just to the user joining the server and only the first time they join the server
where i can insert my own mp3 file my changing the name and file location could you highlight that on the script please
thank you
Title: Re: Music Intro to server help
Post by: sparky2002b on August 21, 2008, 01:38:59 PM
The clients connecting to you would have to already have the MP3 in their sound directory, so, if you change it to some custom MP3, and aren't 100% sure they'll download the file, they won't hear the music anyway.

As for the first-time-only deal...maybe handle that by UniqueID?