Benny/gamemodes/benny/gamemode/teams.lua

161 lines
3.6 KiB
Lua
Raw Permalink Normal View History

concommand.Add("b-cheat_setteam", function( ply, cmd, args )
if !ply or !ply:IsValid() then return end
if !args[1] then
print( "Needs an integer." )
for index, data in ipairs( TEAMS ) do
print( index .. " - " .. data.id )
end
else
ply:SetTeam( TEAMS_IDorName( tonumber(args[1]) or args[1] ) )
end
2024-09-16 00:26:04 -04:00
end, function( cmd, args )
return BENNY.SimpleAutoComplete( cmd, args, TEAMS_IDs )
end )
TEAMS = {
[0] = {
name = "unassigned",
description = "unassigned",
factionid = "unassigned",
id = "UNASSIGNED",
},
{
name = "#Team.cia.Name",
description = "#Team.cia.Description",
factionid = "mp_cia",
id = "CIA",
},
{
name = "#Team.halo.Name",
description = "#Team.halo.Description",
factionid = "mp_halo",
id = "HALO",
},
{
name = "#Team.plasof.Name",
description = "#Team.plasof.Description",
factionid = "mp_plasof",
id = "PLASOF",
},
{
name = "#Team.arng.Name",
description = "#Team.arng.Description",
factionid = "mp_arng",
id = "ARNG",
},
{
name = "#Team.militia.Name",
description = "#Team.militia.Description",
factionid = "mp_militia",
id = "MILITIA",
},
{
name = "#Team.viper.Name",
description = "#Team.viper.Description",
factionid = "mp_viper",
id = "VIPER",
},
{
name = "campaign",
description = "internal campaign faction",
factionid = "campaign",
id = "CAMPAIGN",
},
}
2024-09-16 00:26:04 -04:00
-- "PLASOF" -> Team info
TEAMS_IDtoData = {
[TEAMS[0].id] = TEAMS[0],
[TEAMS[1].id] = TEAMS[1],
[TEAMS[2].id] = TEAMS[2],
[TEAMS[3].id] = TEAMS[3],
[TEAMS[4].id] = TEAMS[4],
[TEAMS[5].id] = TEAMS[5],
[TEAMS[6].id] = TEAMS[6],
}
2024-09-16 00:26:04 -04:00
-- "mp_plasof" -> Team info
TEAMS_FIDtoData = {
[TEAMS[0].factionid] = TEAMS[0],
[TEAMS[1].factionid] = TEAMS[1],
[TEAMS[2].factionid] = TEAMS[2],
[TEAMS[3].factionid] = TEAMS[3],
[TEAMS[4].factionid] = TEAMS[4],
[TEAMS[5].factionid] = TEAMS[5],
[TEAMS[6].factionid] = TEAMS[6],
}
2024-09-16 00:26:04 -04:00
-- 3 -> "PLASOF"
TEAMS_IDs = {
TEAMS[1].id,
TEAMS[2].id,
TEAMS[3].id,
TEAMS[4].id,
TEAMS[5].id,
TEAMS[6].id,
}
2024-09-16 00:26:04 -04:00
-- "PLASOF" -> 3
TEAM_IDs2 = table.Flip( TEAMS_IDs )
function TEAMS_IDorName( id )
if isnumber( id ) then
return id
else
return TEAM_IDs2[string.upper(id)]
end
end
function GM:CreateTeams()
for index, data in ipairs( TEAMS ) do
team.SetUp( index, data.name, Color( 0, 0, 255 ) )
2024-09-16 00:26:04 -04:00
team.SetSpawnPoint( index, {"benny_playerstart_team" .. index} )
end
team.SetSpawnPoint( TEAM_SPECTATOR, "worldspawn" )
end
function GM:PlayerSelectTeamSpawn( TeamID, ply )
local SpawnPoints = team.GetSpawnPoints( TeamID )
if ( !SpawnPoints || table.IsEmpty( SpawnPoints ) ) then return end
local ChosenSpawnPoint = nil
for i = 0, 6 do
ChosenSpawnPoint = table.Random( SpawnPoints )
if ( hook.Call( "IsSpawnpointSuitable", GAMEMODE, ply, ChosenSpawnPoint, i == 6 ) ) then
return ChosenSpawnPoint
end
end
return ChosenSpawnPoint
end
2024-09-16 00:26:04 -04:00
function GM:PlayerSelectSpawn( ply, transition )
if ( transition ) then return end
if BennyGame:GetType() == BG_GTYPE_MP then
local ent = self:PlayerSelectTeamSpawn( ply:Team(), ply )
if IsValid( ent ) then return ent end
2024-09-16 00:26:04 -04:00
end
end
function BennyGame:BestAutoJoinTeam()
2024-09-16 00:26:04 -04:00
local SmallestTeam = BennyGame.TeamsInPlay[math.random( 1, BennyGame.TeamCount )]
local SmallestPlayers = 1000
2024-09-16 00:26:04 -04:00
for TeamID, RealTeamID in ipairs( BennyGame.TeamsInPlay ) do
if ( RealTeamID != TEAM_SPECTATOR && RealTeamID != TEAM_UNASSIGNED && RealTeamID != TEAM_CONNECTING ) then
local PlayerCount = team.NumPlayers( RealTeamID )
if PlayerCount < SmallestPlayers or (PlayerCount == SmallestPlayers and RealTeamID < SmallestTeam ) then
SmallestPlayers = PlayerCount
2024-09-16 00:26:04 -04:00
SmallestTeam = RealTeamID
end
end
end
return SmallestTeam
end