-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathNoSpam.sp
141 lines (120 loc) · 4.03 KB
/
NoSpam.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#pragma semicolon 1
#include <sourcemod>
#include <sdktools>
#define PL_VERSION "0.01"
#define SERVER_TAG "nospam"
public Plugin:myinfo = {
name = "NoSpam",
author = "MadKat",
description = "Allows a server operator to throttle jump and shield spam.",
version = PL_VERSION,
url = "http://www.github.com/madkat"
}
new cvar_enabled;
new cvar_debug;
new float:cvar_jump;
new float:cvar_shield;
#define NS_TIMERS 1
#define NS_JUMP 0
#define NS_SHIELD 1
new Handle:clientTimers[MAXPLAYERS + 1][NS_TIMERS];
new jumpState[MAXPLAYERS + 1];
public OnPluginStart()
{
/*
Cvars
*/
CreateConVar("pvkii_nospam_version", PL_VERSION, "NoSpam for PVKII.", FCVAR_SPONLY | FCVAR_NOTIFY | FCVAR_PLUGIN);
new Handle:cv_enabled = CreateConVar("ns_enabled", "1", "Enables/disables PVKII Randomizer.", FCVAR_NOTIFY | FCVAR_PLUGIN, true, 0.0, true, 1.0);
new Handle:cv_debug = CreateConVar("ns_debug", "0", "Debug mode.", FCVAR_PLUGIN, true, 0.0, true, 1.0);
new Handle:cv_jump = CreateConVar("ns_jump", "1.0", "Set how often a player may jump.", FCVAR_NOTIFY | FCVAR_PLUGIN, true, 0.0, true, 10.0);
new Handle:cv_shield = CreateConVar("ns_shield", "1.0", "Set how often a player may shield smash.", FCVAR_NOTIFY | FCVAR_PLUGIN, true, 0.0, true, 10.0);
HookEvent("player_spawn", player_spawn);
HookEvent("round_end", round_end);
HookEvent("gamemode_roundrestart", gamemode_roundrestart);
HookConVarChange(cv_enabled, cvHookEnabled);
HookConVarChange(cv_debug, cvHookDebug);
HookConVarChange(cv_jump, cvHookJump);
HookConVarChange(cv_shield, cvHookShield);
cvar_enabled = GetConVarBool(cv_enabled);
cvar_debug = GetConVarBool(cv_debug);
cvar_jump = GetConVarFloat(cv_jump);
cvar_shield = GetConVarFloat(cv_shield);
/*
Event Hooks
*/
AddServerTag(SERVER_TAG);
}
public cvHookEnabled(Handle:cvar, const String:oldVal[], const String:newVal[])
{
cvar_enabled = GetConVarBool(cvar);
if (!cvar_enabled)
{
RemoveServerTag(SERVER_TAG);
}
else
{
AddServerTag(SERVER_TAG);
}
}
public cvHookDebug(Handle:cvar, const String:oldVal[], const String:newVal[]) { cvar_debug = GetConVarBool(cvar); }
public cvHookJump(Handle:cvar, const String:oldVal[], const String:newVal[]) { cvar_jump = GetConVarFloat(cvar); }
public cvHookShield(Handle:cvar, const String:oldVal[], const String:newVal[]) { cvar_shield = GetConVarFloat(cvar); }
public Action:OnPlayerRunCmd(client, &buttons, &impulse, Float:vel[3], Float:angles[3], &weapon)
{
if (cvar_enabled)
{
if(IsValidEntity(client) && IsClientInGame(client) && IsPlayerAlive(client))
{
if (buttons & IN_JUMP)
{
new GroundEntity = GetEntPropEnt(client, Prop_Send, "m_hGroundEntity");
if (jumpState[client] == 0 && GroundEntity != -1)
{
if (clientTimers[client][NS_JUMP] == INVALID_HANDLE)
{
clientTimers[client][NS_JUMP] = CreateTimer(cvar_jump, ResetJumpTimer, client);
return Plugin_Continue;
}
else
{
buttons ^= IN_JUMP;
return Plugin_Continue;
}
}
jumpState[client] = 1;
}
else
{
jumpState[client] = 0;
}
}
}
return Plugin_Continue;
}
public Action:ResetJumpTimer(Handle:timer, any:client)
{
clientTimers[client][NS_JUMP] = INVALID_HANDLE;
}
public ResetClient(client)
{
for (new i = 0; i < NS_TIMERS; i++) clientTimers[client][i] = INVALID_HANDLE;
jumpState[client] = 0;
}
public OnMapStart()
{
for (new i = 1; i <= MaxClients; i++) if (IsClientInGame(i)) ResetClient(i);
}
public player_spawn(Handle:event, const String:name[], bool:dontBroadcast)
{
new client = GetClientOfUserId(GetEventInt(event, "userid"));
ResetClient(client);
}
public round_end(Handle:event, const String:name[], bool:dontBroadcast)
{
for (new i = 1; i <= MaxClients; i++) if (IsClientInGame(i)) ResetClient(i);
}
public gamemode_roundrestart(Handle:event, const String:name[], bool:dontBroadcast)
{
for (new i = 1; i <= MaxClients; i++) if (IsClientInGame(i)) ResetClient(i);
}