Quote:
Originally Posted by sirr
If a player is using a script to look around randomly this cannot really be detected. However stuff like +right and +forward can be detected.
|
You can check if he moves his mouse, i don't know if there's a cheat that send angles changes through mouse.
PHP Code:
#include <sourcemod>
#include <sdktools>
#include <cstrike>
#pragma newdecls required
int g_LastButtonsPressed[MAXPLAYERS + 1];
int g_LastTimeMoving[MAXPLAYERS + 1];
ConVar g_Cvar_AfkTime;
public void OnPluginStart()
{
g_Cvar_AfkTime = CreateConVar("sm_max_afk_time", "30", "Maximum time to be AFK.", FCVAR_NONE, true, 30.0);
HookEvent("player_spawn", Event_PlayerSpawn);
HookEvent("player_death", Event_PlayerDeath);
for (int i = 1; i <= MaxClients; i++)
{
if (IsClientInGame(i))
{
OnClientPutInServer(i);
}
}
}
public void OnMapStart()
{
CreateTimer(1.0, Timer_AFK, _, TIMER_REPEAT | TIMER_FLAG_NO_MAPCHANGE);
}
public Action Timer_AFK(Handle timer, any data)
{
int currentTime = GetTime();
for (int i = 1; i <= MaxClients; i++)
{
if (!IsClientInGame(i) || IsFakeClient(i))
{
continue;
}
if (IsPlayerAlive(i))
{
int difference = currentTime - g_LastTimeMoving[i];
if (difference >= g_Cvar_AfkTime.IntValue)
{
PrintToChatAll("%N has been slayed for being AFK too long.", i);
g_LastTimeMoving[i] = currentTime;
ForcePlayerSuicide(i);
}
else
{
int timeleft = g_Cvar_AfkTime.IntValue - difference;
if (timeleft <= 10)
{
PrintToChat(i, "You will be slayed if you do not move in %d seconds.", timeleft);
}
}
}
}
}
public void OnClientPutInServer(int client)
{
g_LastTimeMoving[client] = GetTime();
g_LastButtonsPressed[client] = 0;
}
public void Event_PlayerSpawn(Event event, const char[] name, bool dontBroadcast)
{
int client = GetClientOfUserId(event.GetInt("userid"));
if (!client)
{
return;
}
g_LastTimeMoving[client] = GetTime();
}
public void Event_PlayerDeath(Event event, const char[] name, bool dontBroadcast)
{
int client = GetClientOfUserId(event.GetInt("userid"));
if (!client)
{
return;
}
g_LastTimeMoving[client] = GetTime();
}
public void OnPlayerRunCmdPost(int client, int buttons, int impulse, const float vel[3], const float angles[3], int weapon, int subtype, int cmdnum, int tickcount, int seed, const int mouse[2])
{
// the client is not afk if he moves his mouse
if (mouse[0] || mouse[1])
{
g_LastButtonsPressed[client] = buttons;
g_LastTimeMoving[client] = GetTime();
return;
}
// the client is not afk if he press different buttons than last time
if (g_LastButtonsPressed[client] != buttons)
{
g_LastButtonsPressed[client] = buttons;
g_LastTimeMoving[client] = GetTime();
}
}
__________________