Welcome sound/message

Hi, so i’m new at lua, and i’m trying to make a Welcome sound/message, but it doesn’t work.



function FirstSpawn( ply )
    surface.PlaySound ( "Blabla2.wav" )
    ply:PrintMessage(HUD_PRINTCENTER,"Blabla")
end
hook.Add( "PlayerInitialSpawn", FirstSpawn )

resource.AddSingleFile( "Blabla2.wav" )


you don’t have to make a ressource.Addfile for a lua script, use AddCSLuaFile() for the clientside scripts, nothing for the serverside one.
Also, you need to set an uniqueid to your hook like:
hook.Add( “PlayerInitialSpawn”, “welcommemessage”, FirstSpawn ).

resource.AddSingleFile is for the sound (That’s why his name is Blabla2)

You know, reading the little blue error that pops up when you spawn would have helped you a bit.
You need to know the difference between the server and the client, and how they are both different machines that run at the same time and interact with each other via various means known as console commands, usermessages, networked vars, and datatables.

PlayerInitialSpawn is purely serverside, and since surface.PlaySound is purely clientside, you need the player who just spawned to play it in such a way that no other player will hear it.

This is what people consider the “noob way” of doing it, but it does the job well, and is not exploitable as long as you use it properly.

[lua]function FirstSpawn( ply )
ply:SendLua(“surface.PlaySound ( ‘sound/Blabla2.wav’ )”)
ply:PrintMessage(HUD_PRINTCENTER,“Blabla”)
end
hook.Add( “PlayerInitialSpawn”, “DoWelcomeSound”, FirstSpawn )

resource.AddSingleFile( “sound/Blabla2.wav” )[/lua]

SendLua sends some Lua code to a player and makes them execute it clientside. You should use it ONLY for short pieces of code like this one. If you want to run longer code on a client, you should consider using usermessages (http://wiki.garrysmod.com/?title=Usermessages). It’s a little bit hard to understand at first but if you keep practicing, it’s easy as piss.

Also, make sure the path to your sound is correct. Sounds are usually placed in the sound folder.

Ah, bah tiens, Kilburn,sa fais longtemps que je ne t’ai pas adressé la parole. Non c’est bon j’ai trouvé une alternative
(i’ve found a solution)


function FirstSpawn( ply )
    ply:ConCommand("play sound.wav")
    ply:PrintMessage(HUD_PRINTCENTER,"Message")
end
hook.Add( "PlayerInitialSpawn", "bienvenue", FirstSpawn )

resource.AddSingleFile( "sound/sound.wav" )


you do know the solution _Kilburn posted works…

Of course

I’d like to point out that the player is still loading at the time PlayerInitialSpawn is executed. You want to make sure the player can see the game screen, for which I will refer you to Line 659 of http://code.google.com/p/exsto/source/browse/trunk/lua/exsto/sh_access.lua

Hm, no i don’t have that problem, the sound loads a few seconds after the game screen.