#include #include #include #include int g_iPlayer_move_spec_count; 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); ConVar cvar; HookConVarChange((cvar = CreateConVar("sm_move_spec_to_team_count", "30", "Move real players from spec to teams until this many real players are connected")), Cvar_move_spec_team); g_iPlayer_move_spec_count = cvar.IntValue; delete cvar; } public void Cvar_move_spec_team(ConVar convar, const char[] oldValue, const char[] newValue) { g_iPlayer_move_spec_count = convar.IntValue; } public Action CheckAfks(Handle timer) { int real_players = 0; for (int i = 0; i < MaxClients; i++) { if (IsValidClient(i) && !IsFakeClient(i) && !IsClientSourceTV(i)) { real_players++; } } if (real_players < g_iPlayer_move_spec_count) { for (int i = 0; i < MaxClients; i++) { if (IsValidClient(i) && !IsFakeClient(i) && !IsClientSourceTV(i) && GetClientTeam(i) <= CS_TEAM_SPECTATOR && GetClientIdleTime(i) > 60) { ChangeClientTeam(i, CS_TEAM_T); CreateTimer(1.0, zspawn, GetClientSerial(i)); } } } return Plugin_Handled; } public Action zspawn(Handle hTimer, int Serial) { int client; if ((client = GetClientFromSerial(Serial)) == 0) { return Plugin_Handled; } if (IsValidClient(client)) { FakeClientCommandEx(client, "joinclass"); FakeClientCommandEx(client, "say /zspawn"); } return Plugin_Handled; } stock bool IsValidClient(int client) { if (client > 0 && client <= MaxClients && IsClientConnected(client) && IsClientInGame(client)) return true; return false; }