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
function PlaySound(ply)
ply:ChatPrint(ply:Nick()…" has spawned!")

hook.Add( “PlayerInitialSpawn”, “playerInitialSpawn”, PlaySound )

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  
ply:ChatPrint(ply:Nick().." has spawned!") the player has spawned
           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.
if SERVER then
AddCSLuaFile( “cl_sound.lua” )

function PlaySound(ply)

hook.Add( “PlayerInitialSpawn”, “playerInitialSpawn”, PlaySound

Any idea what I did wrong?


It works now, thank you.