-
Notifications
You must be signed in to change notification settings - Fork 21
/
zp_extraitem_madness.sp
298 lines (255 loc) · 8.05 KB
/
zp_extraitem_madness.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
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
/**
* ============================================================================
*
* Zombie Plague
*
*
* Copyright (C) 2015-2023 qubka (Nikita Ushakov)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* ============================================================================
**/
#include <sourcemod>
#include <sdktools>
#include <zombieplague>
#pragma newdecls required
#pragma semicolon 1
/**
* @brief Record plugin info.
**/
public Plugin myinfo =
{
name = "[ZP] ExtraItem: Madness",
author = "qubka (Nikita Ushakov)",
description = "Addon of extra items",
version = "1.0",
url = "https://forums.alliedmods.net/showthread.php?t=290657"
}
// Timer index
Handle hZombieMadness[MAXPLAYERS+1] = { null, ... };
// Light index
int iLight[MAXPLAYERS+1] = { -1, ... };
// Sound index
int gSound;
// Item index
int gItem;
// Cvars
ConVar hCvarMadnessDuration;
ConVar hCvarMadnessRadius;
ConVar hCvarMadnessDistance;
ConVar hCvarMadnessColor;
/**
* @brief Called when the plugin is fully initialized and all known external references are resolved.
* This is only called once in the lifetime of the plugin, and is paired with OnPluginEnd().
**/
public void OnPluginStart()
{
hCvarMadnessDuration = CreateConVar("zp_extraitem_madness_duration", "5.0", "Madness duration", 0, true, 0.0);
hCvarMadnessRadius = CreateConVar("zp_extraitem_madness_radius", "20.0", "Madness aura size (radius)", 0, true, 0.0);
hCvarMadnessDistance = CreateConVar("zp_extraitem_madness_distance", "600.0", "Madness aura size (distance)", 0, true, 0.0);
hCvarMadnessColor = CreateConVar("zp_extraitem_madness_color", "150 0 0 255", "Madness aura color in 'RGBA'");
AutoExecConfig(true, "zp_extraitem_madness", "sourcemod/zombieplague");
}
/**
* @brief Called after a library is added that the current plugin references optionally.
* A library is either a plugin name or extension name, as exposed via its include file.
**/
public void OnLibraryAdded(const char[] sLibrary)
{
if (!strcmp(sLibrary, "zombieplague", false))
{
if (ZP_IsMapLoaded())
{
ZP_OnEngineExecute();
}
}
}
/**
* @brief Called after a zombie core is loaded.
**/
public void ZP_OnEngineExecute()
{
gItem = ZP_GetExtraItemNameID("madness");
gSound = ZP_GetSoundKeyID("zombie_madness_sounds");
if (gSound == -1) SetFailState("[ZP] Custom sound key ID from name : \"zombie_madness_sounds\" wasn't find");
}
/**
* @brief The map is ending.
**/
public void OnMapEnd()
{
for (int i = 1; i <= MaxClients; i++)
{
hZombieMadness[i] = null; /// with flag TIMER_FLAG_NO_MAPCHANGE
}
}
/**
* @brief Called once a client is authorized and fully in-game, and
* after all post-connection authorizations have been performed.
*
* @note This callback is gauranteed to occur on all clients, and always
* after each OnClientPutInServer() call.
*
* @param client The client index.
**/
public void OnClientPostAdminCheck(int client)
{
SDKHook(client, SDKHook_TraceAttack, TraceAttackHook);
}
/**
* @brief Called when a client is disconnecting from the server.
*
* @param client The client index.
**/
public void OnClientDisconnect(int client)
{
delete hZombieMadness[client];
int entity = EntRefToEntIndex(iLight[client]);
if (entity != -1)
{
AcceptEntityInput(entity, "Kill");
}
iLight[client] = -1;
}
/**
* @brief Called when a client has been killed.
*
* @param client The client index.
* @param attacker The attacker index.
**/
public void ZP_OnClientDeath(int client, int attacker)
{
delete hZombieMadness[client];
int entity = EntRefToEntIndex(iLight[client]);
if (entity != -1)
{
AcceptEntityInput(entity, "Kill");
}
iLight[client] = -1;
}
/**
* @brief Called when a client became a zombie/human.
*
* @param client The client index.
* @param attacker The attacker index.
**/
public void ZP_OnClientUpdated(int client, int attacker)
{
delete hZombieMadness[client];
int entity = EntRefToEntIndex(iLight[client]);
if (entity != -1)
{
AcceptEntityInput(entity, "Kill");
}
iLight[client] = -1;
}
/**
* @brief Called before show an extraitem in the equipment menu.
*
* @param client The client index.
* @param itemID The item index.
*
* @return Plugin_Handled to disactivate showing and Plugin_Stop to disabled showing. Anything else
* (like Plugin_Continue) to allow showing and calling the ZP_OnClientBuyExtraItem() forward.
**/
public Action ZP_OnClientValidateExtraItem(int client, int itemID)
{
if (itemID == gItem)
{
if (hZombieMadness[client] != null)
{
return Plugin_Handled;
}
}
return Plugin_Continue;
}
/**
* @brief Called after select an extraitem in the equipment menu.
*
* @param client The client index.
* @param itemID The item index.
**/
public void ZP_OnClientBuyExtraItem(int client, int itemID)
{
if (itemID == gItem)
{
static float vPosition[3];
GetEntPropVector(client, Prop_Data, "m_vecAbsOrigin", vPosition);
ZP_EmitSoundToAll(gSound, 1, client, SNDCHAN_VOICE);
float flDuration = hCvarMadnessDuration.FloatValue;
static char sEffect[SMALL_LINE_LENGTH];
hCvarMadnessColor.GetString(sEffect, sizeof(sEffect));
int entity = UTIL_CreateLight(client, vPosition, _, _, _, _, _, _, _, sEffect, hCvarMadnessDistance.FloatValue, hCvarMadnessRadius.FloatValue, flDuration);
if (entity != -1)
{
iLight[client] = EntIndexToEntRef(entity);
}
ZP_SetProgressBarTime(client, RoundToNearest(flDuration));
delete hZombieMadness[client];
hZombieMadness[client] = CreateTimer(flDuration, ClientRemoveMadnesss, GetClientUserId(client), TIMER_FLAG_NO_MAPCHANGE);
}
}
/**
* @brief Timer for remove madness.
*
* @param hTimer The timer handle.
* @param userID The user id.
**/
public Action ClientRemoveMadnesss(Handle hTimer, int userID)
{
int client = GetClientOfUserId(userID);
hZombieMadness[client] = null;
if (client)
{
ZP_SetProgressBarTime(client, 0);
}
return Plugin_Stop;
}
/**
* @brief Called before a client take a fake damage.
*
* @param client The client index.
* @param attacker The attacker index. (Not validated!)
* @param inflicter The inflicter index. (Not validated!)
* @param flDamage The amount of damage inflicted.
* @param iBits The ditfield of damage types.
* @param weapon The weapon index or -1 for unspecified.
*
* @note To block damage reset the damage to zero.
**/
public void ZP_OnClientValidateDamage(int client, int &attacker, int &inflictor, float &flDamage, int &iBits, int &weapon)
{
if (hZombieMadness[client] != null)
{
flDamage *= 0.1;
}
}
/**
* Hook: OnTraceAttack
* @brief Called right before the bullet enters a client.
*
* @param client The victim index.
* @param attacker The attacker index.
* @param inflictor The inflictor index.
* @param flDamage The amount of damage inflicted.
* @param iBits The type of damage inflicted.
* @param iAmmo The ammo type of the attacker weapon.
* @param iHitBox The hitbox index.
* @param iHitGroup The hitgroup index.
**/
public Action TraceAttackHook(int client, int &attacker, int &inflictor, float &flDamage, int &iBits, int &iAmmo, int iHitBox, int iHitGroup)
{
return hZombieMadness[client] != null ? Plugin_Handled : Plugin_Continue;
}