Skip to content
Merged
Show file tree
Hide file tree
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
Binary file modified addons/sourcemod/plugins/optional/autopause.smx
Binary file not shown.
93 changes: 41 additions & 52 deletions addons/sourcemod/scripting/autopause.sp
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ char sDebugMessage[256];
public Plugin myinfo =
{
name = "L4D2 Auto-pause",
author = "Darkid, Griffin, StarterX4",
author = "Darkid, Griffin, StarterX4, Forgetest, J.",
description = "When a player disconnects due to crash, automatically pause the game. When they rejoin, give them a correct spawn timer.",
version = "2.2",
version = "2.3",
url = "https://github.com/SirPlease/L4D2-Competitive-Rework"
}

Expand All @@ -49,11 +49,10 @@ ConVar
convarForceUnpause,
convarDebug;

Handle
StringMap
crashedPlayers,
generalCrashers,
infectedPlayers,
survivorPlayers;
teamPlayers;

bool
bReadyUpIsAvailable,
Expand All @@ -67,10 +66,9 @@ public void OnPluginStart()
convarForceUnpause = CreateConVar("autopause_forceunpause", "0", "Whether or not we force unpause when the crashed players have loaded back in");
convarDebug = CreateConVar("autopause_apdebug", "0", "0: No Debugging - 1: Sourcemod Logs - 2: PrintToChat - 3: Both", _, true, 0.0, true, 3.0);

crashedPlayers = CreateTrie();
generalCrashers = CreateArray(64);
infectedPlayers = CreateArray(64);
survivorPlayers = CreateArray(64);
crashedPlayers = new StringMap();
generalCrashers = new StringMap();
teamPlayers = new StringMap();

HookEvent("round_start", Event_RoundStart);
HookEvent("round_end", Event_RoundEnd);
Expand Down Expand Up @@ -112,13 +110,11 @@ public void OnClientPutInServer(int client)
if (strcmp(sAuthId, "BOT") == 0)
return;

int crasherIndex = FindStringInArray(generalCrashers, sAuthId);

if (crasherIndex == -1)
if (!generalCrashers.ContainsKey(sAuthId))
return;

RemoveFromArray(generalCrashers, crasherIndex);
int remainingCrashers = GetArraySize(generalCrashers);
generalCrashers.Remove(sAuthId);
int remainingCrashers = generalCrashers.Size;

if (convarDebug.BoolValue)
{
Expand Down Expand Up @@ -148,12 +144,19 @@ public void OnClientPutInServer(int client)
}
}

public void OnMapEnd()
{
teamPlayers.Clear();
}

void Event_RoundStart(Event hEvent, char[] sEventName, bool dontBroadcast)
{
ClearTrie(crashedPlayers);
ClearArray(generalCrashers);
ClearArray(infectedPlayers);
ClearArray(survivorPlayers);
crashedPlayers.Clear();
generalCrashers.Clear();

// @Forgetest: "player_team" happens before "round_start"
// teamPlayers.Clear();

bRoundEnd = false;
}

Expand All @@ -175,36 +178,11 @@ void Event_PlayerTeam(Event hEvent, char[] sEventName, bool dontBroadcast)
if (strcmp(sAuthId, "BOT") == 0)
return;

int survivorIndex = FindStringInArray(survivorPlayers, sAuthId);
int infectedIndex = FindStringInArray(infectedPlayers, sAuthId);

if (survivorIndex != -1)
{
RemoveFromArray(survivorPlayers, survivorIndex);

if (convarDebug.BoolValue)
{
Format(sDebugMessage, sizeof(sDebugMessage), "[AutoPause (%s)] Removed player %s from the survivor team.", sEventName, sAuthId);
DebugLog(sDebugMessage);
}
}

if (infectedIndex != -1)
{
RemoveFromArray(infectedPlayers, infectedIndex);

if (convarDebug.BoolValue)
{
Format(sDebugMessage, sizeof(sDebugMessage), "[AutoPause (%s)] Removed player %s from the infected team.", sEventName, sAuthId);
DebugLog(sDebugMessage);
}
}

