forked from SilvDev/Various_Scripts_Collection
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathl4d2_cola.sp
More file actions
1714 lines (1431 loc) · 52.6 KB
/
l4d2_cola.sp
File metadata and controls
1714 lines (1431 loc) · 52.6 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
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Healing Cola
* 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.14"
/*======================================================================================
Plugin Info:
* Name : [L4D2] Healing Cola
* Author : SilverShot
* Descrp : Heals players with temporary or main health when they hold the Cola.
* Link : https://forums.alliedmods.net/showthread.php?t=181518
* Plugins : https://sourcemod.net/plugins.php?exact=exact&sortby=title&search=1&author=Silvers
========================================================================================
Change Log:
1.14 (03-Oct-2022)
- Added cvar "l4d2_cola_time" to control how often to heal someone holding a gnome.
- Now uses the "m_iMaxHealth" value instead of the "MAX_MAIN_HEALTH" define. Thanks to "Haigen" for changing.
- Now checks if a Survivor is pinned to allow or disallow healing. Thanks to "Haigen" for fixing.
- Removed unused define "MAX_INCAP_HEALTH" - uses the games "survivor_incap_health" cvar value.
1.13 (15-Sep-2021)
- Added cvar "l4d2_cola_healing_field_self" to determine if the Healing Field can heal yourself or not.
- Changed cvar "l4d2_cola_temp" to be a chance of giving temporary health.
- Fixed Healing Field not healing players with the cvar specified amount. Thanks to "Maur0" for the reporting.
1.12 (12-Sep-2021)
- Re-wrote the heal client logic. Fixing various issues when reaching limits.
- Now has two defines in the source code to set maximum health. MAX_INCAP_HEALTH for incap temp health. MAX_MAIN_HEALTH inclues main and temp health.
- Various fixes brought over from "Healing Gnome" plugin.
1.11 (30-Aug-2021)
- Added cvars "l4d2_cola_max_main" and "l4d2_cola_max_temp" to control the maximum main and temporary health allowed to heal to.
- Fixed cvar "l4d2_cola_heal" when set to "0" not allowing the healing field feature to work. Again.
- Fixed losing temporary health when the limit was reached. Thanks to "Shao" for reporting.
- Now ignores healing the holder with the standard healing when healing field is enabled.
1.10 (06-Jun-2021)
- Fixed cvar "l4d2_cola_heal" when set to "0" not allowing the Healing Field feature to work. Thanks to "ddd123" for reporting.
1.9 (02-Apr-2021)
- Healing Field update - by "Marttt":
- This enables healing around a person carrying the Cola. Uses the same healing field effect like the "Medic" grenade from "Prototype Grenades" plugin.
- Added cvars:
"l4d2_cola_healing_field", "l4d2_cola_healing_field_refresh_time", "l4d2_cola_healing_field_heal_amount", "l4d2_cola_healing_field_heal_amount_incap",
"l4d2_cola_healing_field_heal_beacon", "l4d2_cola_healing_field_color", "l4d2_cola_healing_field_start_radius", "l4d2_cola_healing_field_end_radius",
"l4d2_cola_healing_field_duration", "l4d2_cola_healing_field_width", "l4d2_cola_healing_field_amplitude".
- See threads main post for details on the cvars.
1.8 (31-Mar-2021)
- Changed cvar "l4d2_cola_full" to give full health and remove the black and white effect, either on temporary or main health.
1.7 (29-Mar-2021)
- Added cvar "l4d2_cola_full" to give full health and remove the black and white effect. Requested by "weffer" and "Tonblader".
1.6 (14-Aug-2020)
- Fixed heal timer duplicating. Thanks to "Electr000999" for reporting.
1.5 (10-May-2020)
- Extra checks to prevent "IsAllowedGameMode" throwing errors.
- Various changes to tidy up code.
1.4 (01-Apr-2020)
- Fixed "IsAllowedGameMode" from throwing errors when the "_tog" cvar was changed before MapStart.
1.3 (05-May-2018)
- Converted plugin source to the latest syntax utilizing methodmaps. Requires SourceMod 1.8 or newer.
1.2 (21-Jul-2013)
- Removed Sort_Random work-around. This was fixed in SourceMod 1.4.7, all should update or spawning issues will occur.
1.1 (01-Jul-2012)
- Added cvars "l4d2_cola_glow" and "l4d2_cola_glow_color" to make the cola glow.
- Fixed healing players above 100 HP.
1.0 (30-Mar-2012)
- Initial release.
========================================================================================
Thanks:
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.
* "Zuko & McFlurry" for "[L4D2] Weapon/Zombie Spawner" - Modified SetTeleportEndPoint function.
https://forums.alliedmods.net/showthread.php?t=109659
======================================================================================*/
#pragma semicolon 1
#pragma newdecls required
#include <sourcemod>
#include <sdktools>
#define CVAR_FLAGS FCVAR_NOTIFY
#define CHAT_TAG "\x04[\x05Cola\x04] \x01"
#define CONFIG_SPAWNS "data/l4d2_cola.cfg"
#define MAX_COLAS 32
#define MODEL_COLA "models/w_models/weapons/w_cola.mdl"
Handle g_hTimerHeal;
Menu g_hMenuAng, g_hMenuPos;
ConVar g_hCvarAllow, g_hCvarDecayRate, g_hCvarGlow, g_hCvarGlowCol, g_hCvarFull, g_hCvarHeal, g_hCvarMaxM, g_hCvarMaxT, g_hCvarMPGameMode, g_hCvarModes, g_hCvarModesOff, g_hCvarModesTog, g_hCvarRandom, g_hCvarRate, g_hCvarSafe, g_hCvarTemp, g_hCvarTime;
int g_iColaCount, g_iCola[MAXPLAYERS+1], g_iColas[MAX_COLAS][2], g_iCvarGlow, g_iCvarGlowCol, g_iCvarFull, g_iCvarHeal, g_iCvarMaxM, g_iCvarRandom, g_iCvarSafe, g_iCvarTemp, g_iMap, g_iPlayerSpawn, g_iRoundStart;
bool g_bCvarAllow, g_bMapStarted, g_bLoaded;
float g_fCvarMaxT, g_fCvarDecayRate, g_fCvarRate, g_fCvarTime, g_fHealTime[MAXPLAYERS+1];
// Healing Field stuff:
#define SPRITE_BEAM "materials/sprites/laserbeam.vmt"
#define SPRITE_HALO "materials/sprites/glow01.vmt"
#define DIST_TOLERANCE 25.0
Handle g_hTimerHealingField;
ConVar g_hCvarIncapHealth, g_hCvarField, g_hCvarFieldRefreshTime, g_hCvarFieldHealAmount, g_hCvarFieldHealAmountIncap, g_hCvarFieldHealSelf, g_hCvarFieldBeacon, g_hCvarFieldColor, g_hCvarFieldStartRadius, g_hCvarFieldEndRadius, g_hCvarFieldDuration, g_hCvarFieldWidth, g_hCvarFieldAmplitude;
int g_iBeamSprite, g_iHaloSprite, g_iCvarIncapHealth, g_iCvarFieldColor[4];
bool g_bCvarField, g_bCvarFieldHealSelf, g_bCvarFieldBeacon, g_bCvarFieldColorRandom;
float g_fCvarFieldRefreshTime, g_fCvarFieldHealAmount, g_fCvarFieldHealAmountIncap, g_fCvarFieldStartRadius, g_fCvarFieldEndRadius, g_fCvarFieldDuration, g_fCvarFieldWidth, g_fCvarFieldAmplitude;
char g_sCvarFieldColor[12];
// ====================================================================================================
// PLUGIN INFO / START / END
// ====================================================================================================
public Plugin myinfo =
{
name = "[L4D2] Healing Cola",
author = "SilverShot",
description = "Heals players with temporary or main health when they hold the Cola.",
version = PLUGIN_VERSION,
url = "https://forums.alliedmods.net/showthread.php?t=181518"
}
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 void OnPluginStart()
{
g_hCvarAllow = CreateConVar( "l4d2_cola_allow", "1", "0=Plugin off, 1=Plugin on.", CVAR_FLAGS );
g_hCvarGlow = CreateConVar( "l4d2_cola_glow", "200", "0=Off. Sets the max range at which the cola glows.", CVAR_FLAGS );
g_hCvarGlowCol = CreateConVar( "l4d2_cola_glow_color", "255 0 0", "0=Default glow color. Three values between 0-255 separated by spaces. RGB: Red Green Blue.", CVAR_FLAGS );
g_hCvarFull = CreateConVar( "l4d2_cola_full", "0", "0=Off, Remove black and white effect and give full health when regenerated to 100 with: 1=Temporary health. 2=Main health.", CVAR_FLAGS );
g_hCvarHeal = CreateConVar( "l4d2_cola_heal", "1", "0=Off, 1=Heal players holding the cola.", CVAR_FLAGS );
g_hCvarMaxM = CreateConVar( "l4d2_cola_max_main", "100", "Maximum main health to heal clients to.", CVAR_FLAGS );
g_hCvarMaxT = CreateConVar( "l4d2_cola_max_temp", "100.0", "Maximum temporary health to heal clients to.", CVAR_FLAGS );
g_hCvarModes = CreateConVar( "l4d2_cola_modes", "", "Turn on the plugin in these game modes, separate by commas (no spaces). (Empty = all).", CVAR_FLAGS );
g_hCvarModesOff = CreateConVar( "l4d2_cola_modes_off", "", "Turn off the plugin in these game modes, separate by commas (no spaces). (Empty = none).", CVAR_FLAGS );
g_hCvarModesTog = CreateConVar( "l4d2_cola_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_hCvarRandom = CreateConVar( "l4d2_cola_random", "-1", "-1=All, 0=None. Otherwise randomly select this many colas to spawn from the maps config.", CVAR_FLAGS );
g_hCvarRate = CreateConVar( "l4d2_cola_rate", "1.5", "The rate at which players are healed. HP per second.", CVAR_FLAGS );
g_hCvarSafe = CreateConVar( "l4d2_cola_safe", "0", "On round start spawn the cola: 0=Off, 1=In the saferoom, 2=Equip to random player.", CVAR_FLAGS );
g_hCvarTemp = CreateConVar( "l4d2_cola_temp", "5", "-1=Add temporary health, 0=Add to main health. Values between 1 and 100 creates a chance to give temp health, else main health.", CVAR_FLAGS );
g_hCvarTime = CreateConVar( "l4d2_cola_time", "1.0", "0=Off. Interval in seconds, for healing someone holding the cola.", CVAR_FLAGS );
g_hCvarField = CreateConVar( "l4d2_cola_healing_field", "1", "0=Off. 1=Heal players around the player holding the cola.", CVAR_FLAGS, true, 0.0, true, 1.0 );
g_hCvarFieldRefreshTime = CreateConVar( "l4d2_cola_healing_field_refresh_time", "1.5", "0=Off. Interval in seconds, for the healing field trigger the heal and beacon again.", CVAR_FLAGS, true, 0.0 );
g_hCvarFieldHealAmount = CreateConVar( "l4d2_cola_healing_field_heal_amount", "2.0", "Heal amount from being inside the healing field.", CVAR_FLAGS, true, 0.0 );
g_hCvarFieldHealAmountIncap = CreateConVar( "l4d2_cola_healing_field_heal_amount_incap", "2.0", "Heal amount for incapped players from being inside the healing field.", CVAR_FLAGS, true, 0.0 );
g_hCvarFieldHealSelf = CreateConVar( "l4d2_cola_healing_field_self", "0", "0=Only healing others. 1=Heal £ and others.", CVAR_FLAGS );
g_hCvarFieldBeacon = CreateConVar( "l4d2_cola_healing_field_heal_beacon", "1", "0=Off. 1=Generates a beacon.", CVAR_FLAGS, true, 0.0, true, 1.0 );
g_hCvarFieldColor = CreateConVar( "l4d2_cola_healing_field_color", "0 255 0", "Healing field color. Three values between 0-255 separated by spaces. RGB: Red Green Blue.\nUse \"random\" to generate random colors.", CVAR_FLAGS );
g_hCvarFieldStartRadius = CreateConVar( "l4d2_cola_healing_field_start_radius", "100.0", "Healing field start radius.", CVAR_FLAGS, true, 0.0 );
g_hCvarFieldEndRadius = CreateConVar( "l4d2_cola_healing_field_end_radius", "350.0", "Healing field end radius. Also determines the max distance to heal players around the player holding the cola.\nMax distance = (l4d2_cola_healing_field_end_radius / 2) because of the diameter.", CVAR_FLAGS, true, 0.0 );
g_hCvarFieldDuration = CreateConVar( "l4d2_cola_healing_field_duration", "1.0", "How many seconds the healing field should last.", CVAR_FLAGS, true, 0.0 );
g_hCvarFieldWidth = CreateConVar( "l4d2_cola_healing_field_width", "3.0", "Healing field width.", CVAR_FLAGS, true, 0.0 );
g_hCvarFieldAmplitude = CreateConVar( "l4d2_cola_healing_field_amplitude", "0.0", "Healing field amplitude.", CVAR_FLAGS, true, 0.0 );
CreateConVar( "l4d2_cola_version", PLUGIN_VERSION, "Healing Cola plugin version.", FCVAR_NOTIFY|FCVAR_DONTRECORD);
AutoExecConfig(true, "l4d2_cola");
g_hCvarDecayRate = FindConVar("pain_pills_decay_rate");
g_hCvarMPGameMode = FindConVar("mp_gamemode");
g_hCvarMPGameMode.AddChangeHook(ConVarChanged_Allow);
g_hCvarAllow.AddChangeHook(ConVarChanged_Allow);
g_hCvarModes.AddChangeHook(ConVarChanged_Allow);
g_hCvarModesOff.AddChangeHook(ConVarChanged_Allow);
g_hCvarModesTog.AddChangeHook(ConVarChanged_Allow);
g_hCvarFull.AddChangeHook(ConVarChanged_Cvars);
g_hCvarHeal.AddChangeHook(ConVarChanged_Cvars);
g_hCvarMaxM.AddChangeHook(ConVarChanged_Cvars);
g_hCvarMaxT.AddChangeHook(ConVarChanged_Cvars);
g_hCvarRandom.AddChangeHook(ConVarChanged_Cvars);
g_hCvarRate.AddChangeHook(ConVarChanged_Cvars);
g_hCvarSafe.AddChangeHook(ConVarChanged_Cvars);
g_hCvarTemp.AddChangeHook(ConVarChanged_Cvars);
g_hCvarTime.AddChangeHook(ConVarChanged_Cvars);
g_hCvarDecayRate.AddChangeHook(ConVarChanged_Cvars);
g_hCvarIncapHealth = FindConVar("survivor_incap_health");
g_hCvarIncapHealth.AddChangeHook(ConVarChanged_Cvars);
g_hCvarField.AddChangeHook(ConVarChanged_Cvars);
g_hCvarFieldRefreshTime.AddChangeHook(ConVarChanged_Cvars);
g_hCvarFieldHealAmount.AddChangeHook(ConVarChanged_Cvars);
g_hCvarFieldHealAmountIncap.AddChangeHook(ConVarChanged_Cvars);
g_hCvarFieldHealSelf.AddChangeHook(ConVarChanged_Cvars);
g_hCvarFieldBeacon.AddChangeHook(ConVarChanged_Cvars);
g_hCvarFieldColor.AddChangeHook(ConVarChanged_Cvars);
g_hCvarFieldStartRadius.AddChangeHook(ConVarChanged_Cvars);
g_hCvarFieldEndRadius.AddChangeHook(ConVarChanged_Cvars);
g_hCvarFieldDuration.AddChangeHook(ConVarChanged_Cvars);
g_hCvarFieldWidth.AddChangeHook(ConVarChanged_Cvars);
g_hCvarFieldAmplitude.AddChangeHook(ConVarChanged_Cvars);
RegAdminCmd("sm_cola", CmdColaTemp, ADMFLAG_ROOT, "Spawns a temporary cola at your crosshair.");
RegAdminCmd("sm_colasave", CmdColaSave, ADMFLAG_ROOT, "Spawns a cola at your crosshair and saves to config.");
RegAdminCmd("sm_coladel", CmdColaDelete, ADMFLAG_ROOT, "Removes the cola you are pointing at and deletes from the config if saved.");
RegAdminCmd("sm_colawipe", CmdColaWipe, ADMFLAG_ROOT, "Removes all colas from the current map and deletes them from the config.");
RegAdminCmd("sm_colaglow", CmdColaGlow, ADMFLAG_ROOT, "Toggle to enable glow on all colas to see where they are placed.");
RegAdminCmd("sm_colalist", CmdColaList, ADMFLAG_ROOT, "Display a list cola positions and the total number of.");
RegAdminCmd("sm_colatele", CmdColaTele, ADMFLAG_ROOT, "Teleport to a cola (Usage: sm_colatele <index: 1 to MAX_COLAS>).");
RegAdminCmd("sm_colaang", CmdColaAng, ADMFLAG_ROOT, "Displays a menu to adjust the cola angles your crosshair is over.");
RegAdminCmd("sm_colapos", CmdColaPos, ADMFLAG_ROOT, "Displays a menu to adjust the cola origin your crosshair is over.");
}
public void OnPluginEnd()
{
ResetPlugin();
}
public void OnMapStart()
{
g_bMapStarted = true;
PrecacheModel(MODEL_COLA, true);
g_iBeamSprite = PrecacheModel(SPRITE_BEAM, true);
g_iHaloSprite = PrecacheModel(SPRITE_HALO, true);
}
public void OnMapEnd()
{
g_iMap = 1;
g_bMapStarted = false;
ResetPlugin(false);
}
int GetColor(ConVar hCvar)
{
char sTemp[12];
hCvar.GetString(sTemp, sizeof(sTemp));
if( sTemp[0] == 0 )
return 0;
char sColors[3][4];
int color = ExplodeString(sTemp, " ", sColors, sizeof(sColors), sizeof(sColors[]));
if( color != 3 )
return 0;
color = StringToInt(sColors[0]);
color += 256 * StringToInt(sColors[1]);
color += 65536 * StringToInt(sColors[2]);
return color;
}
int[] GetColors(char[] sColor)
{
int colors[4];
if( sColor[0] == 0 )
return colors;
char sColors[3][4];
int color = ExplodeString(sColor, " ", sColors, sizeof(sColors), sizeof(sColors[]));
if( color != 3 )
return colors;
colors[0] = StringToInt(sColors[0]);
colors[1] = StringToInt(sColors[1]);
colors[2] = StringToInt(sColors[2]);
colors[3] = 255;
return colors;
}
int[] GetRandomColors()
{
int colors[4];
colors[0] = GetRandomInt(0, 255);
colors[1] = GetRandomInt(0, 255);
colors[2] = GetRandomInt(0, 255);
colors[3] = 255;
return colors;
}
// ====================================================================================================
// 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_iCvarGlow = g_hCvarGlow.IntValue;
g_iCvarGlowCol = GetColor(g_hCvarGlowCol);
g_iCvarFull = g_hCvarFull.IntValue;
g_iCvarHeal = g_hCvarHeal.IntValue;
g_iCvarMaxM = g_hCvarMaxM.IntValue;
g_fCvarMaxT = g_hCvarMaxT.FloatValue;
g_iCvarRandom = g_hCvarRandom.IntValue;
g_fCvarRate = g_hCvarRate.FloatValue;
g_iCvarSafe = g_hCvarSafe.IntValue;
g_iCvarTemp = g_hCvarTemp.IntValue;
g_fCvarTime = g_hCvarTime.FloatValue;
g_fCvarDecayRate = g_hCvarDecayRate.FloatValue;
g_iCvarIncapHealth = g_hCvarIncapHealth.IntValue;
g_bCvarField = g_hCvarField.BoolValue;
g_fCvarFieldRefreshTime = g_hCvarFieldRefreshTime.FloatValue;
g_fCvarFieldHealAmount = g_hCvarFieldHealAmount.FloatValue;
g_fCvarFieldHealAmountIncap = g_hCvarFieldHealAmountIncap.FloatValue;
g_bCvarFieldHealSelf = g_hCvarFieldHealSelf.BoolValue;
g_bCvarFieldBeacon = g_hCvarFieldBeacon.BoolValue;
g_hCvarFieldColor.GetString(g_sCvarFieldColor, sizeof(g_sCvarFieldColor));
g_bCvarFieldColorRandom = StrEqual(g_sCvarFieldColor, "random");
g_iCvarFieldColor = GetColors(g_sCvarFieldColor);
g_fCvarFieldStartRadius = g_hCvarFieldStartRadius.FloatValue;
g_fCvarFieldEndRadius = g_hCvarFieldEndRadius.FloatValue;
g_fCvarFieldDuration = g_hCvarFieldDuration.FloatValue;
g_fCvarFieldWidth = g_hCvarFieldWidth.FloatValue;
g_fCvarFieldAmplitude = g_hCvarFieldAmplitude.FloatValue;
}
void IsAllowed()
{
bool bCvarAllow = g_hCvarAllow.BoolValue;
bool bAllowMode = IsAllowedGameMode();
GetCvars();
if( g_bCvarAllow == false && bCvarAllow == true && bAllowMode == true )
{
g_bCvarAllow = true;
LoadColas();
HookEvent("round_end", Event_RoundEnd, EventHookMode_PostNoCopy);
HookEvent("round_start", Event_RoundStart, EventHookMode_PostNoCopy);
HookEvent("player_spawn", Event_PlayerSpawn, EventHookMode_PostNoCopy);
HookEvent("item_pickup", Event_ItemPickup);
}
else if( g_bCvarAllow == true && (bCvarAllow == false || bAllowMode == false) )
{
ResetPlugin();
g_bCvarAllow = false;
UnhookEvent("round_end", Event_RoundEnd, EventHookMode_PostNoCopy);
UnhookEvent("round_start", Event_RoundStart, EventHookMode_PostNoCopy);
UnhookEvent("player_spawn", Event_PlayerSpawn, EventHookMode_PostNoCopy);
UnhookEvent("item_pickup", Event_ItemPickup);
}
}
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
// ====================================================================================================
void Event_RoundEnd(Event event, const char[] name, bool dontBroadcast)
{
ResetPlugin(false);
}
void Event_RoundStart(Event event, const char[] name, bool dontBroadcast)
{
if( g_iPlayerSpawn == 1 && g_iRoundStart == 0 )
CreateTimer(g_iMap == 1 ? 5.0 : 1.0, TimerStart, _, TIMER_FLAG_NO_MAPCHANGE);
g_iRoundStart = 1;
}
void Event_PlayerSpawn(Event event, const char[] name, bool dontBroadcast)
{
if( g_iPlayerSpawn == 0 && g_iRoundStart == 1 )
CreateTimer(g_iMap == 1 ? 5.0 : 1.0, TimerStart, _, TIMER_FLAG_NO_MAPCHANGE);
g_iPlayerSpawn = 1;
}
Action TimerStart(Handle timer)
{
g_iMap = 0;
ResetPlugin();
LoadColas();
if( g_iCvarSafe == 1 )
{
int iClients[MAXPLAYERS+1], count;
for( int i = 1; i <= MaxClients; i++ )
if( IsClientInGame(i) && GetClientTeam(i) == 2 && IsPlayerAlive(i) )
iClients[count++] = i;
int client = GetRandomInt(0, count-1);
client = iClients[client];
if( client )
{
float vPos[3], vAng[3];
GetClientAbsOrigin(client, vPos);
GetClientAbsAngles(client, vAng);
vPos[2] += 25.0;
CreateCola(vPos, vAng);
}
}
else if( g_iCvarSafe == 2 )
{
int iClients[MAXPLAYERS+1], count;
for( int i = 1; i <= MaxClients; i++ )
if( IsClientInGame(i) && GetClientTeam(i) == 2 && IsPlayerAlive(i) )
iClients[count++] = i;
int client = GetRandomInt(0, count-1);
client = iClients[client];
if( client )
{
int entity = GivePlayerItem(client, "weapon_cola_bottles");
if( entity != -1 )
EquipPlayerWeapon(client, entity);
}
}
return Plugin_Continue;
}
void Event_ItemPickup(Event event, const char[] name, bool dontBroadcast)
{
if( g_iCvarHeal || g_bCvarField )
{
char sTemp[16];
event.GetString("item", sTemp, sizeof(sTemp));
if( strcmp(sTemp, "cola_bottles") == 0 )
{
int client = GetClientOfUserId(event.GetInt("userid"));
g_iCola[client] = GetEntPropEnt(client, Prop_Send, "m_hActiveWeapon");
if( g_iCvarHeal && g_hTimerHeal == null )
{
g_hTimerHeal = CreateTimer(g_fCvarTime, TimerHeal, _, TIMER_REPEAT);
}
if( g_bCvarField && g_hTimerHealingField == null )
{
g_hTimerHealingField = CreateTimer(g_fCvarFieldRefreshTime, TimerHealingField, _, TIMER_REPEAT);
}
}
}
}
Action TimerHeal(Handle timer)
{
int entity;
bool healed;
if( g_iCvarHeal )
{
for( int i = 1; i <= MaxClients; i++ )
{
entity = g_iCola[i];
if( entity )
{
if( IsClientInGame(i) && IsPlayerAlive(i) && entity == GetEntPropEnt(i, Prop_Send, "m_hActiveWeapon") && !IsPinned(i) )
{
HealClient(i);
healed = true;
}
else
g_iCola[i] = 0;
}
}
}
if( healed == false )
{
g_hTimerHeal = null;
return Plugin_Stop;
}
return Plugin_Continue;
}
void HealClient(int client)
{
int iHealth = GetClientHealth(client);
int iMaxHealth = GetEntProp(client, Prop_Send, "m_iMaxHealth");
float fGameTime = GetGameTime();
float fHealthTime = GetEntPropFloat(client, Prop_Send, "m_healthBufferTime");
float fHealth = GetEntPropFloat(client, Prop_Send, "m_healthBuffer");
fHealth -= (fGameTime - fHealthTime) * g_fCvarDecayRate;
// Heal temp health
if( g_iCvarTemp == -1 || (g_iCvarTemp != 0 && GetRandomInt(1, 100) <= g_iCvarTemp) )
{
if( fHealth < 0.0 )
fHealth = 0.0;
// How much temp health to give
float fBuff = (0.1 * g_fCvarRate);
fHealth += fBuff;
// Maximum health reached, do we full heal?
if( g_iCvarFull == 1 && fHealth >= g_fCvarMaxT )
{
HealPlayer(client);
SetEntPropFloat(client, Prop_Send, "m_healthBuffer", 0.0);
SetEntPropFloat(client, Prop_Send, "m_healthBufferTime", fGameTime);
}
// Reached maximum health
else if( iHealth + fHealth >= iMaxHealth )
{
// Heal to max allowed temp, or to max main health
if( fHealth >= g_fCvarMaxT )
SetEntPropFloat(client, Prop_Send, "m_healthBuffer", g_fCvarMaxT);
else
SetEntPropFloat(client, Prop_Send, "m_healthBuffer", float(iMaxHealth - iHealth));
SetEntPropFloat(client, Prop_Send, "m_healthBufferTime", fGameTime);
}
// Temp buff is less than maximum allowed
else if( fHealth < g_fCvarMaxT )
{
SetEntPropFloat(client, Prop_Send, "m_healthBuffer", fHealth);
SetEntPropFloat(client, Prop_Send, "m_healthBufferTime", fGameTime);
}
}
else
{
// Heal main health
if( fGameTime - g_fHealTime[client] > g_fCvarTime )
{
g_fHealTime[client] = fGameTime;
int iBuff = RoundToFloor(g_fCvarRate);
iHealth += iBuff;
if( g_iCvarFull == 2 && iHealth >= g_iCvarMaxM )
{
HealPlayer(client);
SetEntPropFloat(client, Prop_Send, "m_healthBuffer", 0.0);
SetEntPropFloat(client, Prop_Send, "m_healthBufferTime", fGameTime);
}
else if( iHealth >= iMaxHealth )
{
iHealth = iMaxHealth;
SetEntPropFloat(client, Prop_Send, "m_healthBuffer", 0.0);
SetEntPropFloat(client, Prop_Send, "m_healthBufferTime", fGameTime);
}
else if( iHealth + fHealth >= iMaxHealth )
{
SetEntPropFloat(client, Prop_Send, "m_healthBuffer", float(iMaxHealth - iHealth));
SetEntPropFloat(client, Prop_Send, "m_healthBufferTime", fGameTime);
}
if( iHealth <= g_iCvarMaxM && iHealth <= iMaxHealth )
{
SetEntityHealth(client, iHealth);
}
}
}
}
// ====================================================================================================
// HEALING FIELD
// ====================================================================================================
Action TimerHealingField(Handle timer)
{
if( !g_bCvarField )
{
g_hTimerHealingField = null;
return Plugin_Stop;
}
int entity;
bool healed;
for( int i = 1; i <= MaxClients; i++ )
{
entity = g_iCola[i];
if( entity )
{
if( IsClientInGame(i) && IsPlayerAlive(i) && entity == GetEntPropEnt(i, Prop_Send, "m_hActiveWeapon") )
{
float vPos[3];
GetEntPropVector(i, Prop_Data, "m_vecAbsOrigin", vPos);
if( g_bCvarFieldBeacon )
CreateBeamRing(vPos);
HealingField(i, vPos);
healed = true;
}
else
g_iCola[i] = 0;
}
}
if( healed == false )
{
g_hTimerHealingField = null;
return Plugin_Stop;
}
return Plugin_Continue;
}
void HealingField(int healer, float vPos[3])
{
for( int i = 1; i <= MaxClients; i++ )
{
if( !g_bCvarFieldHealSelf && i == healer )
continue;
if( IsClientInGame(i) && GetClientTeam(i) == 2 && IsPlayerAlive(i) && !IsPinned(i) )
{
float vEnd[3];
GetEntPropVector(i, Prop_Data, "m_vecAbsOrigin", vEnd);
if( (GetVectorDistance(vPos, vEnd) - DIST_TOLERANCE) <= (g_fCvarFieldEndRadius / 2) )
HealClientOnHealingField(i);
}
}
}
void HealClientOnHealingField(int client)
{
bool bIsIncap = (GetEntProp(client, Prop_Send, "m_isIncapacitated") == 1);
if( bIsIncap )
{
int iHealth = GetClientHealth(client);
if( iHealth >= g_iCvarIncapHealth )
return;
int iBuff = RoundToFloor(g_fCvarFieldHealAmountIncap);
iHealth += iBuff;
if( iHealth > g_iCvarIncapHealth )
iHealth = g_iCvarIncapHealth;
SetEntityHealth(client, iHealth);
}
else
{
int iHealth = GetClientHealth(client);
int iMaxHealth = GetEntProp(client, Prop_Send, "m_iMaxHealth");
float fGameTime = GetGameTime();
float fHealthTime = GetEntPropFloat(client, Prop_Send, "m_healthBufferTime");
float fHealth = GetEntPropFloat(client, Prop_Send, "m_healthBuffer");
fHealth -= (fGameTime - fHealthTime) * g_fCvarDecayRate;
// Heal temp health
if( g_iCvarTemp == -1 || (g_iCvarTemp != 0 && GetRandomInt(1, 100) >= g_iCvarTemp) )
{
if( fHealth < 0.0 )
fHealth = 0.0;
// How much temp health to give
float fBuff = g_fCvarFieldHealAmount;
fHealth += fBuff;
// Maximum health reached, do we full heal?
if( g_iCvarFull == 1 && fHealth >= g_fCvarMaxT )
{
HealPlayer(client);
SetEntPropFloat(client, Prop_Send, "m_healthBuffer", 0.0);
SetEntPropFloat(client, Prop_Send, "m_healthBufferTime", fGameTime);
}
// Reached maximum health
else if( iHealth + fHealth >= iMaxHealth )
{
// Heal to max allowed temp, or to max main health
if( fHealth >= g_fCvarMaxT )
SetEntPropFloat(client, Prop_Send, "m_healthBuffer", g_fCvarMaxT);
else
SetEntPropFloat(client, Prop_Send, "m_healthBuffer", float(iMaxHealth - iHealth));
SetEntPropFloat(client, Prop_Send, "m_healthBufferTime", fGameTime);
}
// Temp buff is less than maximum allowed
else if( fHealth < g_fCvarMaxT )
{
SetEntPropFloat(client, Prop_Send, "m_healthBuffer", fHealth);
SetEntPropFloat(client, Prop_Send, "m_healthBufferTime", fGameTime);
}
}
else
{
// Heal main health
if( fGameTime - g_fHealTime[client] > g_fCvarFieldRefreshTime )
{
g_fHealTime[client] = fGameTime;
int iBuff = RoundToFloor(g_fCvarFieldHealAmount);
iHealth += iBuff;
if( g_iCvarFull == 2 && iHealth >= g_iCvarMaxM )
{
HealPlayer(client);
SetEntPropFloat(client, Prop_Send, "m_healthBuffer", 0.0);
SetEntPropFloat(client, Prop_Send, "m_healthBufferTime", fGameTime);
}
else if( iHealth >= iMaxHealth )
{
iHealth = iMaxHealth;
SetEntPropFloat(client, Prop_Send, "m_healthBuffer", 0.0);
SetEntPropFloat(client, Prop_Send, "m_healthBufferTime", fGameTime);
}
else if( iHealth + fHealth >= iMaxHealth )
{
SetEntPropFloat(client, Prop_Send, "m_healthBuffer", float(iMaxHealth - iHealth));
SetEntPropFloat(client, Prop_Send, "m_healthBufferTime", fGameTime);
}
if( iHealth <= g_iCvarMaxM && iHealth <= iMaxHealth )
{
SetEntityHealth(client, iHealth);
}
}
}
}
}
void CreateBeamRing(float vPos[3])
{
int colors[4];
if( g_bCvarFieldColorRandom )
colors = GetRandomColors();
else
colors = g_iCvarFieldColor;
vPos[2] += 10.0;
TE_SetupBeamRingPoint(vPos, g_fCvarFieldStartRadius, g_fCvarFieldEndRadius, g_iBeamSprite, g_iHaloSprite, 0, 0, g_fCvarFieldDuration, g_fCvarFieldWidth, g_fCvarFieldAmplitude, colors, 0, 0 );
TE_SendToAll();
}
// ====================================================================================================
// LOAD COLAS
// ====================================================================================================
void LoadColas()
{
if( g_bLoaded || g_iCvarRandom == 0 ) return;
g_bLoaded = true;
char sPath[PLATFORM_MAX_PATH];
BuildPath(Path_SM, sPath, sizeof(sPath), CONFIG_SPAWNS);
if( !FileExists(sPath) )
return;
// Load config
KeyValues hFile = new KeyValues("colas");
if( !hFile.ImportFromFile(sPath) )
{
delete hFile;
return;
}
// Check for current map in the config
char sMap[64];
GetCurrentMap(sMap, sizeof(sMap));
if( !hFile.JumpToKey(sMap) )
{
delete hFile;
return;
}
// Retrieve how many colas to display
int iCount = hFile.GetNum("num", 0);
if( iCount == 0 )
{
delete hFile;
return;
}
// Spawn only a select few colas?
int iIndexes[MAX_COLAS+1];
if( iCount > MAX_COLAS )
iCount = MAX_COLAS;
// Spawn saved colas or create random
int iRandom = g_iCvarRandom;
if( iRandom == -1 || iRandom > iCount)
iRandom = iCount;
if( iRandom != -1 )
{
for( int i = 1; i <= iCount; i++ )
iIndexes[i-1] = i;
SortIntegers(iIndexes, iCount, Sort_Random);
iCount = iRandom;
}
// Get the cola origins and spawn
char sTemp[4];
float vPos[3], vAng[3];
int index;
for( int i = 1; i <= iCount; i++ )
{
if( iRandom != -1 ) index = iIndexes[i-1];
else index = i;
IntToString(index, sTemp, sizeof(sTemp));
if( hFile.JumpToKey(sTemp) )
{
hFile.GetVector("angle", vAng);
hFile.GetVector("origin", vPos);
if( vPos[0] == 0.0 && vPos[0] == 0.0 && vPos[0] == 0.0 ) // Should never happen.
LogError("Error: 0,0,0 origin. Iteration=%d. Index=%d. Random=%d. Count=%d.", i, index, iRandom, iCount);
else
CreateCola(vPos, vAng, index);
hFile.GoBack();
}
}
delete hFile;
}
// ====================================================================================================
// CREATE COLA
// ====================================================================================================
void CreateCola(const float vOrigin[3], const float vAngles[3], int index = 0)
{
if( g_iColaCount >= MAX_COLAS )
return;
int iColaIndex = -1;
for( int i = 0; i < MAX_COLAS; i++ )
{
if( g_iColas[i][0] == 0 )
{
iColaIndex = i;
break;
}
}
if( iColaIndex == -1 )
return;
int entity = CreateEntityByName("prop_physics");
if( entity == -1 )
ThrowError("Failed to create cola model.");
g_iColas[iColaIndex][0] = EntIndexToEntRef(entity);
g_iColas[iColaIndex][1] = index;
SetEntityModel(entity, MODEL_COLA);
DispatchSpawn(entity);
TeleportEntity(entity, vOrigin, vAngles, NULL_VECTOR);
if( g_iCvarGlow )
{
SetEntProp(entity, Prop_Send, "m_nGlowRange", g_iCvarGlow);
SetEntProp(entity, Prop_Send, "m_iGlowType", 1);
SetEntProp(entity, Prop_Send, "m_glowColorOverride", g_iCvarGlowCol);
AcceptEntityInput(entity, "StartGlowing");
}
g_iColaCount++;
}
// ====================================================================================================
// COMMANDS
// ====================================================================================================
// sm_cola
// ====================================================================================================
Action CmdColaTemp(int client, int args)
{