Noob here: Weapon on spawn.

I’m new to Garry’s Mod, and I already have a server up and running. I run horror, and I need a good gamemode for that. I need it to where when people spawn in my server, they automatically spawn with a crowbar, and every time they die, and repawn, they get a crowbar again.

\

You’d use the PlayerSpawn hook to call the Player:Give command on spawn.

[editline]20th January 2013[/editline]

So, for example:



function GM:PlayerSpawn(ply)
    ply:Give("weapon_crowbar")
end

but where would I put this code?.. what file

You’d put it in init.lua

It worked when i spawned in. When I died, I did not respawn with one. Also my friend joined and did not spawn with one. Please help

I use this code on my gamemode, and no problem…

[lua]function GM:PlayerSpawn( ply )
ply:Give(“weapon_crowbar”)
ply:Give(“weapon_pistol”)
ply:Give(“weapon_…”)
end[/lua]

Check your console if you have an error.

It may be better to have a hook, instead of overwriting the functionality of PlayerSpawn in his gamemode all together.

Another example that will work.


hook.Add("PlayerSpawn", "Horror_LoadOut", function(Player)
	Player:Give("weapon_crowbar")
end)