just a tiny plugin moving afk spectators to teams
This commit is contained in:
parent
e86e90838a
commit
3d7e279cc7
48
AFKManager/scripting/spectate_handler.sp
Normal file
48
AFKManager/scripting/spectate_handler.sp
Normal file
@ -0,0 +1,48 @@
|
||||
#include <sourcemod>
|
||||
#include <sdktools>
|
||||
#include <cstrike>
|
||||
#include <AFKManager>
|
||||
|
||||
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;
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user