66 lines
1.6 KiB
SourcePawn
66 lines
1.6 KiB
SourcePawn
#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("mce_enable_map_cooldowns_player_count").IntValue;
|
|
int real_players = 0;
|
|
for (int i = 0; i < MaxClients; i++)
|
|
{
|
|
if (IsValidClient(i) && !IsFakeClient(i) && !IsClientSourceTV(i))
|
|
{
|
|
real_players++;
|
|
}
|
|
}
|
|
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)
|
|
{
|
|
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;
|
|
}
|