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; }