Feature Addition

Anyone know if I can add a simple function to my gmod?

It takes me a pretty damn long time to load into singleplayer and/or multiplayer. It takes so long that I usually go do something else while gmod is loading.

I want it to play a sound for me when I’m done loading, like a function that hooks to GM.PlayerInitialSpawn() or something.

I want everything to be totally clientside though, so it will still work if I’m joining a server and it won’t be heard by anyone else.

I’m sure the script is simple, but I don’t know where it would go. Gamemodes/sandbox? Addon/lua/autorun? What should it go in? cl_init?

Also, could someone provide an example script for this? Thanks in advance.

well, here
this would go in
lua/autorun/client
[lua]
function PlaySound(ply)
ply:EmitSound(“achievement_earned.mp3”)
ply:ChatPrint(ply:Nick()…" has spawned!")
end

hook.Add( “PlayerInitialSpawn”, “playerInitialSpawn”, PlaySound )
[/lua]

I’ll break it down for you



function PlaySound(ply)     Ply is an argument
                            that applies to the player who calls
                            the function
ply:EmitSound("achievement_earned.mp3") the player Emits the  
                                        sound
ply:ChatPrint(ply:Nick().." has spawned!") the player has spawned
end
           Event hook             unique name     function called
hook.Add( "PlayerInitialSpawn", "playerInitialSpawn", PlaySound )


I put this in a new addon and loaded up singleplayer. It didn’t work.
[lua]
if SERVER then
AddCSLuaFile( “cl_sound.lua” )
return
end

function PlaySound(ply)
ply:EmitSound(“yeah.mp3”,300,100)
end

hook.Add( “PlayerInitialSpawn”, “playerInitialSpawn”, PlaySound
[/lua]

Any idea what I did wrong?

:l

It works now, thank you.