-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathl4d2_hud_splater.sp
More file actions
679 lines (564 loc) · 18.3 KB
/
l4d2_hud_splater.sp
File metadata and controls
679 lines (564 loc) · 18.3 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
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
/*
* Hud Splatter
* Copyright (C) 2022 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.5"
/*======================================================================================
Plugin Info:
* Name : [L4D2] Hud Splatter
* Author : SilverShot
* Descp : Splat effects on players screen.
* Link : https://forums.alliedmods.net/showthread.php?t=137445
* Plugins : https://sourcemod.net/plugins.php?exact=exact&sortby=title&search=1&author=Silvers
========================================================================================
Change Log:
1.5 (11-Dec-2022)
- Changes to fix compile warnings on SourceMod 1.11.
1.4 (21-Sep-2021)
- Fixed targeting single or multiple people being flipped.
- Fixed missing translations when targeting players.
1.3 (20-Jul-2021)
- Added feature to target individual clients. Thanks to "Lux" for the "TE_SetupParticleAttachment" method and code.
- Changed command "sm_splat" to allow targeting clients.
- Menu still displays the effects to everyone.
1.2 (10-May-2020)
- Added PrecacheParticle function.
- Various changes to tidy up code.
1.1 (05-May-2018)
- Converted plugin source to the latest syntax utilizing methodmaps. Requires SourceMod 1.8 or newer.
1.0 (05-Sep-2010)
- Initial release.
========================================================================================
This plugin was made using source code from the following plugins.
If I have used your code and not credited you, please let me know.
* Thanks to "L. Duke" for " TF2 Particles via TempEnts" tutorial
https://forums.alliedmods.net/showthread.php?t=75102
* Thanks to "Muridias" for updating "L. Duke"s code
https://forums.alliedmods.net/showpost.php?p=836836&postcount=28
* Thanks to "Lux" for the "TE_SetupParticleAttachment" method and code
https://github.com/LuxLuma/Lux-Library/blob/master/scripting/include/lux_library.inc
======================================================================================*/
#pragma semicolon 1
#pragma newdecls required
#include <sourcemod>
#include <sdktools>
#include <sdkhooks>
char g_Particles[19][] =
{
"screen_adrenaline", // Adrenaline
"screen_adrenaline_b",
"screen_hurt",
"screen_hurt_b",
"screen_blood_splatter", // Blood
"screen_blood_splatter_a",
"screen_blood_splatter_b",
"screen_blood_splatter_melee_b",
"screen_blood_splatter_melee",
"screen_blood_splatter_melee_blunt",
"smoker_screen_effect", // Infected
"smoker_screen_effect_b",
"screen_mud_splatter",
"screen_mud_splatter_a",
"screen_bashed", // Misc
"screen_bashed_b",
"screen_bashed_d",
"burning_character_screen",
"storm_lightning_screenglow"
// boomer_vomit_screeneffect // Doesn't work :(
};
ConVar g_hAllow;
bool g_bCvarAllow;
Handle g_hTimerStop[MAXPLAYERS+1];
// ====================================================================================================
// PLUGIN INFO / START / END
// ====================================================================================================
public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
{
EngineVersion test = GetEngineVersion();
if( test != Engine_Left4Dead2 )
{
strcopy(error, err_max, "Plugin only supports Left 4 Dead 2.");
return APLRes_SilentFailure;
}
return APLRes_Success;
}
public Plugin myinfo =
{
name = "[L4D2] Hud Splatter",
author = "SilverShot",
description = "Splat effects on players screen.",
version = PLUGIN_VERSION,
url = "https://forums.alliedmods.net/showthread.php?t=137445"
}
public void OnPluginStart()
{
LoadTranslations("common.phrases");
// Cvars
g_hAllow = CreateConVar("l4d2_hud_splatter", "1", "0=Disables plugin, 1=Enables plugin", FCVAR_NOTIFY);
CreateConVar("l4d2_hud_splatter_version", PLUGIN_VERSION, "Hud Splatter plugin version.", FCVAR_NOTIFY|FCVAR_DONTRECORD);
AutoExecConfig(true, "l4d2_hud_splatter");
g_hAllow.AddChangeHook(ConVarChanged_Enable);
g_bCvarAllow = g_hAllow.BoolValue;
// Console Commands
RegAdminCmd("sm_splat_menu", Command_SplatMenu, ADMFLAG_KICK, "Splat menu.");
RegAdminCmd("sm_splat", Command_Splatter, ADMFLAG_KICK, "Usage: sm_splat <#userid|name> <1-19>");
}
void ConVarChanged_Enable(Handle convar, const char[] oldValue, const char[] newValue)
{
g_bCvarAllow = g_hAllow.BoolValue;
}
public void OnMapStart()
{
for( int i = 0; i < sizeof(g_Particles); i++ )
{
PrecacheParticle(g_Particles[i]);
}
}
// ====================================================================================================
// SPLAT
// ====================================================================================================
void SplatPlayer(int client, int type, bool bAffectAll)
{
int iParticleStringIndex = GetParticleIndex(g_Particles[type]);
if( iParticleStringIndex == INVALID_STRING_INDEX )
{
return;
}
// OLD METHOD:
// AttachParticle(client, g_Particles[type]);
// NEW METHOD
TE_SetupParticleAttachment(iParticleStringIndex, 1, client, true);
if( bAffectAll )
TE_SendToAll();
else
TE_SendToClient(client);
if( type < 4 )
{
if( bAffectAll )
{
delete g_hTimerStop[0];
g_hTimerStop[0] = CreateTimer(10.0, TimerStop, 0);
} else {
delete g_hTimerStop[client];
g_hTimerStop[client] = CreateTimer(10.0, TimerStop, GetClientUserId(client));
}
}
}
Action TimerStop(Handle timer, any client)
{
if( client )
{
client = GetClientOfUserId(client);
if( client && IsClientInGame(client) )
{
TE_SetupStopAllParticles(client);
TE_SendToClient(client);
g_hTimerStop[client] = null;
}
} else {
for( int i = 1; i <= MaxClients; i++ )
{
if( IsClientInGame(i) )
{
TE_SetupStopAllParticles(i);
TE_SendToClient(i);
}
}
g_hTimerStop[client] = null;
}
return Plugin_Continue;
}
public void OnClientDisconnect(int client)
{
delete g_hTimerStop[client];
}
// ====================================================================================================
// COMMANDs
// ====================================================================================================
Action Command_SplatMenu(int client, int args)
{
if( g_bCvarAllow ) Menu_Select(client);
return Plugin_Handled;
}
Action Command_Splatter(int client, int args)
{
if( !g_bCvarAllow ) return Plugin_Handled;
if( args != 2 )
{
ReplyToCommand(client, "Usage: sm_splat <#userid|name> <1-19>");
return Plugin_Handled;
}
// Type
char arg2[4];
GetCmdArg(2, arg2, sizeof(arg2));
int type = StringToInt(arg2);
if( type < 1 || type > 19 )
{
ReplyToCommand(client, "Usage: sm_splat <#userid|name> <1-19>");
return Plugin_Handled;
}
// Target
char arg1[32];
GetCmdArg(1, arg1, sizeof(arg1));
char target_name[MAX_TARGET_LENGTH];
int target_list[MAXPLAYERS], target_count;
bool tn_is_ml;
if( (target_count = ProcessTargetString(
arg1,
client,
target_list,
MAXPLAYERS,
0,
target_name,
sizeof(target_name),
tn_is_ml)) <= 0)
{
ReplyToTargetError(client, target_count);
return Plugin_Handled;
}
// Do
int target;
for( int i = 0; i < target_count; i++ )
{
target = target_list[i];
SplatPlayer(target, type -1, false);
}
return Plugin_Handled;
}
// ====================================================================================================
// MENU MAIN
// ====================================================================================================
// 1. Menu_Select
void Menu_Select(int client)
{
Menu menu = new Menu(MenuHandler_Select);
menu.SetTitle("Select Splatter (Affects everyone):");
menu.AddItem("1", "Adrenaline");
menu.AddItem("2", "Blood");
menu.AddItem("3", "Infected");
menu.AddItem("4", "Miscellaneous");
menu.ExitButton = true;
menu.Display(client, 60);
}
int MenuHandler_Select(Menu menu, MenuAction action, int param1, int param2)
{
if( action == MenuAction_End ) return 0;
if( action == MenuAction_Select )
{
switch( param2 )
{
case 0: Menu_Adren(param1);
case 1: Menu_Blood(param1);
case 2: Menu_Infected(param1);
case 3: Menu_Misc(param1);
}
}
return 0;
}
// ====================================================================================================
// MENUS SELECT
// ====================================================================================================
// Adrenaline
void Menu_Adren(int client)
{
Menu menu = new Menu(MenuHandler_Adren);
menu.SetTitle("Adrenaline Edges");
menu.AddItem("1", "Adrenaline (red)");
menu.AddItem("2", "Adrenaline (dark)");
menu.AddItem("3", "Hurt (red)");
menu.AddItem("4", "Hurt (dark)");
menu.ExitBackButton = true;
menu.Display(client, 60);
}
int MenuHandler_Adren(Menu menu, MenuAction action, int param1, int param2)
{
if( action == MenuAction_End )
{
delete menu;
}
else if( action == MenuAction_Cancel )
{
Menu_Select(param1);
}
else if( action == MenuAction_Select )
{
Menu_Adren(param1);
SplatPlayer(param1, param2, true);
}
return 0;
}
// Blood
void Menu_Blood(int client)
{
Menu menu = new Menu(MenuHandler_Blood);
menu.SetTitle("Blood Splatter");
menu.AddItem("1", "Edge Faded");
menu.AddItem("2", "Center Big");
menu.AddItem("3", "Center Small");
menu.AddItem("4", "Center (melee)");
menu.AddItem("5", "Edge Big (melee)");
menu.AddItem("6", "Edge Small (melee)");
menu.ExitBackButton = true;
menu.Display(client, 60);
}
int MenuHandler_Blood(Menu menu, MenuAction action, int param1, int param2)
{
if( action == MenuAction_End )
{
delete menu;
}
else if( action == MenuAction_Cancel )
{
Menu_Select(param1);
}
else if( action == MenuAction_Select )
{
Menu_Blood(param1);
SplatPlayer(param1, param2 + 4, true);
}
return 0;
}
// Infected
void Menu_Infected(int client)
{
Menu menu = new Menu(MenuHandler_Infected);
menu.SetTitle("Infected");
menu.AddItem("1", "Water (Smoker FX)");
menu.AddItem("2", "Flakes (Smoker FX)");
menu.AddItem("3", "Mud Splatter 1");
menu.AddItem("4", "Mud Splatter 2");
menu.ExitBackButton = true;
menu.Display(client, 60);
}
int MenuHandler_Infected(Menu menu, MenuAction action, int param1, int param2)
{
if( action == MenuAction_End )
{
delete menu;
}
else if( action == MenuAction_Cancel )
{
Menu_Select(param1);
}
else if( action == MenuAction_Select )
{
Menu_Infected(param1);
SplatPlayer(param1, param2 + 10, true);
}
return 0;
}
// Misc
void Menu_Misc(int client)
{
Menu menu = new Menu(MenuHandler_Misc);
menu.SetTitle("Miscellaneous");
menu.AddItem("1", "Big Bash");
menu.AddItem("2", "Bashed");
menu.AddItem("3", "Stars");
menu.AddItem("4", "Flames");
menu.AddItem("5", "Lightning Flash");
menu.ExitBackButton = true;
menu.Display(client, 60);
}
int MenuHandler_Misc(Menu menu, MenuAction action, int param1, int param2)
{
if( action == MenuAction_End )
{
delete menu;
}
else if( action == MenuAction_Cancel )
{
Menu_Select(param1);
}
else if( action == MenuAction_Select )
{
Menu_Misc(param1);
SplatPlayer(param1, param2 + 14, true);
}
return 0;
}
// ====================================================================================================
// PARTICLES
// ====================================================================================================
int PrecacheParticle(const char[] sEffectName)
{
static int table = INVALID_STRING_TABLE;
if( table == INVALID_STRING_TABLE )
{
table = FindStringTable("ParticleEffectNames");
}
int index = FindStringIndex(table, sEffectName);
if( index == INVALID_STRING_INDEX )
{
bool save = LockStringTables(false);
AddToStringTable(table, sEffectName);
LockStringTables(save);
index = FindStringIndex(table, sEffectName);
}
return index;
}
/**
* Sets up a particle effect's attachment.
*
* @param iParticleIndex Particle index.
* @param sAttachmentName Name of attachment.
* @param iEntIndex Entity index of the particle.
* @param bFollow True to make the particle follow attachment points, false otherwise.
*
* @error Invalid effect index.
**/
stock void TE_SetupParticleAttachment(int iParticleIndex, int iAttachmentIndex, int iEntIndex, bool bFollow=false)
{
static float vecDummy[3]={0.0, 0.0, 0.0};
static EngineVersion IsEngine;
if(IsEngine == Engine_Unknown)
IsEngine = GetEngineVersion();
TE_Start("EffectDispatch");
TE_WriteFloat(IsEngine == Engine_Left4Dead2 ? "m_vOrigin.x" :"m_vOrigin[0]", vecDummy[0]);
TE_WriteFloat(IsEngine == Engine_Left4Dead2 ? "m_vOrigin.y" :"m_vOrigin[1]", vecDummy[1]);
TE_WriteFloat(IsEngine == Engine_Left4Dead2 ? "m_vOrigin.z" :"m_vOrigin[2]", vecDummy[2]);
TE_WriteFloat(IsEngine == Engine_Left4Dead2 ? "m_vStart.x" :"m_vStart[0]", vecDummy[0]);
TE_WriteFloat(IsEngine == Engine_Left4Dead2 ? "m_vStart.y" :"m_vStart[1]", vecDummy[1]);
TE_WriteFloat(IsEngine == Engine_Left4Dead2 ? "m_vStart.z" :"m_vStart[2]", vecDummy[2]);
static int iEffectIndex = INVALID_STRING_INDEX;
if(iEffectIndex < 0)
{
iEffectIndex = __FindStringIndex2(FindStringTable("EffectDispatch"), "ParticleEffect");
if(iEffectIndex == INVALID_STRING_INDEX)
SetFailState("Unable to find EffectDispatch/ParticleEffect indexes");
}
TE_WriteNum("m_iEffectName", iEffectIndex);
TE_WriteNum("m_nHitBox", iParticleIndex);
TE_WriteNum("entindex", iEntIndex);
TE_WriteNum("m_nAttachmentIndex", iAttachmentIndex);
TE_WriteNum("m_fFlags", 1); //needed for attachments to work
TE_WriteVector("m_vAngles", vecDummy);
TE_WriteFloat("m_flMagnitude", 0.0);
TE_WriteFloat("m_flScale", 1.0);
TE_WriteFloat("m_flRadius", 0.0);
if(IsEngine == Engine_Left4Dead2)
{
TE_WriteNum("m_nDamageType", bFollow ? 5 : 4);
}
else
{
TE_WriteNum("m_nDamageType", bFollow ? 4 : 3);
}
}
/**
* Stops all particle effects emitted on an entity, such as attachment followers.
* Note: Currently no way to target particles.
*
* @param iEntIndex Entity index to stop all particles from emitting on.
*
* @error Invalid effect index.
**/
void TE_SetupStopAllParticles(int iEntIndex)
{
static float vecDummy[3]={0.0, 0.0, 0.0};
static EngineVersion IsEngine;
if(IsEngine == Engine_Unknown)
IsEngine = GetEngineVersion();
TE_Start("EffectDispatch");
TE_WriteFloat(IsEngine == Engine_Left4Dead2 ? "m_vOrigin.x" :"m_vOrigin[0]", vecDummy[0]);
TE_WriteFloat(IsEngine == Engine_Left4Dead2 ? "m_vOrigin.y" :"m_vOrigin[1]", vecDummy[1]);
TE_WriteFloat(IsEngine == Engine_Left4Dead2 ? "m_vOrigin.z" :"m_vOrigin[2]", vecDummy[2]);
TE_WriteFloat(IsEngine == Engine_Left4Dead2 ? "m_vStart.x" :"m_vStart[0]", vecDummy[0]);
TE_WriteFloat(IsEngine == Engine_Left4Dead2 ? "m_vStart.y" :"m_vStart[1]", vecDummy[1]);
TE_WriteFloat(IsEngine == Engine_Left4Dead2 ? "m_vStart.z" :"m_vStart[2]", vecDummy[2]);
static int iEffectIndex = INVALID_STRING_INDEX;
if(iEffectIndex < 0)
{
iEffectIndex = __FindStringIndex2(FindStringTable("EffectDispatch"), "ParticleEffectStop");
if(iEffectIndex == INVALID_STRING_INDEX)
SetFailState("Unable to find EffectDispatch/ParticleEffectStop indexes");
}
TE_WriteNum("m_iEffectName", iEffectIndex);
TE_WriteNum("m_nHitBox", 0);
TE_WriteNum("entindex", iEntIndex);
TE_WriteNum("m_nAttachmentIndex", 0);
TE_WriteNum("m_fFlags", 1);
TE_WriteVector("m_vAngles", vecDummy);
TE_WriteFloat("m_flMagnitude", 0.0);
TE_WriteFloat("m_flScale", 0.0);
TE_WriteFloat("m_flRadius", 0.0);
TE_WriteNum("m_nDamageType", 0);
}
/**
* Gets a particle system index or late precaches it.
* Note: Cache particle systems in OnMapStart() with Precache_Particle_System to avoid them spewing errors.
*
* @param sParticleName Name of the particle system.
*
* @return The particle system index or INVALID_STRING_INDEX on error.
* @error Invalid particle stringtable index.
**/
int GetParticleIndex(char[] sParticleName)
{
static int iParticleTableid = INVALID_STRING_TABLE;
if(iParticleTableid == INVALID_STRING_TABLE)
{
iParticleTableid = FindStringTable("ParticleEffectNames");
if(iParticleTableid == INVALID_STRING_TABLE)
SetFailState("Failed to find 'ParticleEffectNames' stringtable.");
}
int iParticleStringIndex = __FindStringIndex2(iParticleTableid, sParticleName);
if(iParticleStringIndex == INVALID_STRING_INDEX)
{
iParticleStringIndex = PrecacheParticle(sParticleName);
}
return iParticleStringIndex;
}
//Credit smlib https://github.com/bcserv/smlib
/**
* Rewrite of FindStringIndex, which failed to work correctly in previous tests.
* Searches for the index of a given string in a stringtable.
*
* @param tableidx Stringtable index.
* @param str String to find.
* @return The string index or INVALID_STRING_INDEX on error.
**/
int __FindStringIndex2(int tableidx, const char[] str)
{
static char buf[1024];
int numStrings = GetStringTableNumStrings(tableidx);
for (int i=0; i < numStrings; i++) {
ReadStringTable(tableidx, i, buf, sizeof(buf));
if (StrEqual(buf, str)) {
return i;
}
}
return INVALID_STRING_INDEX;
}
// OLD METHOD:
/*
stock void AttachParticle(int client, char[] particleType)
{
int entity = CreateEntityByName("info_particle_system");
if( IsValidEdict(entity) )
{
DispatchKeyValue(entity, "effect_name", particleType);
DispatchSpawn(entity)
SetVariantString("!activator");
AcceptEntityInput(entity, "SetParent", client);
ActivateEntity(entity);
AcceptEntityInput(entity, "start");
SetVariantString("OnUser1 !self:Kill::10.0:1");
AcceptEntityInput(entity, "AddOutput");
AcceptEntityInput(entity, "FireUser1");
}
}
*/