OK, I tried Kyzer's method.
I updated my UTeam.lua to this:
if not SERVER then return end
UTeam = {}
UTeam.BASETEAMINDEX = 20
UTeam.CONFIG = "UTeam.txt"
if not file.Exists( UTeam.CONFIG ) then
Msg( "[UTeam Error] UTeam config file missing.\n" )
return
end
local t = util.KeyValuesToTable( file.Read( UTeam.CONFIG ) )
if not t.teams then
Msg( "[UTeam Error] UTeam config teams table missing.\n" )
return
end
UTeam.teams = {}
for k,v in pairs( t.teams ) do
UTeam.teams[tonumber(k)]=v
end
if not t.gamemodes then
Msg( "[UTeam Error] UTeam config gamemodes table missing.\n" )
return
end
UTeam.gamemodes = t.gamemodes
function UTeam.checkGamemode()
for _,v in pairs( UTeam.gamemodes ) do
if string.lower(GAMEMODE.Name) == string.lower(v) then return true end
end
hook.Remove( "PlayerSpawn", "UTeamSetTeam" )
hook.Remove( "PlayerInitialSpawn", "UTeamSetupTeams" )
return false
end
function UTeam.setTeam( ply )
if not UTeam.checkGamemode() then return end
for k,v in ipairs( UTeam.teams ) do
if ply:IsUserGroup( v.group ) then
ply:SetTeam( UTeam.BASETEAMINDEX + k )
if v.hp then ply:SetHealth( v.hp ) end
if v.armor then ply:SetArmor( v.armor ) end
if v.model then timer.Simple( 0.1, ply.SetModel, ply, player_manager.TranslatePlayerModel( v.model ) )end
if v.weapons then
timer.Simple( 0.1, function(ply, v)
ply:StripWeapons()
for _,v in pairs(v.weapons) do
ply:Give( v )
end
ply:SelectWeapon(v.weapons[1])
end, ply, v)
end
if v.plytable then
timer.Simple( 0.1, function(ply, v)
for _,v in pairs(v.plytable) do
k = string.sub( v, 1, string.find( v, ":" ) - 1 )
v = string.sub( v, string.find( v, ":" ) + 1 )
ply:GetTable()[k] = tonumber(v) or v
end
end, ply, v)
end
break
end
end
end
hook.Add( "PlayerSpawn", "UTeamSetTeam", UTeam.setTeam )
function UTeam.setupTeams( ply )
if not UTeam.checkGamemode() then return end
for k,v in ipairs( UTeam.teams ) do
team.SetUp( UTeam.BASETEAMINDEX + k, v.name, v.color )
ply:SendLua( "team.SetUp(" .. UTeam.BASETEAMINDEX + k .. ",\"" .. v.name .. "\",Color(" .. v.color.r .. "," .. v.color.g .. "," .. v.color.b .. "," ..
v.color.a .. "))" )
end
end
hook.Add( "PlayerInitialSpawn", "UTeamSetupTeams", UTeam.setupTeams )
I updated my UTeam.txt to this:
"Out"
{
"teams"
{
"1"
{
"name" "Owner"
"group" "superadmin"
"armor" "1000"
"hp" "1000"
"color"
{
"a" "255"
"B" "85"
"g" "200"
"r" "0"
}
"weapons"
{
"1" "weapon_physgun"
"2" "gmod_tool"
"3" "gmod_camera"
"4" "weapon_ar2"
}
"plytable"
{
"1" "SprintSpeed:2000"
"2" "WalkSpeed:1000"
}
}
"2"
{
"name" "Respected"
"group" "admin"
"armor" "200"
"hp" "200"
"color"
{
"a" "255"
"B" "50"
"g" "199"
"r" "255"
}
}
"3"
{
"name" "Regular"
"group" "regular"
"armor" "5"
"hp" "110"
"color"
{
"a" "255"
"B" "252"
"g" "15"
"r" "51"
}
}
"4"
{
"name" "Police"
"group" "operator"
"armor" "15"
"hp" "125"
"color"
{
"a" "255"
"B" "204"
"g" "255"
"r" "204"
}
}
"5"
{
"name" "Players"
"group" "user"
"color"
{
"a" "255"
"B" "255"
"g" "100"
"r" "0"
}
"model" "male1"
}
}
"gamemodes"
{
"1" "Sandbox"
"2" "SpaceBuild"
}
}
But everyone in the game shows as "Unassigned", and the loadouts don't work.
Did I put the code in right?