From e74db611c4bffcd27ea1326719a79dc08d86e6f4 Mon Sep 17 00:00:00 2001 From: jenz Date: Fri, 19 Jun 2026 15:07:07 +0200 Subject: [PATCH] zspawn and joinclass if afk for 1 minute and below mce_enable_map_cooldowns_player_count counted for real players --- AFKManager/scripting/spectate_handler.sp | 29 +++++++++++++++++++----- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/AFKManager/scripting/spectate_handler.sp b/AFKManager/scripting/spectate_handler.sp index 69a9790..04211cf 100644 --- a/AFKManager/scripting/spectate_handler.sp +++ b/AFKManager/scripting/spectate_handler.sp @@ -19,23 +19,40 @@ public void OnPluginStart() public Action CheckAfks(Handle timer) { - int real_players_cap = FindConVar("sm_exclude_specs_avghour").IntValue; + int real_players_cap = FindConVar("mce_enable_map_cooldowns_player_count").IntValue; int real_players = 0; - int real_spectator = 0; for (int i = 0; i < MaxClients; i++) { if (IsValidClient(i) && !IsFakeClient(i) && !IsClientSourceTV(i)) { real_players++; - if (GetClientTeam(i) <= CS_TEAM_SPECTATOR && GetClientIdleTime(i) > 600) + } + } + if (real_players < real_players_cap) + { + for (int i = 0; i < MaxClients; i++) + { + if (IsValidClient(i) && !IsFakeClient(i) && !IsClientSourceTV(i) && GetClientTeam(i) <= CS_TEAM_SPECTATOR && GetClientIdleTime(i) > 60) { - real_spectator = i; + ChangeClientTeam(i, CS_TEAM_T); + CreateTimer(1.0, zspawn, GetClientSerial(i)); } } } - if (real_players < real_players_cap && real_spectator != 0) + return Plugin_Handled; +} + +public Action zspawn(Handle hTimer, int Serial) +{ + int client; + if ((client = GetClientFromSerial(Serial)) == 0) { - ChangeClientTeam(real_spectator, CS_TEAM_T); + return Plugin_Handled; + } + if (IsValidClient(client)) + { + FakeClientCommandEx(client, "joinclass"); + FakeClientCommandEx(client, "say /zspawn"); } return Plugin_Handled; }