diff --git a/AFKManager/scripting/spectate_handler.sp b/AFKManager/scripting/spectate_handler.sp new file mode 100644 index 0000000..69a9790 --- /dev/null +++ b/AFKManager/scripting/spectate_handler.sp @@ -0,0 +1,48 @@ +#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; +}