forked from SilvDev/Various_Scripts_Collection
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathl4d_infected_glow.sp
More file actions
573 lines (460 loc) · 16.5 KB
/
l4d_infected_glow.sp
File metadata and controls
573 lines (460 loc) · 16.5 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
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
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
/*
* Infected Glow
* Copyright (C) 2023 Silvers
*
* 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 <https://www.gnu.org/licenses/>.
*/
#define PLUGIN_VERSION "1.13"
/*======================================================================================
Plugin Info:
* Name : [L4D & L4D2] Infected Glow
* Author : SilverShot
* Descrp : Creates a dynamic light on common/special infected who are burning.
* Link : https://forums.alliedmods.net/showthread.php?t=187933
* Plugins : https://sourcemod.net/plugins.php?exact=exact&sortby=title&search=1&author=Silvers
========================================================================================
Change Log:
1.13 (11-Dec-2023)
- Added cvar "l4d_infected_glow_death" to decide if the glow disappears on death or remains in last position.
1.12 (11-Dec-2022)
- Changes to fix compile warnings on SourceMod 1.11.
1.11 (05-Jun-2022)
- Fixed glow duration not following the burn duration. Thanks to "gongo" for reporting.
1.10 (10-Apr-2022)
- Changed the method for fading lights in and out hopefully preventing random server crash.
1.9 (03-Aug-2020)
- Added light fading out instead of abruptly disappearing.
- Added smoother fading of the light, thanks to "Lux" for original coding from "Fire Glow" plugin.
1.8 (10-May-2020)
- Extra checks to prevent "IsAllowedGameMode" throwing errors.
- Fixed cvar "l4d_infected_glow_infected" not working for the Tank in L4D1.
1.7 (01-Apr-2020)
- Fixed "IsAllowedGameMode" from throwing errors when the "_tog" cvar was changed before MapStart.
1.6 (03-Feb-2020)
- Fixed errors "Invalid edict" by adding "IsValidEdict" - Thanks to "TiTz" for reporting.
1.5 (05-May-2018)
- Converted plugin source to the latest syntax utilizing methodmaps. Requires SourceMod 1.8 or newer.
- Changed cvar "l4d_infected_glow_modes_tog" now supports L4D1.
1.4 (30-Jun-2012)
- Fixed the plugin not working in L4D1.
1.3 (22-Jun-2012)
- Fixed water not removing the glow - Thanks to "id5473" for reporting.
1.2 (20-Jun-2012)
- Added some checks to prevent errors being logged - Thanks to "doritos250" for reporting.
1.1 (20-Jun-2012)
- Fixed not removing the light from Special Infected ignited by incendiary ammo.
1.0 (20-Jun-2012)
- Initial release.
======================================================================================*/
// Testing: l4d_dissolve_allow 0; l4d_burn_duration_allow 0
#pragma semicolon 1
#pragma newdecls required
#include <sourcemod>
#include <sdktools>
#include <sdkhooks>
#define CVAR_FLAGS FCVAR_NOTIFY
#define MAX_LIGHTS 8
ConVar g_hCvarAllow, g_hCvarColor, g_hCvarDeath, g_hCvarDist, g_hCvarInfected, g_hCvarMPGameMode, g_hCvarModes, g_hCvarModesOff, g_hCvarModesTog;
int g_iCvarInfected, g_iEntities[MAX_LIGHTS][2], g_iTick[MAX_LIGHTS], g_iClassTank;
bool g_bCvarAllow, g_bMapStarted, g_bLeft4Dead2, g_bFrameProcessing, g_bWatch, g_bCvarDeath;
char g_sCvarCols[12];
float g_fFaderTick[MAX_LIGHTS], g_fFaderStart[MAX_LIGHTS], g_fFaderEnd[MAX_LIGHTS], g_fCvarDist;
Handle g_hTimer[MAX_LIGHTS];
enum
{
INDEX_ENTITY = 0,
INDEX_TARGET = 1
}
// ====================================================================================================
// PLUGIN INFO / START / END
// ====================================================================================================
public Plugin myinfo =
{
name = "[L4D & L4D2] Infected Glow",
author = "SilverShot",
description = "Creates a dynamic light on common/special infected who are burning.",
version = PLUGIN_VERSION,
url = "https://forums.alliedmods.net/showthread.php?t=187933"
}
public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
{
EngineVersion test = GetEngineVersion();
if( test == Engine_Left4Dead ) g_bLeft4Dead2 = false;
else if( test == Engine_Left4Dead2 ) g_bLeft4Dead2 = true;
else
{
strcopy(error, err_max, "Plugin only supports Left 4 Dead 1 & 2.");
return APLRes_SilentFailure;
}
return APLRes_Success;
}
public void OnPluginStart()
{
g_hCvarAllow = CreateConVar( "l4d_infected_glow_allow", "1", "0=Plugin off, 1=Plugin on.", CVAR_FLAGS );
g_hCvarModes = CreateConVar( "l4d_infected_glow_modes", "", "Turn on the plugin in these game modes, separate by commas (no spaces). (Empty = all).", CVAR_FLAGS );
g_hCvarModesOff = CreateConVar( "l4d_infected_glow_modes_off", "", "Turn off the plugin in these game modes, separate by commas (no spaces). (Empty = none).", CVAR_FLAGS );
g_hCvarModesTog = CreateConVar( "l4d_infected_glow_modes_tog", "0", "Turn on the plugin in these game modes. 0=All, 1=Coop, 2=Survival, 4=Versus, 8=Scavenge. Add numbers together.", CVAR_FLAGS );
g_hCvarColor = CreateConVar( "l4d_infected_glow_color", "255 50 0", "The light color. Three values between 0-255 separated by spaces. RGB Color255 - Red Green Blue.", CVAR_FLAGS );
g_hCvarDeath = CreateConVar( "l4d_infected_glow_death", "0", "0=Glow disappears on death (even if ragdoll is burning). 1=Glow remains in last position until flames would likely disappear.", CVAR_FLAGS );
g_hCvarDist = CreateConVar( "l4d_infected_glow_distance", "200.0", "How far does the dynamic light illuminate the area.", CVAR_FLAGS );
g_hCvarInfected = CreateConVar( "l4d_infected_glow_infected", "511", "1=Common, 2=Witch, 4=Smoker, 8=Boomer, 16=Hunter, 32=Spitter, 64=Jockey, 128=Charger, 256=Tank, 511=All.", CVAR_FLAGS );
CreateConVar( "l4d_infected_glow_version", PLUGIN_VERSION, "Molotov and Gascan Glow plugin version.", FCVAR_NOTIFY|FCVAR_DONTRECORD);
AutoExecConfig(true, "l4d_infected_glow");
g_hCvarMPGameMode = FindConVar("mp_gamemode");
g_hCvarMPGameMode.AddChangeHook(ConVarChanged_Allow);
g_hCvarModesTog.AddChangeHook(ConVarChanged_Allow);
g_hCvarModes.AddChangeHook(ConVarChanged_Allow);
g_hCvarModesOff.AddChangeHook(ConVarChanged_Allow);
g_hCvarAllow.AddChangeHook(ConVarChanged_Allow);
g_hCvarDeath.AddChangeHook(ConVarChanged_Cvars);
g_hCvarDist.AddChangeHook(ConVarChanged_Cvars);
g_hCvarColor.AddChangeHook(ConVarChanged_Cvars);
g_hCvarInfected.AddChangeHook(ConVarChanged_Cvars);
g_iClassTank = g_bLeft4Dead2 ? 9 : 6;
}
public void OnPluginEnd()
{
ResetPlugin();
}
public void OnMapStart()
{
g_bMapStarted = true;
}
public void OnMapEnd()
{
g_bMapStarted = false;
ResetPlugin();
}
void ResetPlugin()
{
g_bWatch = false;
for( int i = 0; i < MAX_LIGHTS; i++ )
{
delete g_hTimer[i] = null;
if( IsValidEntRef(g_iEntities[i][INDEX_ENTITY]) == true )
{
RemoveEntity(g_iEntities[i][INDEX_ENTITY]);
}
g_iEntities[i][INDEX_ENTITY] = 0;
g_iEntities[i][INDEX_TARGET] = 0;
}
}
// ====================================================================================================
// CVARS
// ====================================================================================================
public void OnConfigsExecuted()
{
IsAllowed();
}
void ConVarChanged_Allow(Handle convar, const char[] oldValue, const char[] newValue)
{
IsAllowed();
}
void ConVarChanged_Cvars(Handle convar, const char[] oldValue, const char[] newValue)
{
GetCvars();
}
void GetCvars()
{
g_bCvarDeath = g_hCvarDeath.BoolValue;
g_fCvarDist = g_hCvarDist.FloatValue;
g_hCvarColor.GetString(g_sCvarCols, sizeof(g_sCvarCols));
g_iCvarInfected = g_hCvarInfected.IntValue;
}
void IsAllowed()
{
bool bCvarAllow = g_hCvarAllow.BoolValue;
bool bAllowMode = IsAllowedGameMode();
GetCvars();
if( g_bCvarAllow == false && bCvarAllow == true && bAllowMode == true )
{
g_bCvarAllow = true;
}
else if( g_bCvarAllow == true && (bCvarAllow == false || bAllowMode == false) )
{
ResetPlugin();
g_bCvarAllow = false;
}
}
int g_iCurrentMode;
bool IsAllowedGameMode()
{
if( g_hCvarMPGameMode == null )
return false;
int iCvarModesTog = g_hCvarModesTog.IntValue;
if( iCvarModesTog != 0 )
{
if( g_bMapStarted == false )
return false;
g_iCurrentMode = 0;
int entity = CreateEntityByName("info_gamemode");
if( IsValidEntity(entity) )
{
DispatchSpawn(entity);
HookSingleEntityOutput(entity, "OnCoop", OnGamemode, true);
HookSingleEntityOutput(entity, "OnSurvival", OnGamemode, true);
HookSingleEntityOutput(entity, "OnVersus", OnGamemode, true);
HookSingleEntityOutput(entity, "OnScavenge", OnGamemode, true);
ActivateEntity(entity);
AcceptEntityInput(entity, "PostSpawnActivate");
if( IsValidEntity(entity) ) // Because sometimes "PostSpawnActivate" seems to kill the ent.
RemoveEdict(entity); // Because multiple plugins creating at once, avoid too many duplicate ents in the same frame
}
if( g_iCurrentMode == 0 )
return false;
if( !(iCvarModesTog & g_iCurrentMode) )
return false;
}
char sGameModes[64], sGameMode[64];
g_hCvarMPGameMode.GetString(sGameMode, sizeof(sGameMode));
Format(sGameMode, sizeof(sGameMode), ",%s,", sGameMode);
g_hCvarModes.GetString(sGameModes, sizeof(sGameModes));
if( sGameModes[0] )
{
Format(sGameModes, sizeof(sGameModes), ",%s,", sGameModes);
if( StrContains(sGameModes, sGameMode, false) == -1 )
return false;
}
g_hCvarModesOff.GetString(sGameModes, sizeof(sGameModes));
if( sGameModes[0] )
{
Format(sGameModes, sizeof(sGameModes), ",%s,", sGameModes);
if( StrContains(sGameModes, sGameMode, false) != -1 )
return false;
}
return true;
}
void OnGamemode(const char[] output, int caller, int activator, float delay)
{
if( strcmp(output, "OnCoop") == 0 )
g_iCurrentMode = 1;
else if( strcmp(output, "OnSurvival") == 0 )
g_iCurrentMode = 2;
else if( strcmp(output, "OnVersus") == 0 )
g_iCurrentMode = 4;
else if( strcmp(output, "OnScavenge") == 0 )
g_iCurrentMode = 8;
}
// ====================================================================================================
// EVENTS
// ====================================================================================================
public void OnEntityCreated(int entity, const char[] classname)
{
if( g_bCvarAllow && g_bMapStarted )
{
if( strcmp(classname, "entityflame") == 0 )
{
CreateTimer(0.1, TimerCreate, EntIndexToEntRef(entity));
}
}
}
public void OnEntityDestroyed(int entity)
{
if( g_bWatch && g_bCvarAllow && g_bMapStarted && entity > 0 )
{
entity = EntIndexToEntRef(entity);
int valid;
for( int i = 0; i < MAX_LIGHTS; i++ )
{
if( entity == g_iEntities[i][INDEX_TARGET] && IsValidEntRef(g_iEntities[i][INDEX_ENTITY]) )
{
if( g_bCvarDeath )
{
int parent = GetEntPropEnt(entity, Prop_Data, "m_hMoveParent");
if( parent > 0 && parent <= MaxClients && IsValidEntity(parent) )
{
float vVec[3];
GetEntPropVector(parent, Prop_Data, "m_vecVelocity", vVec);
AcceptEntityInput(g_iEntities[i][INDEX_ENTITY], "ClearParent");
delete g_hTimer[i];
g_hTimer[i] = CreateTimer(GetVectorLength(vVec) <= 250.0 ? 7.0 : 0.1, TimerDestroy, i);
continue;
}
}
CreateTimer(0.1, TimerDestroy, i);
}
else if( IsValidEntRef(g_iEntities[i][INDEX_TARGET]) == true )
{
valid = 1;
}
}
if( valid == 0 )
{
g_bWatch = false;
}
}
}
// ====================================================================================================
// LIGHTS
// ====================================================================================================
Action TimerCreate(Handle timer, int target)
{
if( (target = EntRefToEntIndex(target)) != INVALID_ENT_REFERENCE )
{
int client = GetEntPropEnt(target, Prop_Data, "m_hEntAttached");
if( client < 1 )
return Plugin_Continue;
static char sTemp[64];
// Validate target
if( client > MaxClients )
{
int infected = g_iCvarInfected & (1<<0);
int witch = g_iCvarInfected & (1<<1);
if( infected || witch )
{
if( IsValidEntity(client) == false || IsValidEdict(client) == false )
return Plugin_Continue;
GetEdictClassname(client, sTemp, sizeof(sTemp));
if( (infected && strcmp(sTemp, "infected") != 0) && (witch && strcmp(sTemp, "witch") != 0) )
return Plugin_Continue;
} else {
return Plugin_Continue;
}
}
else
{
if( IsClientInGame(client) == false || GetClientTeam(client) != 3 )
return Plugin_Continue;
int class = GetEntProp(client, Prop_Send, "m_zombieClass") + 1;
if( class == g_iClassTank ) class = 8;
if( !(g_iCvarInfected & (1 << class)) )
return Plugin_Continue;
}
// Find empty index
int index = -1;
for( int i = 0; i < MAX_LIGHTS; i++ )
{
if( IsValidEntRef(g_iEntities[i][INDEX_ENTITY]) == false )
{
index = i;
break;
}
}
if( index == -1 )
return Plugin_Continue;
// Create light
int entity = CreateEntityByName("light_dynamic");
if( entity == -1)
{
LogError("Failed to create 'light_dynamic'");
return Plugin_Continue;
}
g_bWatch = true;
g_iEntities[index][INDEX_ENTITY] = EntIndexToEntRef(entity);
g_iEntities[index][INDEX_TARGET] = EntIndexToEntRef(target);
Format(sTemp, sizeof(sTemp), "%s 255", g_sCvarCols);
DispatchKeyValue(entity, "_light", sTemp);
DispatchKeyValue(entity, "brightness", "2");
DispatchKeyValueFloat(entity, "spotlight_radius", 32.0);
DispatchKeyValueFloat(entity, "distance", 5.0);
DispatchKeyValue(entity, "style", "6");
DispatchSpawn(entity);
SetVariantString("!activator");
AcceptEntityInput(entity, "SetParent", target);
float vPos[3];
vPos[2] = 50.0;
TeleportEntity(entity, vPos, NULL_VECTOR, NULL_VECTOR);
AcceptEntityInput(entity, "TurnOn");
float flTickInterval = GetTickInterval();
int iTickRate = RoundFloat(1 / flTickInterval);
// Fade
if( !g_bFrameProcessing )
{
g_bFrameProcessing = true;
RequestFrame(OnFrameFadeIn);
}
g_iTick[index] = 8;
g_fFaderEnd[index] = GetGameTime() + 9999.9;
g_fFaderStart[index] = GetGameTime() + flTickInterval * iTickRate + 2.0;
g_fFaderTick[index] = GetGameTime();
}
return Plugin_Continue;
}
void OnFrameFadeIn()
{
g_bFrameProcessing = false;
float fDist;
float fTime = GetGameTime();
float flTickInterval = GetTickInterval();
int iTickRate = RoundFloat(1 / flTickInterval);
// Loop through valid ents
for( int i = 0; i < MAX_LIGHTS; i++ )
{
if( IsValidEntRef(g_iEntities[i][INDEX_ENTITY]) )
{
// Fade in
if( fTime < g_fFaderStart[i] )
{
fDist = (g_fCvarDist / iTickRate) * g_iTick[i];
if( fDist < g_fCvarDist )
{
g_bFrameProcessing = true;
SetVariantFloat(fDist);
AcceptEntityInput(g_iEntities[i][INDEX_ENTITY], "Distance");
g_iTick[i]++;
}
}
}
}
if( g_bFrameProcessing )
{
RequestFrame(OnFrameFadeIn);
}
}
Action TimerDestroy(Handle timer, int index)
{
g_hTimer[index] = null;
if( IsValidEntRef(g_iEntities[index][INDEX_ENTITY]) )
{
g_iTick[index] = 0;
RequestFrame(OnFrameFadeOut, index);
}
return Plugin_Continue;
}
void OnFrameFadeOut(int index)
{
if( !IsValidEntRef(g_iEntities[index][INDEX_ENTITY]) )
{
g_iEntities[index][INDEX_ENTITY] = 0;
g_iEntities[index][INDEX_TARGET] = 0;
delete g_hTimer[index];
return;
}
float fDist;
float flTickInterval = GetTickInterval();
int iTickRate = RoundFloat(1 / flTickInterval);
fDist = (g_fCvarDist / iTickRate) * (iTickRate - g_iTick[index]);
g_iTick[index]++;
if( fDist > 0.0 )
{
if( fDist < g_fCvarDist )
{
SetVariantFloat(fDist);
AcceptEntityInput(g_iEntities[index][INDEX_ENTITY], "Distance");
}
RequestFrame(OnFrameFadeOut, index);
} else {
RemoveEntity(g_iEntities[index][INDEX_ENTITY]);
g_iTick[index] = 0;
g_iEntities[index][INDEX_ENTITY] = 0;
g_iEntities[index][INDEX_TARGET] = 0;
delete g_hTimer[index];
}
}
bool IsValidEntRef(int entity)
{
if( entity && EntRefToEntIndex(entity) != INVALID_ENT_REFERENCE )
return true;
return false;
}