diff --git a/addons/sourcemod/plugins/optional/autopause.smx b/addons/sourcemod/plugins/optional/autopause.smx index 9df0036d4..23a7aaff6 100644 Binary files a/addons/sourcemod/plugins/optional/autopause.smx and b/addons/sourcemod/plugins/optional/autopause.smx differ diff --git a/addons/sourcemod/scripting/autopause.sp b/addons/sourcemod/scripting/autopause.sp index 78d90d383..442396c51 100644 --- a/addons/sourcemod/scripting/autopause.sp +++ b/addons/sourcemod/scripting/autopause.sp @@ -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" } @@ -49,11 +49,10 @@ ConVar convarForceUnpause, convarDebug; -Handle +StringMap crashedPlayers, generalCrashers, - infectedPlayers, - survivorPlayers; + teamPlayers; bool bReadyUpIsAvailable, @@ -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); @@ -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) { @@ -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; } @@ -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) { @@ -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) { @@ -229,7 +207,7 @@ void Event_PlayerTeam(Event hEvent, char[] sEventName, bool dontBroadcast) } } - PushArrayString(infectedPlayers, sAuthId); + teamPlayers.SetValue(sAuthId, newTeam); if (convarDebug.BoolValue) { @@ -237,6 +215,16 @@ void Event_PlayerTeam(Event hEvent, char[] sEventName, bool dontBroadcast) 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) @@ -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)) @@ -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) @@ -306,7 +295,7 @@ void Event_PlayerDisconnect(Event hEvent, char[] sEventName, bool dontBroadcast) DebugLog(sDebugMessage); } - SetTrieValue(crashedPlayers, sAuthId, fTimeLeft); + crashedPlayers.SetValue(sAuthId, fTimeLeft); } } }