#include #include #include #include public Plugin myinfo = { name = "spectator_handler", author = "jenz", description = "moves afk spectators to team", version = "1.3", url = "" }; public void OnPluginStart() { CreateTimer(60.0, CheckAfks, _, TIMER_REPEAT); } public Action CheckAfks(Handle timer) { int real_players_cap = FindConVar("sm_exclude_specs_avghour").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) { real_spectator = i; } } } if (real_players < real_players_cap && real_spectator != 0) { ChangeClientTeam(real_spectator, CS_TEAM_T); } return Plugin_Handled; } stock bool IsValidClient(int client) { if (client > 0 && client <= MaxClients && IsClientConnected(client) && IsClientInGame(client)) return true; return false; }