Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 35 additions & 4 deletions addons/sourcemod/scripting/TeamManager.sp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
GlobalForward g_hWarmupEndFwd;
Handle g_hWarmupTimer = null;

ConVar g_cvWarmup, g_cvWarmuptime, g_cvWarmupMaxTime, g_cvWarmupWaitingCenterText, g_cvWarmupCountdownCenterText, g_cvForceTeam, g_cvPlayersRatio, g_cvCleanOnWarmupEnd, g_cvAliveTeamChange;
ConVar g_cvWarmup, g_cvWarmuptime, g_cvWarmupMaxTime, g_cvWarmupWaitingCenterText, g_cvWarmupCountdownCenterText, g_cvForceTeam, g_cvPlayersRatio, g_cvExcludeSpectators, g_cvCleanOnWarmupEnd, g_cvAliveTeamChange;
ConVar g_cvDynamic, g_cvDynamicRatio, g_cvDynamicTime;

bool g_bWarmup = false;
Expand All @@ -35,7 +35,7 @@ public Plugin myinfo =
name = "TeamManager",
author = "BotoX + maxime1907, .Rushaway",
description = "Adds a warmup round, makes every human a ct and every zombie a t",
version = "2.3.5",
version = "2.3.6",
url = "https://github.com/srcdslab/sm-plugin-TeamManager"
};

Expand Down Expand Up @@ -67,6 +67,7 @@ public void OnPluginStart()
g_cvWarmupCountdownCenterText = CreateConVar("sm_warmup_centertext_countdown", "1", "Display the warmup countdown message in center text", 0, true, 0.0, true, 1.0);
g_cvForceTeam = CreateConVar("sm_warmupteam", "1", "Force the player to join the counterterrorist team", 0, true, 0.0, true, 1.0);
g_cvPlayersRatio = CreateConVar("sm_warmupratio", "0.60", "Ratio of connected players that need to be in game to start warmup timer.", 0, true, 0.0, true, 1.0);
g_cvExcludeSpectators = CreateConVar("sm_teammanager_warmup_exclude_spectators", "0", "Exclude spectators from warmup player counts. [0 = Disabled | 1 = Enabled]", 0, true, 0.0, true, 1.0);
g_cvCleanOnWarmupEnd = CreateConVar("sm_warmup_slay", "0", "Slay all players at the end of the warmup round. [0 = Disabled | 1 = Enabled | 2 = Enabled + Clean temporary entities]", 0, true, 0.0, true, 2.0);
g_cvAliveTeamChange = CreateConVar("sm_teammanager_aliveteamchange", "1", "Determines if players are allowed to change teams while they're alive. [0 = Dissalow | 1 = Allow]", 0, true, 0.0, true, 1.0);

Expand Down Expand Up @@ -202,8 +203,8 @@ public Action OnWarmupTimer(Handle timer)

if (g_cvPlayersRatio.FloatValue > 0.0)
{
int ClientsConnected = GetClientCount(false);
int ClientsInGame = GetClientCount(true);
int ClientsConnected, ClientsInGame;
GetWarmupPlayerCounts(ClientsConnected, ClientsInGame);
int ClientsNeeded = RoundToCeil(float(ClientsConnected) * g_cvPlayersRatio.FloatValue);
ClientsNeeded = ClientsNeeded > MIN_PLAYERS ? ClientsNeeded : MIN_PLAYERS;

Expand Down Expand Up @@ -237,6 +238,36 @@ public Action OnWarmupTimer(Handle timer)
return Plugin_Continue;
}

stock void GetWarmupPlayerCounts(int &ClientsConnected, int &ClientsInGame)
{
ClientsConnected = 0;
ClientsInGame = 0;

bool excludeSpectators = g_cvExcludeSpectators.BoolValue;

for (int client = 1; client <= MaxClients; client++)
{
if (!IsClientConnected(client) || IsClientSourceTV(client))
{
continue;
}

bool inGame = IsClientInGame(client);

if (excludeSpectators && inGame && GetClientTeam(client) == CS_TEAM_SPECTATOR)
{
continue;
}

ClientsConnected++;

if (inGame)
{
ClientsInGame++;
}
}
}

stock void EndWarmUp()
{
g_iWarmup = 0;
Expand Down
Loading