int newTeam = hEvent.GetInt("team");

if (newTeam == L4D_TEAM_SURVIVOR)
{
PushArrayString(survivorPlayers, sAuthId);
teamPlayers.SetValue(sAuthId, newTeam);

if (convarDebug.BoolValue)
{
Expand All @@ -216,11 +194,11 @@ void Event_PlayerTeam(Event hEvent, char[] sEventName, bool dontBroadcast)
{
float fSpawnTime;

if (GetTrieValue(crashedPlayers, sAuthId, fSpawnTime))
if (crashedPlayers.GetValue(sAuthId, fSpawnTime))
{
CountdownTimer CTimer_SpawnTimer = L4D2Direct_GetSpawnTimer(client);
CTimer_Start(CTimer_SpawnTimer, fSpawnTime);
RemoveFromTrie(crashedPlayers, sAuthId);
crashedPlayers.Remove(sAuthId);

if (convarDebug.BoolValue)
{
Expand All @@ -229,14 +207,24 @@ void Event_PlayerTeam(Event hEvent, char[] sEventName, bool dontBroadcast)
}
}

PushArrayString(infectedPlayers, sAuthId);
teamPlayers.SetValue(sAuthId, newTeam);

if (convarDebug.BoolValue)
{
Format(sDebugMessage, sizeof(sDebugMessage), "[AutoPause (%s)] Added player %s to the infected team.", sEventName, sAuthId);
DebugLog(sDebugMessage);
}
}
else if (teamPlayers.GetValue(sAuthId, newTeam))
{
teamPlayers.Remove(sAuthId);

if (convarDebug.BoolValue)
{
Format(sDebugMessage, sizeof(sDebugMessage), "[AutoPause (%s)] Removed player %s from the %s team.", sEventName, sAuthId, newTeam == L4D_TEAM_SURVIVOR ? "survivor" : "infected");
DebugLog(sDebugMessage);
}
}
}

void Event_PlayerDisconnect(Event hEvent, char[] sEventName, bool dontBroadcast)
Expand All @@ -252,7 +240,7 @@ void Event_PlayerDisconnect(Event hEvent, char[] sEventName, bool dontBroadcast)
if (strcmp(sAuthId, "BOT") == 0)
return;

if (FindStringInArray(infectedPlayers, sAuthId) == -1 && FindStringInArray(survivorPlayers, sAuthId) == -1)
if (!teamPlayers.ContainsKey(sAuthId))
return;

if (GetClientTeam(client) == L4D_TEAM_SURVIVOR && !IsPlayerAlive(client))
Expand Down Expand Up @@ -286,14 +274,15 @@ void Event_PlayerDisconnect(Event hEvent, char[] sEventName, bool dontBroadcast)
else
FakeClientCommand(client, "sm_pause");

if (FindStringInArray(generalCrashers, sAuthId) == -1)
PushArrayString(generalCrashers, sAuthId);
if (!generalCrashers.ContainsKey(sAuthId))
generalCrashers.SetValue(sAuthId, true);

CPrintToChatAll("%t", "Crashed", client);
}
}

if (FindStringInArray(infectedPlayers, sAuthId) != -1)
int team;
if (teamPlayers.GetValue(sAuthId, team) && team == L4D_TEAM_INFECTED)
{
CountdownTimer CTimer_SpawnTimer = L4D2Direct_GetSpawnTimer(client);
if (CTimer_SpawnTimer != CTimer_Null)
Expand All @@ -306,7 +295,7 @@ void Event_PlayerDisconnect(Event hEvent, char[] sEventName, bool dontBroadcast)
DebugLog(sDebugMessage);
}

SetTrieValue(crashedPlayers, sAuthId, fTimeLeft);
crashedPlayers.SetValue(sAuthId, fTimeLeft);
}
}
}
Expand Down