forked from akowald/resurrect
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresurrect.sp
1452 lines (1222 loc) · 46.9 KB
/
resurrect.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
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
/**
* ==============================================================================
* Resurrection - Arena Team Fortress 2 Mod
* Copyright (C) 2014 Alex Kowald
* ==============================================================================
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation.
*
* 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/>.
*
*/
#pragma semicolon 1
#define RES_MAIN_PLUGIN
#include <sourcemod>
#include <sdktools>
#include <sdkhooks>
#include <tf2>
#include <tf2_stocks>
//#define DEBUG
#define PLUGIN_VERSION "0.7"
#define PLUGIN_PREFIX "\x07F0E68CRes>\x01"
#define SOUND_REVIVE "mvm/mvm_revive.wav"
#define SOUND_WARN "misc/doomsday_lift_warning.wav"
#define SOUND_MARKED "weapons/samurai/tf_marked_for_death_indicator.wav"
#define SOUND_LAST_RITES "misc/killstreak.wav"
#define SOUND_REVIVED_ALL "ui/itemcrate_smash_ultrarare_short.wav"
#define CAPHUD_PARITY_BITS 6
#define CAPHUD_PARITY_MASK ((1<<CAPHUD_PARITY_BITS)-1)
#define TIMER_STARTED_AUTO 0
#define TIMER_STARTED_NOMINATED 1
#define ArenaRoundState_RoundRunning 7
#define TFTeam_Red 2
#define TFTeam_Blue 3
new const String:g_strReviveDemo[][] = {"vo/demoman_mvm_resurrect01.mp3", "vo/demoman_mvm_resurrect02.mp3", "vo/demoman_mvm_resurrect03.mp3", "vo/demoman_mvm_resurrect05.mp3", "vo/demoman_mvm_resurrect06.mp3", "vo/demoman_mvm_resurrect07.mp3", "vo/demoman_mvm_resurrect08.mp3", "vo/demoman_mvm_resurrect09.mp3", "vo/demoman_mvm_resurrect10.mp3", "vo/demoman_mvm_resurrect11.mp3"};
new const String:g_strReviveEngie[][] = {"vo/engineer_mvm_resurrect01.mp3", "vo/engineer_mvm_resurrect02.mp3", "vo/engineer_mvm_resurrect03.mp3"};
new const String:g_strReviveHeavy[][] = {"vo/heavy_mvm_resurrect01.mp3", "vo/heavy_mvm_resurrect02.mp3", "vo/heavy_mvm_resurrect04.mp3", "vo/heavy_mvm_resurrect05.mp3", "vo/heavy_mvm_resurrect06.mp3", "vo/heavy_mvm_resurrect07.mp3"};
new const String:g_strReviveMedic[][] = {"vo/medic_mvm_resurrect01.mp3", "vo/medic_mvm_resurrect02.mp3", "vo/medic_mvm_resurrect03.mp3"};
new const String:g_strReviveScout[][] = {"vo/scout_mvm_resurrect01.mp3", "vo/scout_mvm_resurrect02.mp3", "vo/scout_mvm_resurrect03.mp3", "vo/scout_mvm_resurrect04.mp3", "vo/scout_mvm_resurrect05.mp3", "vo/scout_mvm_resurrect06.mp3", "vo/scout_mvm_resurrect07.mp3", "vo/scout_mvm_resurrect08.mp3"};
new const String:g_strReviveSniper[][] = {"vo/sniper_mvm_resurrect01.mp3", "vo/sniper_mvm_resurrect02.mp3", "vo/sniper_mvm_resurrect03.mp3"};
new const String:g_strReviveSoldier[][] = {"vo/soldier_mvm_resurrect01.mp3", "vo/soldier_mvm_resurrect02.mp3", "vo/soldier_mvm_resurrect03.mp3", "vo/soldier_mvm_resurrect04.mp3", "vo/soldier_mvm_resurrect05.mp3", "vo/soldier_mvm_resurrect06.mp3"};
new const String:g_strReviveSpy[][] = {"vo/spy_mvm_resurrect01.mp3", "vo/spy_mvm_resurrect02.mp3", "vo/spy_mvm_resurrect03.mp3", "vo/spy_mvm_resurrect04.mp3", "vo/spy_mvm_resurrect05.mp3", "vo/spy_mvm_resurrect06.mp3", "vo/spy_mvm_resurrect07.mp3", "vo/spy_mvm_resurrect08.mp3", "vo/spy_mvm_resurrect09.mp3"};
new const String:g_strRevivePyro[][] = {"vo/pyro_sf13_spell_generic01.mp3", "vo/pyro_autocappedcontrolpoint01.mp3"};
new const String:g_strSoundMarked[][] = {"weapons/samurai/tf_marked_for_death_impact_01.wav", "weapons/samurai/tf_marked_for_death_impact_02.wav", "weapons/samurai/tf_marked_for_death_impact_03.wav"};
new const String:g_strSoundLastMan[][] = {"vo/announcer_am_lastmanalive01.mp3", "vo/announcer_am_lastmanalive02.mp3", "vo/announcer_am_lastmanalive03.mp3", "vo/announcer_am_lastmanalive04.mp3"};
new const String:g_strSoundForfeit[][] = {"vo/announcer_am_lastmanforfeit01.mp3", "vo/announcer_am_lastmanforfeit02.mp3", "vo/announcer_am_lastmanforfeit03.mp3", "vo/announcer_am_lastmanforfeit04.mp3"};
new const String:g_strTeamColors[][] = {"\x07B2B2B2", "\x07B2B2B2", "\x07FF4040", "\x0799CCFF"};
new bool:g_bIsArena;
new bool:g_bEnabledForRound = false;
new bool:g_bPlayOnce[MAXPLAYERS+1];
new Handle:g_hTimerVote;
new bool:g_bDemocracy[MAXPLAYERS+1];
new bool:g_bPlayAnnouncer;
new g_iRefCaptureArea;
new g_iRefObj;
new g_iRefTimer;
new g_iRefControlPoint;
new Handle:g_hCvarEnabled;
new Handle:g_hCvarTimeUnlock;
new Handle:g_hCvarTimeMFD;
new Handle:g_hCvarTimeImmunity;
new Handle:g_hCvarTimeTurtle;
new Handle:g_hCvarCapMid;
new Handle:g_hCvarCapMin;
new Handle:g_hCvarCapMax;
new Handle:g_hCvarHealthBonus;
new Handle:g_hCvarVotePercent;
new Handle:g_hCvarAutoStart;
new Handle:g_hCvarAutoAction;
new Handle:g_hCvarDemoAction;
new Handle:g_hCvarDemoCooldown;
new Handle:g_hCvarDemoTreshold;
new Handle:g_hCvarDemoMinPlayers;
new Handle:g_hCvarAnnouncer;
new Handle:g_hCvarLastRites;
new Handle:g_hCvarLastRitesDuration;
new Handle:g_hCvarFirstBlood;
new Handle:g_hCvarMapHack;
new Handle:g_hCvarArenaRoundTime;
new Handle:g_hCvarArenaFirstBlood;
enum eMapHack
{
MapHack_None=0,
MapHack_HardHat,
MapHack_Arakawa,
MapHack_BlackwoodValley,
MapHack_Ferrous
};
new eMapHack:g_nMapHack;
enum eActionState
{
Action_VoteNone=0,
Action_VoteOn,
Action_VoteOff,
Action_VoteBoth
};
#include "resurrect_menus.sp"
public Plugin:myinfo =
{
name = "Resurrection",
author = "linux_lover ([email protected])",
description = "Teammates come back to life when the control point is captured.",
version = PLUGIN_VERSION,
url = "TF2Randomizer.com"
};
public OnPluginStart()
{
CreateConVar("resurrect_version", PLUGIN_VERSION, "Resurrection Version", FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY);
g_hCvarEnabled = CreateConVar("resurrect_enabled", "1", "0/1 - Enable or disable the plugin.");
g_hCvarTimeUnlock = CreateConVar("resurrect_time_unlock", "15", "Seconds until the control point unlocks and players can cap.");
g_hCvarTimeMFD = CreateConVar("resurrect_time_mfd", "5.0", "Seconds after leaving a control point that mark for death effects remain on the player.");
g_hCvarTimeImmunity = CreateConVar("resurrect_time_immunity", "3.0", "Seconds of immunity after being resurrected.");
g_hCvarTimeTurtle = CreateConVar("resurrect_time_turtle", "81", "If a control point is held for this many seconds, the game ends. This prevents camping and turtling by C/D spies or engineers.");
g_hCvarHealthBonus = CreateConVar("resurrect_health_bonus", "4.0", "Seconds of health bonus when capturing with no teammates. Set to 0.0 to disable.");
g_hCvarVotePercent = CreateConVar("resurrect_vote_percentage", "0.5", "Percentage of votes needed in order for a vote to pass.", _, true, 0.0, true, 1.0);
g_hCvarAnnouncer = CreateConVar("resurrect_announcer", "0", "Number of players required when the round starts to play 'last man standing' or 'disappointment' announcer sounds. Set to a high number (64) to disable.");
g_hCvarLastRites = CreateConVar("resurrect_lastrites", "2", "Number of MORE players on the opposite team to activate last rites. Set to a high number (64) to disable last rites.");
g_hCvarLastRitesDuration = CreateConVar("resurrect_lastrites_duration", "5.0", "Seconds of minicrits awarded for the last rite effect.");
g_hCvarFirstBlood = CreateConVar("resurrect_firstblood", "-1", "Number of players required for first blood. -1 will do nothing.");
g_hCvarMapHack = CreateConVar("resurrect_maphack", "1", "0/1 - Enable or disable changes to the map to support resurrection mode.");
g_hCvarAutoStart = CreateConVar("resurrect_auto_start", "2.0", "Minutes after a map starts to launch a vote to toggle resurrection mode.");
g_hCvarAutoAction = CreateConVar("resurrect_auto_action", "0", "0 - do not start automatic votes | 1 - only start votes to turn ON | 2 - only start votes to turn OFF | 3 - both");
g_hCvarDemoAction = CreateConVar("resurrect_democracy_action", "0", "0 - do not allow players to vote | 1 - allow players to vote ON | 2 - allow players to vote OFF | 3 - allow both");
g_hCvarDemoTreshold = CreateConVar("resurrect_democracy_treshold", "0.3", "Percentage of players needed to type !res in order to start a vote.");
g_hCvarDemoCooldown = CreateConVar("resurrect_democracy_cooldown", "300", "Cooldown in seconds between voting to change resurrection mode.");
g_hCvarDemoMinPlayers = CreateConVar("resurrect_democracy_minplayers", "3", "Minimum players on the server in order for players to start a vote.");
g_hCvarCapMin = CreateConVar("resurrect_cap_min", "0.25", "Minimum capture time when one team has fewer alive players.");
g_hCvarCapMid = CreateConVar("resurrect_cap_mid", "0.7", "Medium capture time when both teams have the same amount of alive players.");
g_hCvarCapMax = CreateConVar("resurrect_cap_max", "2.0", "Maximum capture time when one team has more alive players.");
g_hCvarArenaRoundTime = FindConVar("tf_arena_round_time");
g_hCvarArenaFirstBlood = FindConVar("tf_arena_first_blood");
Resurrect_StripNotifyFlag(g_hCvarArenaRoundTime, true);
HookConVarChange(g_hCvarEnabled, CVarChanged_Enabled);
HookConVarChange(g_hCvarMapHack, CVarChanged_MapHack);
HookEvent("teamplay_round_start", Event_RoundStart);
HookEvent("arena_round_start", Event_RoundActive);
HookEvent("teamplay_point_captured", Event_PointCaptured);
HookEvent("server_cvar", Event_Cvar, EventHookMode_Pre);
HookEvent("teamplay_round_win", Event_RoundWin);
HookEvent("player_death", Event_PlayerDeath);
RegAdminCmd("resurrect_test", Command_Test, ADMFLAG_ROOT);
RegAdminCmd("resurrect_toggle", Command_Toggle, ADMFLAG_GENERIC);
RegAdminCmd("resurrect_vote", Command_Vote, ADMFLAG_VOTE);
HookEntityOutput("tf_logic_arena", "OnCapEnabled", Logic_OnCapEnabled);
LoadTranslations("resurrect.phrases");
}
public OnAllPluginsLoaded()
{
AdminMenu_Init();
}
public OnLibraryAdded(const String:name[])
{
if(strcmp(name, LIBRARY_ADMINMENU))
{
AdminMenu_Init();
}
}
public OnLibraryRemoved(const String:name[])
{
if(strcmp(name, LIBRARY_ADMINMENU) == 0)
{
g_hAdminMenu = INVALID_HANDLE;
}
}
public APLRes:AskPluginLoad2(Handle:myself, bool:late, String:error[], error_max)
{
CreateNative("Resurrect_Enable", Native_Enable);
CreateNative("Resurrect_IsRunning", Native_IsRunning);
RegPluginLibrary("resurrect");
return APLRes_Success;
}
Resurrect_StripNotifyFlag(Handle:hCvar, bool:bStrip)
{
new iFlags = GetConVarFlags(hCvar);
if(bStrip)
{
iFlags &= ~FCVAR_NOTIFY;
}else{
iFlags &= FCVAR_NOTIFY;
}
SetConVarFlags(hCvar, iFlags);
}
public OnPluginEnd()
{
Entity_Cleanup();
// Fix the tf_arena_round_time cvar and notify the players
Resurrect_StripNotifyFlag(g_hCvarArenaRoundTime, false);
decl String:strValue[32];
GetConVarString(g_hCvarArenaRoundTime, strValue, sizeof(strValue));
for(new i=1; i<=MaxClients; i++)
{
if(IsClientInGame(i) && !IsFakeClient(i)) SendConVarValue(i, g_hCvarArenaRoundTime, strValue);
}
}
public OnMapStart()
{
g_bEnabledForRound = false;
g_bVoteInProgress = false;
for(new i=0; i<MAXPLAYERS+1; i++)
Entity_Cleanup();
decl String:strMap[64];
GetCurrentMap(strMap, sizeof(strMap));
g_bIsArena = (strncmp(strMap, "arena_", 6) == 0);
Resurrect_LoadResources();
}
MapHack_Init()
{
g_nMapHack = MapHack_None;
decl String:strMap[64];
GetCurrentMap(strMap, sizeof(strMap));
if(GetConVarBool(g_hCvarMapHack))
{
if(strncmp(strMap, "arena_hardhat", 13) == 0)
{
g_nMapHack = MapHack_HardHat;
}else if(strncmp(strMap, "arena_arakawa", 13) == 0)
{
g_nMapHack = MapHack_Arakawa;
}else if(strcmp(strMap, "arena_blackwood_valley") == 0)
{
g_nMapHack = MapHack_BlackwoodValley;
}else if(strncmp(strMap, "arena_ferrous", 13) == 0)
{
g_nMapHack = MapHack_Ferrous;
}
}
}
public OnMapEnd()
{
Timer_KillVote();
}
public OnConfigsExecuted()
{
MapHack_Init();
Timer_KillVote();
if(g_bIsArena)
{
new bool:bStartTimer = false;
switch(eActionState:GetConVarInt(g_hCvarAutoAction))
{
case Action_VoteOn:
{
if(!GetConVarBool(g_hCvarEnabled))
{
bStartTimer = true;
}
}
case Action_VoteOff:
{
if(GetConVarBool(g_hCvarEnabled))
{
bStartTimer = true;
}
}
case Action_VoteBoth: bStartTimer = true;
}
if(bStartTimer)
{
new Float:flDuration = GetConVarFloat(g_hCvarAutoStart);
if(flDuration > 0.0) g_hTimerVote = CreateTimer(flDuration * 60.0, Timer_StartVote, TIMER_STARTED_AUTO, TIMER_REPEAT);
}
}
}
Resurrect_LoadResources()
{
PrecacheSound(SOUND_REVIVE);
PrecacheSound(SOUND_WARN);
PrecacheSound(SOUND_MARKED);
PrecacheSound(SOUND_LAST_RITES);
PrecacheSound(SOUND_REVIVED_ALL);
PrecacheSound(SOUND_VOTE_STARTED);
PrecacheSound(SOUND_VOTE_PASSED);
PrecacheSound(SOUND_VOTE_FAILED);
for(new i=0; i<sizeof(g_strReviveDemo); i++) PrecacheSound(g_strReviveDemo[i]);
for(new i=0; i<sizeof(g_strReviveEngie); i++) PrecacheSound(g_strReviveEngie[i]);
for(new i=0; i<sizeof(g_strReviveHeavy); i++) PrecacheSound(g_strReviveHeavy[i]);
for(new i=0; i<sizeof(g_strReviveMedic); i++) PrecacheSound(g_strReviveMedic[i]);
for(new i=0; i<sizeof(g_strReviveScout); i++) PrecacheSound(g_strReviveScout[i]);
for(new i=0; i<sizeof(g_strReviveSniper); i++) PrecacheSound(g_strReviveSniper[i]);
for(new i=0; i<sizeof(g_strReviveSoldier); i++) PrecacheSound(g_strReviveSoldier[i]);
for(new i=0; i<sizeof(g_strReviveSpy); i++) PrecacheSound(g_strReviveSpy[i]);
for(new i=0; i<sizeof(g_strRevivePyro); i++) PrecacheSound(g_strRevivePyro[i]);
for(new i=0; i<sizeof(g_strSoundMarked); i++) PrecacheSound(g_strSoundMarked[i]);
for(new i=0; i<sizeof(g_strSoundLastMan); i++) PrecacheSound(g_strSoundLastMan[i]);
for(new i=0; i<sizeof(g_strSoundForfeit); i++) PrecacheSound(g_strSoundForfeit[i]);
}
bool:Resurrect_IsEnabled()
{
return g_bEnabledForRound;
}
bool:Resurrect_CanBeEnabled()
{
return g_bIsArena && GetConVarBool(g_hCvarEnabled);
}
Resurrect_RefreshCvars()
{
for(new i=1; i<=MaxClients; i++)
{
if(IsClientInGame(i) && !IsFakeClient(i))
{
SendConVarValue(i, g_hCvarArenaRoundTime, "9001");
}
}
}
public OnClientPostAdminCheck(client)
{
if(!IsFakeClient(client)) SendConVarValue(client, g_hCvarArenaRoundTime, "9001");
}
public OnClientDisconnect(client)
{
g_bDemocracy[client] = false;
}
public Event_RoundStart(Handle:hEvent, const String:strEventName[], bool:bDontBroadcast)
{
#if defined DEBUG
PrintToServer("(Event_RoundStart)");
#endif
g_bEnabledForRound = false;
if(!Resurrect_CanBeEnabled()) return;
g_bEnabledForRound = true;
Entity_Cleanup();
for(new i=0; i<sizeof(g_bPlayOnce); i++) g_bPlayOnce[i] = false;
Resurrect_RefreshCvars();
// Determine whether or not to play 'last man standing' or 'disappoint' announcer lines for the next round
g_bPlayAnnouncer = false;
new iPlayerCount;
for(new i=1; i<=MaxClients; i++)
{
if(IsClientInGame(i) && GetClientTeam(i) >= 2) iPlayerCount++;
}
if(iPlayerCount >= GetConVarInt(g_hCvarAnnouncer)) g_bPlayAnnouncer = true;
// Determine whether or not to enable first blood crits
new iNumFirstBlood = GetConVarInt(g_hCvarFirstBlood);
if(iNumFirstBlood > 0)
{
if(iPlayerCount >= iNumFirstBlood)
{
SetConVarInt(g_hCvarArenaFirstBlood, 1);
PrintToChatAll("%s %T", PLUGIN_PREFIX, "Res_Chat_FirstBlood", LANG_SERVER, 0x04, iNumFirstBlood, 0x01, 0x04, 0x01);
}else{
SetConVarInt(g_hCvarArenaFirstBlood, 0);
}
}
// Disable the master control point so the game does not end when the player captures a control point
new iMaster = FindEntityByClassname(MaxClients+1, "team_control_point_master");
if(iMaster > MaxClients)
{
#if defined DEBUG
PrintToServer("(Event_RoundStart) Found team_control_point_master: %d!", iMaster);
#endif
AcceptEntityInput(iMaster, "Disable");
}
// Find tf_objective_resource for later
new iObjective = Entity_GetObj();
if(iObjective <= MaxClients)
{
LogMessage("Failed to find \"tf_objective_resource\" entity!");
new iNumControlPoints = GetEntProp(iObjective, Prop_Send, "m_iNumControlPoints");
if(iNumControlPoints != 1)
{
LogMessage("Found %d control points, this could mean trouble!", iNumControlPoints);
}
}
// Find the trigger_capture_area which controls capping time
new iCaptureArea = MaxClients+1;
while((iCaptureArea = FindEntityByClassname(iCaptureArea, "trigger_capture_area")) > MaxClients)
{
if(GetEntProp(iCaptureArea, Prop_Data, "m_bDisabled")) continue;
decl String:strName[128];
GetEntPropString(iCaptureArea, Prop_Data, "m_iszCapPointName", strName, sizeof(strName));
#if defined DEBUG
PrintToServer("(Event_RoundStart) Found trigger_capture_area: %d area_cap_point: \"%s\"!", iCaptureArea, strName);
#endif
g_iRefCaptureArea = EntIndexToEntRef(iCaptureArea);
new iControlPoint = Entity_FindEntityByName(strName, "team_control_point");
if(iControlPoint > MaxClients)
{
#if defined DEBUG
PrintToServer("(Event_RoundStart) Found team_control_point: %d!", iControlPoint);
#endif
g_iRefControlPoint = EntIndexToEntRef(iControlPoint);
}
// Set the initial capturing time
// Respawn time will be reset when the player begins capturing so this isn't that important
Resurrect_SetCaptureTime(TFTeam_Red, GetConVarFloat(g_hCvarCapMax));
Resurrect_SetCaptureTime(TFTeam_Blue, GetConVarFloat(g_hCvarCapMax));
HookSingleEntityOutput(iCaptureArea, "OnStartTeam1", Area_StartCapture, false);
HookSingleEntityOutput(iCaptureArea, "OnStartTeam2", Area_StartCapture, false);
// Hook touch
SDKHook(iCaptureArea, SDKHook_Touch, Area_Touch);
SDKHook(iCaptureArea, SDKHook_StartTouch, Area_StartTouch);
//SDKHook(iCaptureArea, SDKHook_EndTouch, Area_EndTouch);
}
// Find tf_logic_arena and allow us to dynamically set when capture points are unlocked
new iTimeUnlock = GetConVarInt(g_hCvarTimeUnlock);
if(iTimeUnlock != -1)
{
new iLogic = FindEntityByClassname(MaxClients+1, "tf_logic_arena");
if(iLogic > MaxClients)
{
#if defined DEBUG
PrintToServer("(Event_RoundStart) Found tf_logic_arena: %d!", iLogic);
#endif
if(g_nMapHack == MapHack_Ferrous) iTimeUnlock = 40; // Map starts the train moving 40s after OnArenaRoundStart
SetEntPropFloat(iLogic, Prop_Data, "m_flTimeToEnableCapPoint", float(iTimeUnlock));
}
}
PrintToChatAll("%s \x0732CD32%T", PLUGIN_PREFIX, "Res_Chat_Description", LANG_SERVER, "\x07F0E68C");
}
public Action:Area_Touch(iCaptureArea, client)
{
//PrintToServer("(Area_Touch) client: %d!", client);
// Only apply marked for death effects while they are defending the control point
if(client >= 1 && client <= MaxClients && IsClientInGame(client) && IsPlayerAlive(client))
{
// Check if they own the control point they are standing on
new iControlPoint = EntRefToEntIndex(g_iRefControlPoint);
if(iControlPoint > MaxClients && GetEntProp(iControlPoint, Prop_Send, "m_iTeamNum") == GetClientTeam(client))
{
if(!TF2_IsPlayerInCondition(client, TFCond_MarkedForDeathSilent))
{
// They are touching the point and not marked yet (they probably just captured)
Resurrect_HandleMarkedEffects(client);
}
TF2_AddCondition(client, TFCond_MarkedForDeathSilent, GetConVarFloat(g_hCvarTimeMFD));
}
}
return Plugin_Continue;
}
public Area_StartTouch(iCaptureArea, client)
{
//PrintToServer("(Area_StartTouch) client: %d!", client);
// Play a sound to let the player know they might be marked for death
if(client >= 1 && client <= MaxClients && IsClientInGame(client) && IsPlayerAlive(client))
{
// Check if they own the control point they are standing on
new iControlPoint = EntRefToEntIndex(g_iRefControlPoint);
if(iControlPoint > MaxClients && GetEntProp(iControlPoint, Prop_Send, "m_iTeamNum") == GetClientTeam(client))
{
Resurrect_HandleMarkedEffects(client);
}
}
}
Resurrect_HandleMarkedEffects(client)
{
// Play the long 4.0s marked sound only the first time the player becomes marked for death to get the idea across
if(!g_bPlayOnce[client])
{
EmitSoundToClient(client, SOUND_MARKED);
g_bPlayOnce[client] = true;
}else{
// This is a shorter 'punch' impact sound
EmitSoundToClient(client, g_strSoundMarked[GetRandomInt(0, sizeof(g_strSoundMarked)-1)], _, _, _, _, 1.0);
}
}
public Logic_OnCapEnabled(const String:output[], caller, activator, Float:delay)
{
#if defined DEBUG
PrintToServer("(Logic_OnCapEnabled) caller: %d activator: %d!", output, caller, activator);
#endif
if(!Resurrect_IsEnabled()) return;
if(!Resurrect_IsInRound()) return;
new Handle:hAnno = CreateEvent("show_annotation");
if(hAnno != INVALID_HANDLE)
{
decl String:strText[100];
Format(strText, sizeof(strText), "%T", "Res_Anno_PointUnlocked", LANG_SERVER);
// Display a message at the control point making players aware of the objective
new Float:flPos[3];
new iCP = FindEntityByClassname(MaxClients+1, "team_control_point");
if(iCP > MaxClients)
{
GetEntPropVector(iCP, Prop_Send, "m_vecOrigin", flPos);
}
SetEventFloat(hAnno, "worldPosX", flPos[0]);
SetEventFloat(hAnno, "worldPosY", flPos[1]);
SetEventFloat(hAnno, "worldPosZ", flPos[2]);
SetEventInt(hAnno, "id", 0);
SetEventFloat(hAnno, "lifetime", 3.0);
SetEventString(hAnno, "text", strText);
SetEventString(hAnno, "play_sound", "misc/null.wav");
FireEvent(hAnno); // Frees the handle
}
}
public Area_StartCapture(const String:output[], caller, activator, Float:delay)
{
#if defined DEBUG
PrintToServer("(Area_StartCapture) caller: %d activator: %d!", output, caller, activator);
#endif
if(activator != EntRefToEntIndex(g_iRefCaptureArea)) return;
if(!Resurrect_IsEnabled()) return;
if(!Resurrect_IsInRound()) return;
// Determine which team started capping by the name of the output
new iTeam = (strcmp(output, "OnStartTeam2") == 0) ? TFTeam_Blue : TFTeam_Red;
Resurrect_SetCaptureTime(iTeam, Resurrect_GetCaptureTime(iTeam));
}
Entity_GetObj()
{
if(g_iRefObj != 0)
{
new iEntity = EntRefToEntIndex(g_iRefObj);
if(iEntity > MaxClients) return iEntity;
}
new iEntity = FindEntityByClassname(MaxClients+1, "tf_objective_resource");
if(iEntity > MaxClients)
{
g_iRefObj = EntIndexToEntRef(iEntity);
return iEntity;
}
return 0;
}
Entity_GetTimer()
{
Resurrect_RefreshCvars();
if(g_iRefTimer != 0)
{
new iTimer = EntRefToEntIndex(g_iRefTimer);
if(iTimer > MaxClients) return iTimer;
}
// Catch the tf_arena_round_timer should it be alive and hide it from view
// We aren't going to disable it, just hide it so it should stalemate the round when time is up
new iRoundTimer = MaxClients+1;
while((iRoundTimer = FindEntityByClassname(iRoundTimer, "team_round_timer")) > MaxClients)
{
if(GetEntProp(iRoundTimer, Prop_Send, "m_bIsDisabled")) continue;
SetVariantInt(0);
AcceptEntityInput(iRoundTimer, "ShowInHUD");
SetVariantInt(0);
AcceptEntityInput(iRoundTimer, "AutoCountdown", iRoundTimer);
}
new iTimer = CreateEntityByName("team_round_timer");
if(iTimer > MaxClients)
{
DispatchSpawn(iTimer);
new iDuration = GetConVarInt(g_hCvarTimeTurtle);
SetVariantInt(iDuration);
AcceptEntityInput(iTimer, "SetMaxTime");
SetVariantInt(iDuration);
AcceptEntityInput(iTimer, "SetTime");
SetVariantInt(1);
AcceptEntityInput(iTimer, "ShowInHUD");
SetVariantInt(1);
AcceptEntityInput(iTimer, "AutoCountdown", iTimer);
AcceptEntityInput(iTimer, "Enable");
AcceptEntityInput(iTimer, "Resume");
g_iRefTimer = EntIndexToEntRef(iTimer);
HookSingleEntityOutput(iTimer, "OnFinished", Timer_OnFinished, true);
return iTimer;
}
return 0;
}
Entity_Cleanup()
{
Timer_Cleanup();
g_iRefObj = 0;
g_iRefCaptureArea = 0;
}
Timer_Cleanup()
{
if(g_iRefTimer != 0)
{
new iTimer = EntRefToEntIndex(g_iRefTimer);
if(iTimer > MaxClients)
{
AcceptEntityInput(iTimer, "Disable");
AcceptEntityInput(iTimer, "Kill");
}
g_iRefTimer = 0;
}
}
public Timer_OnFinished(const String:output[], caller, activator, Float:delay)
{
#if defined DEBUG
PrintToServer("(Timer_OnFinished) caller: %d activator: %d", caller, activator);
#endif
if(activator != EntRefToEntIndex(g_iRefTimer)) return;
if(!Resurrect_IsEnabled()) return;
if(!Resurrect_IsInRound()) return;
// Determine which team control the control point and trigger a win
AcceptEntityInput(FindEntityByClassname(MaxClients+1, "team_control_point_master"), "Enable");
Timer_Cleanup();
}
Float:Resurrect_GetCaptureTime(iTeam, iAlive1=-1, iAlive2=-1)
{
// The general idea: the more players alive on the other team -> the quicker the control point can be captured
// and viceaversa: the more players alive on my team -> the slower the control point can be captured
new iOppositeTeam = (iTeam == TFTeam_Red) ? TFTeam_Blue : TFTeam_Red;
// The general idea: the more players dead on a team -> the quicker the control point can be captured
// Find out how many more alive players the other team has
new iNumAlive[4];
if(iAlive1 != -1 && iAlive2 != -1)
{
iNumAlive[TFTeam_Red] = iAlive1;
iNumAlive[TFTeam_Blue] = iAlive2;
}else{
for(new i=1; i<=MaxClients; i++)
{
if(IsClientInGame(i))
{
new iClientTeam = GetClientTeam(i);
if(iClientTeam == TFTeam_Red || iClientTeam == TFTeam_Blue)
{
if(IsPlayerAlive(i)) iNumAlive[iClientTeam]++;
}
}
}
}
new Float:flMin = GetConVarFloat(g_hCvarCapMin);
new Float:flMid = GetConVarFloat(g_hCvarCapMid);
new Float:flMax = GetConVarFloat(g_hCvarCapMax);
// Calculate the change for each player difference
// For now, use the interval between the min and max to calculate the modifier
new Float:flMult;
if(iNumAlive[iTeam] >= iNumAlive[iOppositeTeam])
{
// More players are alive on my team
flMult = flMax - flMid;
}else{
// More players are alive on the opposite team
flMult = flMid - flMin;
}
// Get a percentage to be able to use a modifier
new iPlayerCap = 10;
new iDiff = iNumAlive[iTeam] - iNumAlive[iOppositeTeam];
if(iDiff > iPlayerCap) iDiff = iPlayerCap; else if(iDiff < iPlayerCap * -1) iDiff = iPlayerCap * -1;
new Float:flRate = flMid + (float(iDiff) / float(iPlayerCap)) * flMult;
flRate = Pow(flRate, 1.1);
if(flRate > flMax) flRate = flMax; else if(flRate < flMin) flRate = flMin;
return flRate;
}
Resurrect_SetCaptureTime(iTeam, Float:flCaptureTime)
{
if(iTeam != TFTeam_Red && iTeam != TFTeam_Blue) return;
// Applies a new capture rate for the control point
new iCaptureArea = EntRefToEntIndex(g_iRefCaptureArea);
if(iCaptureArea > MaxClients)
{
new iObjective = Entity_GetObj();
if(iObjective > MaxClients)
{
#if defined DEBUG
PrintToServer("(Resurrect_SetCaptureTime) Setting respawn on team %d to: %0.2f..", iTeam, flCaptureTime);
#endif
SetEntPropFloat(iCaptureArea, Prop_Data, "m_flCapTime", flCaptureTime);
// You need to do this in order for client's HUDs to predict the capture rate
new iCPIndex = 0;
// Mappers have a little control given by the property "Number of RED/BLUE players to cap" on trigger_capture_area
new iReqCappers = GetEntProp(iObjective, Prop_Send, "m_iTeamReqCappers", _, iCPIndex + 8 * iTeam);
SetEntPropFloat(iObjective, Prop_Send, "m_flTeamCapTime", flCaptureTime * float(iReqCappers * 2), iCPIndex + 8 * iTeam);
// Tells the client to update the HUD
new iHudParity = GetEntProp(iObjective, Prop_Send, "m_iUpdateCapHudParity");
iHudParity = (iHudParity + 1) & CAPHUD_PARITY_MASK;
SetEntProp(iObjective, Prop_Send, "m_iUpdateCapHudParity", iHudParity);
}
}
}
public Event_RoundActive(Handle:hEvent, const String:strEventName[], bool:bDontBroadcast)
{
#if defined DEBUG
PrintToServer("(Event_RoundActive)");
#endif
if(!Resurrect_IsEnabled()) return;
if(!Resurrect_IsInRound()) return;
switch(g_nMapHack)
{
case MapHack_HardHat:
{
// Remove the spawn doors so respawning players are not trapped
new iEntity = Entity_FindEntityByName("door_any_trackdoor_1_prop", "prop_dynamic");
if(iEntity > MaxClients)
{
#if defined DEBUG
PrintToServer("(Event_RoundActive) Removing entity \"door_any_trackdoor_1_prop\"!");
#endif
AcceptEntityInput(iEntity, "Kill");
}
iEntity = Entity_FindEntityByName("door_any_trackdoor_2_prop", "prop_dynamic");
if(iEntity > MaxClients)
{
#if defined DEBUG
PrintToServer("(Event_RoundActive) Removing entity \"door_any_trackdoor_2_prop\"!");
#endif
AcceptEntityInput(iEntity, "Kill");
}
iEntity = Entity_FindEntityByName("door_any_trackdoor_1", "func_door");
if(iEntity > MaxClients)
{
#if defined DEBUG
PrintToServer("(Event_RoundActive) Removing entity \"door_any_trackdoor_1\"!");
#endif
AcceptEntityInput(iEntity, "Kill");
}
iEntity = Entity_FindEntityByName("door_any_trackdoor_2", "func_door");
if(iEntity > MaxClients)
{
#if defined DEBUG
PrintToServer("(Event_RoundActive) Removing entity \"door_any_trackdoor_2\"!");
#endif
AcceptEntityInput(iEntity, "Kill");
}
}
case MapHack_Arakawa:
{
// Remove the spawn door props when the round starts
new iEntity;
while((iEntity = Entity_FindEntityByName("door_any_large_dyn_1", "func_door")) != -1)
{
#if defined DEBUG
PrintToServer("(Event_RoundActive) Removing entity \"door_any_large_dyn_1\"!");
#endif
AcceptEntityInput(iEntity, "Kill");
}
while((iEntity = Entity_FindEntityByName("door_any_large_dyn_1_prop", "prop_dynamic")) != -1)
{
#if defined DEBUG
PrintToServer("(Event_RoundActive) Removing entity \"door_any_large_dyn_1_prop\"!");
#endif
AcceptEntityInput(iEntity, "Kill");
}
while((iEntity = Entity_FindEntityByName("door_any_large_dyn_2", "func_door")) != -1)
{
#if defined DEBUG
PrintToServer("(Event_RoundActive) Removing entity \"door_any_large_dyn_2\"!");
#endif
AcceptEntityInput(iEntity, "Kill");
}
while((iEntity = Entity_FindEntityByName("door_any_large_dyn_2_prop", "prop_dynamic")) != -1)
{
#if defined DEBUG
PrintToServer("(Event_RoundActive) Removing entity \"door_any_large_dyn_2_prop\"!");
#endif
AcceptEntityInput(iEntity, "Kill");
}
}
case MapHack_BlackwoodValley:
{
// Rename the logic_relay to disable the explosion when the point is captured
new iEntity = Entity_FindEntityByName("end_pit_destroy_relay", "logic_relay");
if(iEntity != -1)
{
#if defined DEBUG
PrintToServer("(Event_RoundActive) Found: \"end_pit_destroy_relay_res\"!");
#endif
DispatchKeyValue(iEntity, "targetname", "end_pit_destroy_relay_res");
}
}
}
}
public Event_PointCaptured(Handle:hEvent, const String:strEventName[], bool:bDontBroadcast)
{
#if defined DEBUG
PrintToServer("(Event_PointCaptured)");
#endif
if(!Resurrect_IsEnabled()) return;
if(!Resurrect_IsInRound()) return;
// A point has been captured
// Respawn the dead teammates of the player that captured the control point
new iCappingTeam = GetEventInt(hEvent, "team");
if(iCappingTeam < 2 || iCappingTeam > 3) return;
// Create a timer to force players from hiding
new iTimeTurtle = GetConVarInt(g_hCvarTimeTurtle);
if(iTimeTurtle > 0)
{
new iTimer = Entity_GetTimer();
if(iTimer > MaxClients)
{
// ** VALVE BUG **: The AddTime input on team_round_timer does NOT work in arena
// The timer thinks the game is over due to arena's specific round running state
new RoundState:oldState = GameRules_GetRoundState();
GameRules_SetProp("m_iRoundState", RoundState_RoundRunning);
SetVariantInt(iTimeTurtle);
AcceptEntityInput(iTimer, "AddTime");
GameRules_SetProp("m_iRoundState", oldState);
}
}
new iCount;
new iNumTeammates;
new Float:flTimeImmunity = GetConVarFloat(g_hCvarTimeImmunity);
for(new i=1; i<=MaxClients; i++)
{
if(IsClientInGame(i) && GetClientTeam(i) == iCappingTeam)
{
iNumTeammates++;
if(!IsPlayerAlive(i))
{
TF2_RespawnPlayer(i);
// Add immunity effects to the player being resurrected
TF2_AddCondition(i, TFCond_UberchargedCanteen, flTimeImmunity);
Particle_Attach(i, (iCappingTeam == TFTeam_Red) ? "hwn_cart_drips_red" : "hwn_cart_drips_blue", _, 50.0, flTimeImmunity);
Resurrect_VocalizeRevive(i);
iCount++;
}
}
}
// Play a sound to the team that didn't cap letting them know that new players are on the field
new iOppositeTeam = (iCappingTeam == TFTeam_Red) ? TFTeam_Blue : TFTeam_Red;
for(new i=1; i<=MaxClients; i++)
{
if(IsClientInGame(i))
{
new iTeam = GetClientTeam(i);
if(iTeam == iCappingTeam)
{
if(iCount >= iNumTeammates-1 && iCount >= 3)
{
// Play a special sound when a player revives the entire team
EmitSoundToClient(i, SOUND_REVIVED_ALL);
}else{
EmitSoundToClient(i, SOUND_REVIVE);
}
}else if(iTeam == iOppositeTeam)
{
EmitSoundToClient(i, SOUND_WARN);
}
}
}
new String:strCappers[64];
GetEventString(hEvent, "cappers", strCappers, sizeof(strCappers));
// Build a string of the list of cappers
new Float:flTimeHealthBonus = GetConVarFloat(g_hCvarHealthBonus);
new String:strChat[192];
new iLength = strlen(strCappers);
new bool:bOnce = false;
for(new i=0; i<iLength; i++)
{
new client = strCappers[i];
if(client >= 1 && client <= MaxClients && IsClientInGame(client))
{
if(!bOnce)
{
// All cappers should be on the same team
Format(strChat, sizeof(strChat), "%s %s", PLUGIN_PREFIX, g_strTeamColors[GetClientTeam(client)]);
bOnce = true;
}
Format(strChat, sizeof(strChat), "%s%N, ", strChat, client);