From 8a213d5881cd13e795dc4209745ad03350f9585d Mon Sep 17 00:00:00 2001 From: zaCade Date: Sat, 14 Jan 2023 15:27:08 +0100 Subject: [PATCH] [AFKManager] Disable during breaks. --- AFKManager/scripting/AFKManager.sp | 61 ++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/AFKManager/scripting/AFKManager.sp b/AFKManager/scripting/AFKManager.sp index f42719c9..ec1cffa0 100644 --- a/AFKManager/scripting/AFKManager.sp +++ b/AFKManager/scripting/AFKManager.sp @@ -4,6 +4,7 @@ #include #undef REQUIRE_PLUGIN +#include #include #define REQUIRE_PLUGIN @@ -12,6 +13,8 @@ #define AFK_CHECK_INTERVAL 5.0 +bool g_Plugin_Break; + bool g_Players_bEnabled[MAXPLAYERS + 1]; bool g_Players_bFlagged[MAXPLAYERS + 1]; int g_Players_iLastAction[MAXPLAYERS + 1]; @@ -112,6 +115,26 @@ public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max return APLRes_Success; } +public void OnAllPluginsLoaded() +{ + g_Plugin_Break = LibraryExists("Break"); + + LogMessage("AFKManager capabilities:\nBreak: %s", + (g_Plugin_Break ? "loaded" : "not loaded")); +} + +public void OnLibraryAdded(const char[] name) +{ + if(StrEqual(name, "Break")) + g_Plugin_Break = true; +} + +public void OnLibraryRemoved(const char[] name) +{ + if(StrEqual(name, "Break")) + g_Plugin_Break = false; +} + public void OnMapStart() { CreateTimer(AFK_CHECK_INTERVAL, Timer_CheckPlayer, _, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE); @@ -128,6 +151,41 @@ public void OnMapStart() } } +public void Break_OnBreakStarted() +{ + for(int i = 1; i <= MaxClients; i++) + { + if(IsClientConnected(i)) + OnClientConnected(i); + } +} + +public void Break_OnBreakCancelled() +{ + for(int i = 1; i <= MaxClients; i++) + { + if(IsClientConnected(i)) + { + OnClientConnected(i); + if(IsClientInGame(i) && IsClientAuthorized(i)) + OnClientPostAdminCheck(i); + } + } +} + +public void Break_OnBreakFinished() +{ + for(int i = 1; i <= MaxClients; i++) + { + if(IsClientConnected(i)) + { + OnClientConnected(i); + if(IsClientInGame(i) && IsClientAuthorized(i)) + OnClientPostAdminCheck(i); + } + } +} + public void OnClientConnected(int client) { ResetPlayer(client); @@ -135,6 +193,9 @@ public void OnClientConnected(int client) public void OnClientPostAdminCheck(int client) { + if(g_Plugin_Break && Break_IsBreakActive()) + return; + if(!IsFakeClient(client)) InitializePlayer(client); }