Teams!

ok been working on code again and ive hit a brick wall, as only team 3 will work on my server - its probably a nooby thing but heres the code for the teams



function GM:PlayerSay( pl, text, teamonly )
	
	if ( text == "!team 1" ) then
		pl:PrintMessage(HUD_PRINTCENTER, "Joined Team 1")
		pl:SetTeam(6)
	return "" end
	
	return self.BaseClass:PlayerSay( pl, text, teamonly )
	
end

function GM:PlayerSay( pl, text, teamonly )
	
	if ( text == "!team 2" ) then
		pl:PrintMessage(HUD_PRINTCENTER, "Joined Team 2")
		pl:SetTeam(7)
	return "" end
	
	return self.BaseClass:PlayerSay( pl, text, teamonly )
	
end

function GM:PlayerSay( pl, text, teamonly )
	
	if ( text == "!team 3" ) then
		pl:PrintMessage(HUD_PRINTCENTER, "Joined Team 3")
		pl:SetTeam(8)
	return "" end
	
	return self.BaseClass:PlayerSay( pl, text, teamonly )
	
end


is there a better way to do this / have i done something wrong? as players can only join team 3 and none of the others.



local TeamNumbers = {6, 7, 8}
function GM:PlayerSay(ply, txt)
	local text = string.lower(txt)
	if string.sub(text, 1, 6) == "!team " then
		local number = tonumber(string.sub(text, 7,8))
		if number <= #TeamNumbers then
			ply:PrintMessage(HUD_PRINTCENTER, "Joined Team "..number)
			ply:SetTeam(TeamNumbers[number])
			return ""
		end
	end
end


This should work

Thanks! it worked, now i can continue :stuck_out_tongue:

No problem :slight_smile: