-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathantiafk.sp
93 lines (76 loc) · 2.22 KB
/
antiafk.sp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include <smutils>
#pragma semicolon 1
#pragma newdecls required
public Plugin myinfo =
{
name = "Anti-AFK",
author = "Kyle",
description = "<- description ->",
version = "1.0",
url = "https://www.kxnrl.com"
};
enum struct client_info_t
{
bool m_IsAFK;
int m_Count;
float m_Angle;
}
static client_info_t g_Client[MAXPLAYERS+1];
public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
{
RegPluginLibrary("Insurgency-AntiAFK");
return APLRes_Success;
}
public void OnPluginStart()
{
SMUitls_InitUserMessage();
SMUtils_SetChatPrefix("[{purple}魔法少女{white}]");
SMUtils_SetChatSpaces(" ");
}
public void OnMapStart()
{
CreateTimer(30.0, Timer_CheckPlayers, _, TIMER_FLAG_NO_MAPCHANGE|TIMER_REPEAT);
}
public void OnClientConnected(int client)
{
resetPlayer(client);
}
public Action Timer_CheckPlayers(Handle timer, any unused)
{
if (GetClientCount(false) <= 26)
return Plugin_Continue;
for(int client = MinClients; client <= MaxClients; ++client)
{
if (!ClientIsValid(client))
continue;
if (g_Client[client].m_IsAFK)
{
if (++g_Client[client].m_Count >= 5)
{
KickClient(client, "[AFK] 挂机时间过长被踢出");
continue;
}
Chat(client, "{red}警告{silver}: {green}长时间无操作将会被踢出游戏{silver}.");
Text(client, "[警告]\n长时间无操作将会被踢出游戏");
Hint(client, "[警告]\n长时间无操作将会被踢出游戏");
}
g_Client[client].m_IsAFK = true;
}
return Plugin_Continue;
}
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])
{
if (IsFakeClient(client))
return;
if (mouse[0] || mouse[1] || g_Client[client].m_Angle != angles[0])
{
// reset
resetPlayer(client);
}
g_Client[client].m_Angle = angles[0];
}
static void resetPlayer(int client)
{
g_Client[client].m_IsAFK = false;
g_Client[client].m_Count = 0;
}