-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathL4D2_Nightmarish_Common.sp
360 lines (300 loc) · 11.7 KB
/
L4D2_Nightmarish_Common.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
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
#pragma semicolon 1
#pragma newdecls required
#include <sourcemod>
#include <sdktools>
#include <sdkhooks>
#define L4D2 Nightmarish Common
#define PLUGIN_VERSION "1.1"
#define DEBUG 0
ConVar cvarNightmareChance;
ConVar cvarType1Size;
ConVar cvarType1HPMin;
ConVar cvarType1HPMax;
ConVar cvarType1SpeedMin;
ConVar cvarType1SpeedMax;
ConVar cvarType1Damage;
ConVar cvarType1Armor;
ConVar cvarType2Size;
ConVar cvarType2HPMin;
ConVar cvarType2HPMax;
ConVar cvarType2SpeedMin;
ConVar cvarType2SpeedMax;
ConVar cvarType2Damage;
ConVar cvarType2Armor;
ConVar cvarType3Size;
ConVar cvarType3HPMin;
ConVar cvarType3HPMax;
ConVar cvarType3SpeedMin;
ConVar cvarType3SpeedMax;
ConVar cvarType3Damage;
ConVar cvarType3Armor;
ConVar cvarType4Size;
ConVar cvarType4HPMin;
ConVar cvarType4HPMax;
ConVar cvarType4SpeedMin;
ConVar cvarType4SpeedMax;
ConVar cvarType4Damage;
ConVar cvarType4Armor;
int CommonType[4097];
bool isMapRunning = false;
Handle PluginStartTimer = null;
public Plugin myinfo =
{
name = "噩梦感染者",
author = "Mortiegama",
description = "随机调整普感大小、血量、伤害、速度",
version = PLUGIN_VERSION,
url = "https://forums.alliedmods.net/showthread.php?t=239492"
}
//AtomicStryker - Damage Mod (SDK Hooks):
//https://forums.alliedmods.net/showthread.php?p=1184761
//Bacardi - Cleaning up code:
//https://forums.alliedmods.net/showpost.php?p=2128853&postcount=4
public void OnPluginStart()
{
CreateConVar("l4d_ncm_version", PLUGIN_VERSION, "插件版本", FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY);
cvarNightmareChance = CreateConVar("l4d_ncm_nightmarechance", "90", "普通感染者转变几率", 0, true, 0.0, false, _);
cvarType1Size= CreateConVar("l4d_ncm_type1size", "0.7", "类型1大小", 0, true, 0.0, false, _);
cvarType1HPMin= CreateConVar("l4d_ncm_type1hpmin", "20", "类型1血量最小值", 0, true, 0.0, false, _);
cvarType1HPMax= CreateConVar("l4d_ncm_type1hpmax", "40", "类型1血量最大值", 0, true, 0.0, false, _);
cvarType1SpeedMin= CreateConVar("l4d_ncm_type1speedmin", "1.5", "类型1速度最小值", 0, true, 0.0, false, _);
cvarType1SpeedMax= CreateConVar("l4d_ncm_type1speedmax", "1.8", "类型1速度最大值", 0, true, 0.0, false, _);
cvarType1Damage= CreateConVar("l4d_ncm_type1damage", "1.5", "类型1伤害倍率", 0, true, 0.0, false, _);
cvarType1Armor= CreateConVar("l4d_ncm_type1armor", "1.8", "类型1受伤倍率", 0, true, 0.0, false, _);
cvarType2Size= CreateConVar("l4d_ncm_type1size", "0.9", "类型2大小", 0, true, 0.0, false, _);
cvarType2HPMin= CreateConVar("l4d_ncm_type2hpmin", "65", "类型2血量最小值", 0, true, 0.0, false, _);
cvarType2HPMax= CreateConVar("l4d_ncm_type2hpmax", "85", "类型2血量最大值", 0, true, 0.0, false, _);
cvarType2SpeedMin= CreateConVar("l4d_ncm_type2speedmin", "1.2", "类型2速度最小值", 0, true, 0.0, false, _);
cvarType2SpeedMax= CreateConVar("l4d_ncm_type2speedmax", "1.6", "类型2速度最大值", 0, true, 0.0, false, _);
cvarType2Damage= CreateConVar("l4d_ncm_type2damage", "0.8", "类型2伤害倍率", 0, true, 0.0, false, _);
cvarType2Armor= CreateConVar("l4d_ncm_type2armor", "0.7", "类型2受伤倍率", 0, true, 0.0, false, _);
cvarType3Size= CreateConVar("l4d_ncm_type3size", "1.1", "类型3大小", 0, true, 0.0, false, _);
cvarType3HPMin= CreateConVar("l4d_ncm_type3hpmin", "30", "类型3血量最小值", 0, true, 0.0, false, _);
cvarType3HPMax= CreateConVar("l4d_ncm_type3hpmax", "60", "类型3血量最大值", 0, true, 0.0, false, _);
cvarType3SpeedMin= CreateConVar("l4d_ncm_type3speedmin", "1.1", "类型3速度最小值", 0, true, 0.0, false, _);
cvarType3SpeedMax= CreateConVar("l4d_ncm_type3speedmax", "1.5", "类型3速度最大值", 0, true, 0.0, false, _);
cvarType3Damage= CreateConVar("l4d_ncm_type3damage", "1.3", "类型3伤害倍率", 0, true, 0.0, false, _);
cvarType3Armor= CreateConVar("l4d_ncm_type3armor", "1.1", "类型3受伤倍率", 0, true, 0.0, false, _);
cvarType4Size= CreateConVar("l4d_ncm_type4size", "1.2", "类型4大小", 0, true, 0.0, false, _);
cvarType4HPMin= CreateConVar("l4d_ncm_type4hpmin", "80", "类型4血量最小值", 0, true, 0.0, false, _);
cvarType4HPMax= CreateConVar("l4d_ncm_type4hpmax", "110", "类型4血量最大值", 0, true, 0.0, false, _);
cvarType4SpeedMin= CreateConVar("l4d_ncm_type4speedmin", "0.4", "类型4速度最小值", 0, true, 0.0, false, _);
cvarType4SpeedMax= CreateConVar("l4d_ncm_type4speedmax", "0.7", "类型4速度最大值", 0, true, 0.0, false, _);
cvarType4Damage= CreateConVar("l4d_ncm_type4damage", "0.6", "类型4伤害倍率", 0, true, 0.0, false, _);
cvarType4Armor= CreateConVar("l4d_ncm_type4armor", "0.5", "类型4受伤倍率", 0, true, 0.0, false, _);
AutoExecConfig(true, "L4D2_NightmarishCommon");
PluginStartTimer = CreateTimer(3.0, OnPluginStart_Delayed);
}
public Action OnPluginStart_Delayed(Handle timer)
{
if(PluginStartTimer != null)
{
KillTimer(PluginStartTimer);
PluginStartTimer = null;
}
return Plugin_Stop;
}
public void OnMapStart()
{
isMapRunning = true;
}
public void OnClientPostAdminCheck(int client)
{
SDKHook(client, SDKHook_OnTakeDamage, OnTakeDamage_Survivor);
}
public void OnEntityCreated(int entity, const char[] classname)
{
if (!isMapRunning || IsServerProcessing() == false) return;
if (StrEqual(classname, "infected", false))
{
// CreateTimer(0.5, Timer_CommonSpawn, EntIndexToEntRef(entity), TIMER_FLAG_NO_MAPCHANGE);
SDKHook(entity, SDKHook_SpawnPost, CommonSpawn);
}
}
public void OnEntityDestroyed(int entity)
{
SDKUnhook(entity, SDKHook_SpawnPost, CommonSpawn);
SDKUnhook(entity, SDKHook_OnTakeDamage, OnTakeDamage_Infected);
}
// public Action Timer_CommonSpawn(Handle timer, any ref)
public void CommonSpawn(int entity)
{
// int entity = EntRefToEntIndex(ref);
SDKUnhook(entity, SDKHook_SpawnPost, CommonSpawn);
if(/*entity == INVALID_ENT_REFERENCE || */!IsValidEntity(entity) || !IsValidEdict(entity))
{ return/* Plugin_Stop*/; }
int NightmareChance = GetRandomInt(0, 99);
int NightmarePercent = (GetConVarInt(cvarNightmareChance));
if (NightmareChance < NightmarePercent)
{
int integer = GetRandomInt(1, 4);
#if DEBUG
PrintToChatAll("Entity is a common infected, type %i.", integer);
#endif
int iHP;
float iSpeed;
float iScale;
switch (integer)
{
case 1:
{
#if DEBUG
PrintToChatAll("Zombie type small strong fast low.");
#endif
iHP = GetRandomInt(GetConVarInt(cvarType1HPMin), GetConVarInt(cvarType1HPMax));
iSpeed = GetRandomFloat(GetConVarFloat(cvarType1SpeedMin), GetConVarFloat(cvarType1SpeedMax));
iScale = GetConVarFloat(cvarType1Size);
CommonType[entity] = 1;
}
case 2:
{
#if DEBUG
PrintToChatAll("Zombie type small weak quick sturdy.");
#endif
iHP = GetRandomInt(GetConVarInt(cvarType2HPMin), GetConVarInt(cvarType2HPMax));
iSpeed = GetRandomFloat(GetConVarFloat(cvarType2SpeedMin), GetConVarFloat(cvarType2SpeedMax));
iScale = GetConVarFloat(cvarType2Size);
CommonType[entity] = 2;
}
case 3:
{
#if DEBUG
PrintToChatAll("Zombie type big tough quick weak.");
#endif
iHP = GetRandomInt(GetConVarInt(cvarType3HPMin), GetConVarInt(cvarType3HPMax));
iSpeed = GetRandomFloat(GetConVarFloat(cvarType3SpeedMin), GetConVarFloat(cvarType3SpeedMax));
iScale = GetConVarFloat(cvarType3Size);
CommonType[entity] = 3;
}
case 4:
{
#if DEBUG
PrintToChatAll("Zombie type large titanic slow titanic.");
#endif
iHP = GetRandomInt(GetConVarInt(cvarType4HPMin), GetConVarInt(cvarType4HPMax));
iSpeed = GetRandomFloat(GetConVarFloat(cvarType4SpeedMin), GetConVarFloat(cvarType4SpeedMax));
iScale = GetConVarFloat(cvarType4Size);
CommonType[entity] = 4;
}
}
SDKHook(entity, SDKHook_OnTakeDamage, OnTakeDamage_Infected);
SetEntPropFloat(entity, Prop_Send, "m_flModelScale", iScale);
SetEntProp(entity, Prop_Data, "m_iMaxHealth", iHP);//Set max and
SetEntProp(entity, Prop_Data, "m_iHealth", iHP); //current health of witch to defined health.
AcceptEntityInput(entity, "Disable");
SetEntPropFloat(entity, Prop_Data, "m_flSpeed", 1.0*iSpeed);
AcceptEntityInput(entity, "Enable");
}
// return Plugin_Continue;
}
public Action OnTakeDamage_Infected(int victim, int &attacker, int &inflictor, float &damage, int &damagetype)
{
if (!isMapRunning || IsServerProcessing() == false) return Plugin_Stop;
if (IsValidCommon(victim))
{
switch (CommonType[victim])
{
case 1:
{
float damagemod = GetConVarFloat(cvarType1Armor);
#if DEBUG
PrintToChatAll("Damage Caught: %f damage times %f mod.", damage, damagemod);
#endif
if (FloatCompare(damagemod, 1.0) != 0) { damage = damage * damagemod; }
}
case 2:
{
float damagemod = GetConVarFloat(cvarType2Armor);
#if DEBUG
PrintToChatAll("Damage Caught: %f damage times %f mod.", damage, damagemod);
#endif
if (FloatCompare(damagemod, 1.0) != 0) { damage = damage * damagemod; }
}
case 3:
{
float damagemod = GetConVarFloat(cvarType3Armor);
#if DEBUG
PrintToChatAll("Damage Caught: %f damage times %f mod.", damage, damagemod);
#endif
if (FloatCompare(damagemod, 1.0) != 0) { damage = damage * damagemod; }
}
case 4:
{
float damagemod = GetConVarFloat(cvarType4Armor);
#if DEBUG
PrintToChatAll("Damage Caught: %f damage times %f mod.", damage, damagemod);
#endif
if (FloatCompare(damagemod, 1.0) != 0) { damage = damage * damagemod; }
}
}
}
return Plugin_Changed;
}
public Action OnTakeDamage_Survivor(int victim, int &attacker, int &inflictor, float &damage, int &damagetype)
{
if (!isMapRunning || IsServerProcessing() == false) return Plugin_Stop;
if (IsValidCommon(attacker))
{
if (IsValidClient(victim) && GetClientTeam(victim) == 2)
{
switch (CommonType[attacker])
{
case 1:
{
float damagemod = GetConVarFloat(cvarType1Damage);
#if DEBUG
PrintToChatAll("Survivor damage Caught: %f damage times %f mod.", damage, damagemod);
#endif
if (FloatCompare(damagemod, 1.0) != 0) { damage = damage * damagemod; }
}
case 2:
{
float damagemod = GetConVarFloat(cvarType2Damage);
#if DEBUG
PrintToChatAll("Survivor damage Caught: %f damage times %f mod.", damage, damagemod);
#endif
if (FloatCompare(damagemod, 1.0) != 0) { damage = damage * damagemod; }
}
case 3:
{
float damagemod = GetConVarFloat(cvarType3Damage);
#if DEBUG
PrintToChatAll("Survivor damage Caught: %f damage times %f mod.", damage, damagemod);
#endif
if (FloatCompare(damagemod, 1.0) != 0) { damage = damage * damagemod; }
}
case 4:
{
float damagemod = GetConVarFloat(cvarType4Damage);
#if DEBUG
PrintToChatAll("Survivor damage Caught: %f damage times %f mod.", damage, damagemod);
#endif
if (FloatCompare(damagemod, 1.0) != 0) { damage = damage * damagemod; }
}
}
}
}
return Plugin_Changed;
}
public void OnMapEnd()
{
isMapRunning = false;
}
int IsValidCommon(int common)
{
if(common > MaxClients && IsValidEdict(common) && IsValidEntity(common))
{
char classname[32];
GetEdictClassname(common, classname, sizeof(classname));
if(StrEqual(classname, "infected")) { return true; }
}
return false;
}
public int IsValidClient(int client)
{
if (client <= 0) return false;
if (client > MaxClients) return false;
if (!IsClientInGame(client)) return false;
if (!IsPlayerAlive(client)) return false;
return true;
}