Gamemode Spawn

I’m trying to set my team and then get a physgun, for some reason its not working, no errors whatsoever.

[lua]
function GM:PlayerInitialSpawn( ply )
if(team.NumPlayers( 1 ) <= team.NumPlayers( 2 )) then
ply:SetTeam(1)
else
ply:SetTeam(2)
end
end

function GM:PlayerLoadout(ply)

ply:StripWeapons()

if ply:Team() == 1 then
	ply:Give("weapon_physgun")

elseif ply:Team() == 2 then
	ply:Give("weapon_physgun")
end

end
[/lua]

You don’t need to strip weapons at loadout.

Also, are you sure that PlayerLoadout is being called? Paste your PlayerSpawn-function?

No PlayerSpawn code yet, though its derived from sandbox so PlayerLoadout should be called ?

Yeah, it should… That’s really weird.

If you are going to use PlayerSpawn then just add it there.
I think this will work.

serverside
[lua]
function GM:PlayerInitialSpawn( ply )

if team.NumPlayers( 1 ) not &gt; team.NumPlayers( 2 ) then

	ply:SetTeam(1)

else

	ply:SetTeam(2)

end

end

function GM:PlayerSpawn( ply )

-- Other Stuff

local team = ply:Team()

if team == 1 then

	ply:Give("weapon_physgun")

elseif team == 2 then

	ply:Give("weapon_physgun")

end

end
[/lua]

shared
[lua]
team.SetUp( 1, “1”, Color( 255, 255, 255, 255 ) )
team.SetUp( 2, “2”, Color( 0, 0, 0, 255 ) )
[/lua]

No don’t, the Loadout hook was created for a reason, to decouple the spawning logic from the loadout logic so they can be overridden separately.

I used my own code, and changed the loadout part into the spawn part, it fixed it but it is still strange, I also noticed that if I didn’ t overide the playerspawn method it gave me a error.

There’s a fix for that error that still does what PlayerSpawn should:
[lua]
function GM:PlayerSpawn( ply )

-- Some versions add some team-based stuff here but I don't think you'll need it
-- Otherwise see http://www.facepunch.com/showpost.php?p=20771864&postcount=6

ply:UnSpectate()

hook.Call( "PlayerLoadout", GAMEMODE, ply )
hook.Call( "PlayerSetModel", GAMEMODE, ply )

-- Optionally set player speed here... Otherwise you'll get different speeds from sandbox, I think.
GAMEMODE:SetPlayerSpeed( ply, 250, 500 )

end[/lua]

[editline]08:12PM[/editline]

Ignore the url-tags in the lua box, couldn’t get rid of them >.<