forked from SirPlease/L4D2-Competitive-Rework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathl4d2_spitblock.sp
More file actions
194 lines (153 loc) · 4.64 KB
/
l4d2_spitblock.sp
File metadata and controls
194 lines (153 loc) · 4.64 KB
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#pragma semicolon 1
#pragma newdecls required
#include <sourcemod>
#include <sdktools>
#include <sdkhooks>
#define MAX_ENTITY_NAME_SIZE 64
#define MAX_MAP_NAME_SIZE 64
#define DMG_TYPE_SPIT (DMG_RADIATION|DMG_ENERGYBEAM)
#define PLUGIN_TAG "l4d2_spitblock"
bool
g_bIsBlockEnable = false;
float
g_fBlockSquare[4] = {0.0, ...};
StringMap
g_hSpitBlockSquares = null;
bool
g_bLateLoad = false;
public Plugin myinfo =
{
name = "L4D2 Spit Blocker",
author = "ProdigySim, Estoopi, Jacob, Visor, A1m`",
description = "Blocks spit damage on various maps",
version = "2.3",
url = "https://github.com/SirPlease/L4D2-Competitive-Rework"
};
public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
{
g_bLateLoad = late;
return APLRes_Success;
}
public void OnPluginStart()
{
g_hSpitBlockSquares = new StringMap();
RegServerCmd("spit_block_square", AddSpitBlockSquare);
RegServerCmd("spit_remove_block_square", RemoveSpitBlockSquare);
if (g_bLateLoad) {
for (int i = 1; i <= MaxClients; i++) {
if (IsClientInGame(i)) {
OnClientPutInServer(i);
}
}
}
}
Action AddSpitBlockSquare(int iArgs)
{
float fSquare[4];
char sMapName[MAX_MAP_NAME_SIZE], sBuffer[32], sGetCmd[128];
if (iArgs != 5) {
GetCmdArgString(sGetCmd, sizeof(sGetCmd));
ErrorAnnounce("[%s] You entered the wrong number of arguments '%f'. Need 5 arguments.", PLUGIN_TAG, sGetCmd);
ErrorAnnounce("[%s] Usage: spit_block_square <mapname> <x1> <y1> <x2> <y2>.", PLUGIN_TAG);
return Plugin_Handled;
}
GetCmdArg(1, sMapName, sizeof(sMapName));
for (int i = 0; i < 4; i++) {
GetCmdArg(2 + i, sBuffer, sizeof(sBuffer));
fSquare[i] = StringToFloat(sBuffer);
}
g_hSpitBlockSquares.SetArray(sMapName, fSquare, sizeof(fSquare), true);
OnMapStart();
//PrintToServer("[%s] Spit block square added on this map '%s'.", PLUGIN_TAG, sMapName);
return Plugin_Handled;
}
Action RemoveSpitBlockSquare(int iArgs)
{
float fSquare[4];
char sMapName[MAX_MAP_NAME_SIZE], sGetCmd[128];
if (iArgs != 1) {
GetCmdArgString(sGetCmd, sizeof(sGetCmd));
ErrorAnnounce("[%s] You entered the wrong number of arguments '%f'. Need 1 argument.", PLUGIN_TAG, sGetCmd);
ErrorAnnounce("[%s] Usage: spit_remove_block_square <mapname>.", PLUGIN_TAG);
return Plugin_Handled;
}
GetCmdArg(1, sMapName, sizeof(sMapName));
if (g_hSpitBlockSquares.GetArray(sMapName, fSquare, sizeof(fSquare))) {
g_hSpitBlockSquares.Remove(sMapName);
PrintToServer("[%s] Spit block square removed on this map '%s'.", PLUGIN_TAG, sMapName);
} else {
PrintToServer("[%s] Сould not find the specified map '%s'.", PLUGIN_TAG, sMapName);
}
OnMapStart();
return Plugin_Handled;
}
public void OnMapStart()
{
char sMapName[MAX_MAP_NAME_SIZE];
GetCurrentMap(sMapName, sizeof(sMapName));
if (g_hSpitBlockSquares.GetArray(sMapName, g_fBlockSquare, sizeof(g_fBlockSquare))) {
g_bIsBlockEnable = true;
return;
}
for (int i = 0; i < sizeof(g_fBlockSquare); i++) {
g_fBlockSquare[i] = 0.0;
}
g_bIsBlockEnable = false;
}
public void OnClientPutInServer(int iClient)
{
SDKHook(iClient, SDKHook_OnTakeDamage, stop_spit_dmg);
}
Action stop_spit_dmg(int iVictim, int &iAttacker, int &iInflictor, float &fDamage, int &iDamageType)
{
if (!g_bIsBlockEnable || !(iDamageType & DMG_TYPE_SPIT)) { //for performance
return Plugin_Continue;
}
if (!IsInsectSwarm(iInflictor) || !IsValidClient(iVictim)) {
return Plugin_Continue;
}
float fOrigin[3];
GetClientAbsOrigin(iVictim, fOrigin);
if (isPointIn2DBox(fOrigin[0], fOrigin[1], g_fBlockSquare[0], g_fBlockSquare[1], g_fBlockSquare[2], g_fBlockSquare[3])) {
return Plugin_Handled;
}
return Plugin_Continue;
}
// Is x0, y0 in the box defined by x1, y1 and x2, y2
bool isPointIn2DBox(float x0, float y0, float x1, float y1, float x2, float y2)
{
if (x1 > x2) {
if (y1 > y2) {
return (x0 <= x1 && x0 >= x2 && y0 <= y1 && y0 >= y2);
} else {
return (x0 <= x1 && x0 >= x2 && y0 >= y1 && y0 <= y2);
}
} else {
if(y1 > y2) {
return (x0 >= x1 && x0 <= x2 && y0 <= y1 && y0 >= y2);
} else {
return (x0 >= x1 && x0 <= x2 && y0 >= y1 && y0 <= y2);
}
}
}
bool IsInsectSwarm(int iEntity)
{
if (iEntity <= MaxClients || !IsValidEdict(iEntity)) {
return false;
}
char sClassName[MAX_ENTITY_NAME_SIZE];
GetEdictClassname(iEntity, sClassName, sizeof(sClassName));
return (strcmp(sClassName, "insect_swarm") == 0);
}
bool IsValidClient(int iClient)
{
return (iClient > 0 && iClient <= MaxClients /*&& IsClientInGame(iClient)*/); //need?
}
void ErrorAnnounce(const char[] szFormat, any ...)
{
int iLen = strlen(szFormat) + 255;
char[] szBuffer = new char[iLen];
VFormat(szBuffer, iLen, szFormat, 2);
LogError(szBuffer);
PrintToServer(szBuffer);
}