TeamManager: add max timer

This commit is contained in:
Dogan 2018-12-25 17:47:39 +01:00
parent 27ae71dd4e
commit 6e36e86b44

View File

@ -7,9 +7,11 @@
#define MIN_PLAYERS 2
int g_iWarmup = 0;
int g_iMaxWarmup = 0;
bool g_bWarmup = false;
ConVar g_CVar_sm_warmuptime;
ConVar g_CVar_sm_warmupratio;
ConVar g_CVar_sm_warmupmaxtime;
bool g_bRoundEnded = false;
bool g_bZombieSpawned = false;
@ -35,6 +37,7 @@ public void OnPluginStart()
g_CVar_sm_warmuptime = CreateConVar("sm_warmuptime", "10", "Warmup timer.", 0, true, 0.0, true, 60.0);
g_CVar_sm_warmupratio = 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_CVar_sm_warmupmaxtime = CreateConVar("sm_warmupmaxtime", "45", "Max Warmup timer.", 0, true, 0.0, true, 120.0);
AutoExecConfig(true, "plugin.TeamManager");
}
@ -55,19 +58,12 @@ public void OnMapStart()
public Action OnWarmupTimer(Handle timer)
{
if(g_CVar_sm_warmupratio.FloatValue > 0.0)
if(g_iMaxWarmup >= g_CVar_sm_warmupmaxtime.IntValue)
{
int ClientsConnected = GetClientCount(false);
int ClientsInGame = GetClientCount(true);
int ClientsNeeded = RoundToCeil(float(ClientsConnected) * g_CVar_sm_warmupratio.FloatValue);
ClientsNeeded = ClientsNeeded > MIN_PLAYERS ? ClientsNeeded : MIN_PLAYERS;
if(ClientsInGame < ClientsNeeded)
{
g_iWarmup = 0;
PrintCenterTextAll("Warmup: Waiting for %d more players to join.", ClientsNeeded - ClientsInGame);
return Plugin_Continue;
}
g_iMaxWarmup = 0;
g_bWarmup = false;
CS_TerminateRound(3.0, CSRoundEnd_GameStart, false);
return Plugin_Stop;
}
if(g_iWarmup >= g_CVar_sm_warmuptime.IntValue)
@ -78,8 +74,27 @@ public Action OnWarmupTimer(Handle timer)
return Plugin_Stop;
}
PrintCenterTextAll("Warmup: %d", g_CVar_sm_warmuptime.IntValue - g_iWarmup);
if(g_CVar_sm_warmupratio.FloatValue > 0.0)
{
int ClientsConnected = GetClientCount(false);
int ClientsInGame = GetClientCount(true);
int ClientsNeeded = RoundToCeil(float(ClientsConnected) * g_CVar_sm_warmupratio.FloatValue);
ClientsNeeded = ClientsNeeded > MIN_PLAYERS ? ClientsNeeded : MIN_PLAYERS;
if(ClientsInGame < ClientsNeeded)
{
g_iWarmup = 0;
g_iMaxWarmup++;
PrintCenterTextAll("Warmup: Waiting for %d more players to join or %d seconds.", ClientsNeeded - ClientsInGame, g_CVar_sm_warmupmaxtime.IntValue - g_iMaxWarmup);
return Plugin_Continue;
}
else if(ClientsInGame >= ClientsNeeded)
{
g_iWarmup++;
PrintCenterTextAll("Warmup: Enough players joined. %d seconds left. ", g_CVar_sm_warmuptime.IntValue - g_iWarmup);
return Plugin_Continue;
}
}
return Plugin_Continue;
}