forked from redsunservers/VSH-Rewrite
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathevent.sp
More file actions
935 lines (764 loc) · 26.5 KB
/
event.sp
File metadata and controls
935 lines (764 loc) · 26.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
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
static bool g_bSpawnTeamSwitch;
void Event_Init()
{
HookEvent("teamplay_round_start", Event_RoundStart, EventHookMode_Pre);
HookEvent("arena_round_start", Event_RoundArenaStart);
HookEvent("teamplay_round_win", Event_RoundEnd);
HookEvent("teamplay_point_captured", Event_PointCaptured);
HookEvent("player_spawn", Event_PlayerSpawn);
HookEvent("player_death", Event_PlayerDeath, EventHookMode_Pre);
HookEvent("post_inventory_application", Event_PlayerInventoryUpdate);
HookEvent("player_hurt", Event_PlayerHurt, EventHookMode_Pre);
HookEvent("deploy_buff_banner", Event_BuffBannerDeployed);
HookEvent("player_chargedeployed", Event_UberDeployed);
HookEvent("teamplay_broadcast_audio", Event_BroadcastAudio, EventHookMode_Pre);
HookEvent("player_builtobject", Event_BuiltObject, EventHookMode_Pre);
HookEvent("npc_hurt", Event_ObjectHurt);
HookEvent("object_destroyed", Event_ObjectDestroyed, EventHookMode_Pre);
HookEvent("player_sapped_object", Event_SappedObject, EventHookMode_Pre);
HookUserMessage(GetUserMessageId("PlayerJarated"), Event_Jarated);
}
public void Event_RoundStart(Event event, const char[] sName, bool bDontBroadcast)
{
g_bSpawnTeamSwitch = false;
if (!g_bEnabled || GameRules_GetProp("m_bInWaitingForPlayers"))
return;
// Start dome stuffs regardless if first round
Dome_RoundStart();
// Play one round of arena
if (g_iTotalRoundPlayed <= 0)
return;
// Arena has a very dumb logic, if all players from a team leave the round will end and then restart without reseting the game state...
// Catch that issue and don't run our logic!
int iRed = 0, iBlu = 0;
for (int iClient = 1; iClient <= MaxClients; iClient++)
{
if (IsClientInGame(iClient))
{
switch (TF2_GetClientTeam(iClient))
{
case TFTeam_Red: iRed++;
case TFTeam_Blue: iBlu++;
}
}
}
// Both team must have at least one player!
if (iRed == 0 || iBlu == 0)
{
if (iRed + iBlu >= 2) //If we have atleast 2 players in red or blue, force one person to other team and try again
{
for (int iClient = 1; iClient <= MaxClients; iClient++)
{
if (IsClientInGame(iClient))
{
//Once we found someone whos in red or blue, swap his team
TFTeam nTeam = TF2_GetClientTeam(iClient);
if (nTeam == TFTeam_Red)
{
g_bSpawnTeamSwitch = true;
TF2_ForceTeamJoin(iClient, TFTeam_Blue);
return;
}
else if (nTeam == TFTeam_Blue)
{
g_bSpawnTeamSwitch = true;
TF2_ForceTeamJoin(iClient, TFTeam_Red);
return;
}
}
}
}
//If we reach that part, either nobody is in server or people in spectator
return;
}
g_hTimerBossMusic = null;
g_bRoundStarted = false;
// New round started
for (int iClient = 1; iClient <= MaxClients; iClient++)
{
//Clean up any boss(es) that is/are still active
SaxtonHaleBase boss = SaxtonHaleBase(iClient);
if (boss.bValid)
boss.DestroyAllClass();
g_iPlayerDamage[iClient] = 0;
g_iPlayerAssistDamage[iClient] = 0;
g_iClientOwner[iClient] = 0;
if (!IsClientInGame(iClient) || TF2_GetClientTeam(iClient) <= TFTeam_Spectator)
continue;
// Put every players in same team & pick the boss later
TF2_ForceTeamJoin(iClient, TFTeam_Attack);
}
g_iTotalAttackCount = SaxtonHale_GetAliveAttackPlayers();
NextBoss_SetNextBoss(); //Set boss
g_iTotalAttackCount = SaxtonHale_GetAliveAttackPlayers(); //Update amount of attack players
RequestFrame(Frame_InitVshPreRoundTimer, tf_arena_preround_time.IntValue);
}
public void Event_RoundArenaStart(Event event, const char[] sName, bool bDontBroadcast)
{
if (!g_bEnabled || GameRules_GetProp("m_bInWaitingForPlayers")) return;
//Play one round of arena, and force unlock/enable dome
if (g_iTotalRoundPlayed <= 0)
{
GameRules_SetPropFloat("m_flCapturePointEnableTime", 0.0);
return;
}
g_bRoundStarted = true;
g_iTotalAttackCount = SaxtonHale_GetAliveAttackPlayers();
//New round started
for (int iClient = 1; iClient <= MaxClients; iClient++)
{
if (!IsClientInGame(iClient)) continue;
g_iPlayerDamage[iClient] = 0;
g_iPlayerAssistDamage[iClient] = 0;
ClassLimit_SetMainClass(iClient, TFClass_Unknown);
if (!SaxtonHale_IsValidAttack(iClient)) continue;
//Display weapon balances in chat
TFClassType nClass = TF2_GetPlayerClass(iClient);
ClassLimit_SetMainClass(iClient, nClass);
for (int iSlot = 0; iSlot <= WeaponSlot_InvisWatch; iSlot++)
{
int iWeapon = TF2_GetItemInSlot(iClient, iSlot);
if (IsValidEdict(iWeapon))
{
int iIndex = GetEntProp(iWeapon, Prop_Send, "m_iItemDefinitionIndex");
for (int i = 0; i <= 1; i++)
{
char sDesp[255];
// Desp for all weapon in class slot
if (i == 0)
g_ConfigClass[nClass][iSlot].GetDesp(sDesp, sizeof(sDesp));
// Desp for specific index
else if (i == 1)
g_ConfigIndex.GetDesp(iIndex, sDesp, sizeof(sDesp));
if (!StrEmpty(sDesp))
{
//Color tags
for (int iColor = 0; iColor < sizeof(g_strColorTag); iColor++)
ReplaceString(sDesp, sizeof(sDesp), g_strColorTag[iColor], g_strColorCode[iColor]);
//Bug with single % not showing, use %% to have % appeared once
ReplaceString(sDesp, sizeof(sDesp), "%", "%%");
//Add VSH color at start
Format(sDesp, sizeof(sDesp), "%s%s", TEXT_COLOR, sDesp);
PrintToChat(iClient, sDesp);
}
}
}
}
}
//Play boss music if there is one
if (g_ConfigConvar.LookupInt("vsh_music_enable"))
{
for (int iBoss = 1; iBoss <= MaxClients; iBoss++)
{
if (SaxtonHale_IsValidBoss(iBoss, false))
{
SaxtonHaleBase boss = SaxtonHaleBase(iBoss);
float flMusicTime;
boss.CallFunction("GetMusicInfo", g_sBossMusic, sizeof(g_sBossMusic), flMusicTime);
if (!StrEmpty(g_sBossMusic))
{
// Prefix the filepath with #, so it's considered as music by the engine, allowing people to adjust its volume through the music volume slider
if (g_sBossMusic[0] != '#')
Format(g_sBossMusic, sizeof(g_sBossMusic), "#%s", g_sBossMusic);
for (int i = 1; i <= MaxClients; i++)
if (IsClientInGame(i) && Preferences_Get(i, VSHPreferences_Music))
EmitSoundToClient(i, g_sBossMusic, _, SNDCHAN_STATIC, SNDLEVEL_NONE);
if (flMusicTime > 0.0)
g_hTimerBossMusic = CreateTimer(flMusicTime, Timer_Music, boss, TIMER_REPEAT);
break;
}
}
}
}
//Refresh boss health from player count
for (int iClient = 1; iClient <= MaxClients; iClient++)
{
SaxtonHaleBase boss = SaxtonHaleBase(iClient);
if (boss.bValid)
{
int iHealth = boss.CallFunction("CalculateMaxHealth");
boss.iMaxHealth = iHealth;
boss.iHealth = iHealth;
}
}
char sMessage[2048], sBuffer[256], sPreviousModifiers[256];
int iColor[4] = {255, 255, 255, 255};
bool bAllowModifiersColor = true;
//Loop through each bosses to display
for (int iClient = 1; iClient <= MaxClients; iClient++)
{
SaxtonHaleBase boss = SaxtonHaleBase(iClient);
if (!IsClientInGame(iClient) || !boss.bValid || boss.bMinion) continue;
if (!StrEmpty(sMessage)) StrCat(sMessage, sizeof(sMessage), "\n");
//Get client name
Format(sMessage, sizeof(sMessage), "%s%N became", sMessage, iClient);
//Display text who is what boss and modifiers with health
if (boss.bModifiers)
{
boss.CallFunction("GetModifiersName", sBuffer, sizeof(sBuffer));
Format(sMessage, sizeof(sMessage), "%s %s", sMessage, sBuffer);
if (!StrEmpty(sPreviousModifiers) && !StrEqual(sPreviousModifiers, sBuffer))
{
//More than 1 different modifiers, dont allow colors
bAllowModifiersColor = false;
}
else
{
boss.CallFunction("GetRenderColor", iColor);
}
Format(sPreviousModifiers, sizeof(sPreviousModifiers), sBuffer);
}
//Get Boss name and health
boss.CallFunction("GetBossName", sBuffer, sizeof(sBuffer));
Format(sMessage, sizeof(sMessage), "%s %s with %d HP!", sMessage, sBuffer, boss.iMaxHealth);
}
if (!bAllowModifiersColor)
for (int iRGB = 0; iRGB < sizeof(iColor); iRGB++)
iColor[iRGB] = 255;
float flHUD[2];
flHUD[0] = -1.0;
flHUD[1] = 0.3;
float flFade[2];
flFade[0] = 0.4;
flFade[1] = 0.4;
for (int i = 1; i <= MaxClients; i++)
if (IsClientInGame(i))
Hud_Display(i, CHANNEL_INTRO, sMessage, flHUD, 5.0, iColor, 0, 0.0, flFade);
Dome_RoundArenaStart();
Teuton_RoundArenaStart();
//Display chat on who is next boss
int iNextPlayer = Queue_GetPlayerFromRank(1);
if (0 < iNextPlayer <= MaxClients && IsClientInGame(iNextPlayer))
PrintToChat(iNextPlayer, "%s================%s\nYou are about to be the next boss!\n%s================", TEXT_DARK, TEXT_COLOR, TEXT_DARK);
}
public void Event_RoundEnd(Event event, const char[] sName, bool bDontBroadcast)
{
if (!g_bEnabled) return;
g_hTimerBossMusic = null;
g_bRoundStarted = false;
TFTeam iWinningTeam = view_as<TFTeam>(event.GetInt("team"));
g_iTotalRoundPlayed++;
if (g_iTotalRoundPlayed <= 1)
{
if (g_iTotalRoundPlayed == 1)//Arena round ended disable arena logic!
Plugin_Cvars(true);
return;
}
int iMainBoss = GetMainBoss();
if (iWinningTeam == TFTeam_Boss)
{
if (0 < iMainBoss <= MaxClients && IsClientInGame(iMainBoss))//Play our win line
{
SaxtonHaleBase boss = SaxtonHaleBase(iMainBoss);
if (boss.bValid)
{
char sSound[PLATFORM_MAX_PATH];
boss.CallFunction("GetSound", sSound, sizeof(sSound), VSHSound_Win);
if (!StrEmpty(sSound))
BroadcastSoundToTeam(TFTeam_Spectator, sSound);
Forward_BossWin(TFTeam_Boss);
}
}
}
else
{
if (0 < iMainBoss <= MaxClients && IsClientInGame(iMainBoss))//Play our lose line
{
SaxtonHaleBase boss = SaxtonHaleBase(iMainBoss);
if (boss.bValid)
{
char sSound[PLATFORM_MAX_PATH];
boss.CallFunction("GetSound", sSound, sizeof(sSound), VSHSound_Lose);
if (!StrEmpty(sSound))
BroadcastSoundToTeam(TFTeam_Spectator, sSound);
Forward_BossLose(TFTeam_Boss);
}
}
}
ArrayList aPlayersList = new ArrayList();
for (int iClient = 1; iClient <= MaxClients; iClient++)
{
if (IsClientInGame(iClient))
{
//End music
if (!StrEmpty(g_sBossMusic))
StopSound(iClient, SNDCHAN_STATIC, g_sBossMusic);
if (SaxtonHale_IsValidBoss(iClient, false))
{
//Clean up now to avoid stray particles
ClearBossEffects(iClient);
}
else if (GetClientTeam(iClient) > 1)
{
aPlayersList.Push(iClient);
if (!Client_HasFlag(iClient, ClientFlags_Punishment))
{
int iAddQueue = 10 + RoundToFloor(float(SaxtonHale_GetScore(iClient)) / 300.0);
if (iAddQueue > 20)
iAddQueue = 20;
if (iAddQueue < 10)
iAddQueue = 10;
Queue_AddPlayerPoints(iClient, iAddQueue);
}
}
}
}
g_sBossMusic = "";
char sPlayerNames[3][70];
sPlayerNames[0] = "----";
sPlayerNames[1] = "----";
sPlayerNames[2] = "----";
for (int iRank = 0; iRank < 3; iRank++)
{
int iBestPlayerIndex = -1;
int iLength = aPlayersList.Length;
int iBestScore = 0;
for (int i = 0; i < iLength; i++)
{
int iPlayer = aPlayersList.Get(i);
int iPlayerScore = SaxtonHale_GetScore(iPlayer);
if (iPlayerScore > iBestScore)
{
iBestScore = iPlayerScore;
iBestPlayerIndex = i;
}
}
if (iBestPlayerIndex != -1)
{
char sBufferName[59];
int iPlayer = aPlayersList.Get(iBestPlayerIndex);
GetClientName(iPlayer, sBufferName, sizeof(sBufferName));
Format(sPlayerNames[iRank], sizeof(sPlayerNames[]), "%s - %i", sBufferName, SaxtonHale_GetScore(iPlayer));
aPlayersList.Erase(iBestPlayerIndex);
}
}
delete aPlayersList;
float flHUD[2];
flHUD[0] = -1.0;
flHUD[1] = 0.3;
char sMessage[2048], sBuffer[256];
for (int iClient = 1; iClient <= MaxClients; iClient++)
{
SaxtonHaleBase boss = SaxtonHaleBase(iClient);
if (boss.bValid && !boss.bMinion)
{
if (!StrEmpty(sMessage)) StrCat(sMessage, sizeof(sMessage), "\n");
Format(sMessage, sizeof(sMessage), "%s%N as", sMessage, iClient);
//Get Modifiers name
if (boss.bModifiers)
{
boss.CallFunction("GetModifiersName", sBuffer, sizeof(sBuffer));
Format(sMessage, sizeof(sMessage), "%s %s", sMessage, sBuffer);
}
//Get Boss name
boss.CallFunction("GetBossName", sBuffer, sizeof(sBuffer));
//Format with health
if (IsPlayerAlive(iClient) && boss.iHealth > 0)
Format(sMessage, sizeof(sMessage), "%s %s had %d of %d HP left", sMessage, sBuffer, boss.iHealth, boss.iMaxHealth);
else
Format(sMessage, sizeof(sMessage), "%s %s died with %d max HP", sMessage, sBuffer, boss.iMaxHealth);
}
}
Format(sMessage, sizeof(sMessage), "%s\n1) %s \n2) %s \n3) %s ", sMessage, sPlayerNames[0], sPlayerNames[1], sPlayerNames[2]);
for (int iClient = 1; iClient <= MaxClients; iClient++)
{
if (IsClientInGame(iClient))
{
Format(sBuffer, sizeof(sBuffer), sMessage);
if (!SaxtonHale_IsValidBoss(iClient, false))
Format(sBuffer, sizeof(sBuffer), "%s\nYour damage: %d | Your assist: %d", sBuffer, g_iPlayerDamage[iClient], g_iPlayerAssistDamage[iClient]);
Hud_Display(iClient, CHANNEL_INTRO, sBuffer, flHUD, 10.0);
}
}
}
public void Event_PointCaptured(Event event, const char[] sName, bool bDontBroadcast)
{
if (!g_bEnabled) return;
TFTeam nTeam = view_as<TFTeam>(event.GetInt("team"));
Dome_SetTeam(nTeam);
}
public void Event_BroadcastAudio(Event event, const char[] sName, bool bDontBroadcast)
{
if (!g_bEnabled) return;
if (g_iTotalRoundPlayed <= 0) return;
char strSound[50];
event.GetString("sound", strSound, sizeof(strSound));
if (strcmp(strSound, "Game.TeamWin3") == 0
|| strcmp(strSound, "Game.YourTeamLost") == 0
|| strcmp(strSound, "Game.YourTeamWon") == 0
|| strcmp(strSound, "Announcer.AM_RoundStartRandom") == 0
|| strcmp(strSound, "Game.Stalemate") == 0)
SetEventBroadcast(event, true);
}
public void Event_PlayerSpawn(Event event, const char[] sName, bool bDontBroadcast)
{
if (!g_bEnabled) return;
if (g_iTotalRoundPlayed <= 0) return;
if (g_bSpawnTeamSwitch)
return;
int iClient = GetClientOfUserId(event.GetInt("userid"));
if (TF2_GetClientTeam(iClient) <= TFTeam_Spectator)
return;
if (g_bRoundStarted && SaxtonHale_IsValidAttack(iClient))
{
//Latespawn... get outa here
ForcePlayerSuicide(iClient);
return;
}
bool bRespawn;
TFClassType iOldClass = view_as<TFClassType>(event.GetInt("class"));
TFClassType iNewClass = ClassLimit_GetNewClass(iClient);
if (iOldClass != iNewClass && iNewClass != TFClass_Unknown)
{
TF2_SetPlayerClass(iClient, iNewClass);
bRespawn = true;
}
SaxtonHaleBase boss = SaxtonHaleBase(iClient);
for (int i = 1; i <= MaxClients; i++)
{
if (SaxtonHale_IsValidBoss(i, false))
{
if (!boss.bValid && TF2_GetClientTeam(iClient) != TFTeam_Attack)
{
TF2_ChangeClientTeam(iClient, TFTeam_Attack);
bRespawn = true;
}
break;
}
}
if (bRespawn)
{
TF2_RespawnPlayer(iClient);
return;
}
// Player spawned, if they are a boss, call their spawn function
if (boss.bValid)
boss.CallFunction("OnSpawn");
UpdateClientGlowEnt(iClient);
}
public Action Event_BuiltObject(Event event, const char[] sName, bool bDontBroadcast)
{
if (!g_bEnabled) return Plugin_Continue;
if (g_iTotalRoundPlayed <= 0) return Plugin_Continue;
int iClient = GetClientOfUserId(event.GetInt("userid"));
SaxtonHaleBase boss = SaxtonHaleBase(iClient);
if (boss.bValid)
return boss.CallFunction("OnBuildObject", event);
return Plugin_Continue;
}
public Action Event_ObjectHurt(Event event, const char[] sName, bool bDontBroadcast)
{
if (!g_bEnabled) return Plugin_Continue;
if (g_iTotalRoundPlayed <= 0) return Plugin_Continue;
int iBuilding = event.GetInt("entindex");
char sClassname[256];
GetEntityClassname(iBuilding, sClassname, sizeof(sClassname));
if (StrContains(sClassname, "obj_") != 0)
return Plugin_Continue;
int iAttacker = GetClientOfUserId(event.GetInt("attacker_player"));
if (0 < iAttacker <= MaxClients && TF2_GetClientTeam(iAttacker) == TFTeam_Attack)
{
g_iPlayerAssistDamage[iAttacker] += event.GetInt("damageamount");
}
else if (iAttacker == 0 && event.GetInt("weaponid") == 0)
{
//Assuming this is sapper damage, not sure if any other method can trigger this
int iSapper = TF2_GetSapper(iBuilding);
if (iSapper != INVALID_ENT_REFERENCE)
{
iAttacker = GetEntPropEnt(iSapper, Prop_Send, "m_hBuilder");
if (0 < iAttacker <= MaxClients && IsClientInGame(iAttacker) && TF2_GetClientTeam(iAttacker) == TFTeam_Attack)
g_iPlayerAssistDamage[iAttacker] += event.GetInt("damageamount");
}
}
return Plugin_Continue;
}
public Action Event_ObjectDestroyed(Event event, const char[] sName, bool bDontBroadcast)
{
if (!g_bEnabled) return Plugin_Continue;
if (g_iTotalRoundPlayed <= 0) return Plugin_Continue;
int iClient = GetClientOfUserId(event.GetInt("attacker"));
SaxtonHaleBase boss = SaxtonHaleBase(iClient);
if (boss.bValid)
{
char sSound[PLATFORM_MAX_PATH];
boss.CallFunction("GetSound", sSound, sizeof(sSound), VSHSound_KillBuilding);
if (!StrEmpty(sSound))
EmitSoundToAll(sSound, iClient, SNDCHAN_VOICE, SNDLEVEL_SCREAMING);
return boss.CallFunction("OnDestroyObject", event);
}
return Plugin_Continue;
}
public Action Event_SappedObject(Event event, const char[] sName, bool bDontBroadcast)
{
if (!g_bEnabled) return Plugin_Continue;
if (g_iTotalRoundPlayed <= 0) return Plugin_Continue;
int iVictim = GetClientOfUserId(event.GetInt("ownerid"));
SaxtonHaleBase boss = SaxtonHaleBase(iVictim);
if (boss.bValid)
return boss.CallFunction("OnObjectSapped", event);
return Plugin_Continue;
}
public Action Event_PlayerDeath(Event event, const char[] sName, bool bDontBroadcast)
{
if (!g_bEnabled) return Plugin_Continue;
if (g_iTotalRoundPlayed <= 0) return Plugin_Continue;
int iVictim = GetClientOfUserId(event.GetInt("userid"));
int iAttacker = GetClientOfUserId(event.GetInt("attacker"));
int iVictimTeam = GetClientTeam(iVictim);
if (iVictimTeam <= 1) return Plugin_Continue;
SaxtonHaleBase bossVictim = SaxtonHaleBase(iVictim);
SaxtonHaleBase bossAttacker = SaxtonHaleBase(iAttacker);
bool bDeadRinger = (event.GetInt("death_flags") & TF_DEATHFLAG_DEADRINGER) != 0;
int iSentry = TF2_GetBuilding(iVictim, TFObject_Sentry);
if (iSentry > MaxClients)
{
SetVariantInt(999999);
AcceptEntityInput(iSentry, "RemoveHealth");
}
if (!bDeadRinger && g_bRoundStarted)
Teuton_PlayerDeath(iVictim);
if (bossVictim.bValid)
{
//Call boss death
bossVictim.CallFunction("OnDeath", event);
CheckForceAttackWin(iVictim);
for (int iClient = 1; iClient <= MaxClients; iClient++)
{
if (iVictim != iClient && SaxtonHale_IsValidBoss(iClient, false))
{
char sSound[PLATFORM_MAX_PATH];
if (IsPlayerAlive(iClient)) //There another main boss alive, call death sound
bossVictim.CallFunction("GetSound", sSound, sizeof(sSound), VSHSound_Death);
if (StrEmpty(sSound)) //Otherwise just use lose sound
bossVictim.CallFunction("GetSound", sSound, sizeof(sSound), VSHSound_Lose);
if (!StrEmpty(sSound))
BroadcastSoundToTeam(TFTeam_Spectator, sSound);
break;
}
}
}
if (0 < iAttacker <= MaxClients && iVictim != iAttacker && IsClientInGame(iAttacker))
{
//Call boss kill
if (bossAttacker.bValid)
bossAttacker.CallFunction("OnPlayerKilled", event, iVictim);
}
if (g_bRoundStarted && !bDeadRinger && SaxtonHale_IsValidAttack(iVictim))
{
//Victim who died is still "alive" during this event, so we subtract by 1 to not count victim
int iLastAlive = SaxtonHale_GetAliveAttackPlayers() - 1;
if (iLastAlive >= 2)
{
//Play boss kill voiceline
if ((GetRandomInt(0, 1)) && 0 < iAttacker <= MaxClients && bossAttacker.bValid)
{
char sSound[PLATFORM_MAX_PATH];
bossAttacker.CallFunction("GetSoundKill", sSound, sizeof(sSound), TF2_GetPlayerClass(iVictim));
if (!StrEmpty(sSound))
EmitSoundToAll(sSound, iAttacker, SNDCHAN_VOICE, SNDLEVEL_SCREAMING);
}
}
if (iLastAlive == 1)
{
//Play last man voiceline
int iBoss = 0;
if (0 < iAttacker <= MaxClients && IsClientInGame(iAttacker))
{
iBoss = iAttacker;
}
else
{
for (int iClient = 1; iClient <= MaxClients; iClient++)
{
if (SaxtonHale_IsValidBoss(iClient, false) && IsPlayerAlive(iClient))
{
iBoss = iClient;
break;
}
}
}
SaxtonHaleBase boss = SaxtonHaleBase(iBoss);
if (iBoss != 0 && boss.bValid)
{
char sSound[PLATFORM_MAX_PATH];
boss.CallFunction("GetSound", sSound, sizeof(sSound), VSHSound_Lastman);
if (!StrEmpty(sSound))
BroadcastSoundToTeam(TFTeam_Spectator, sSound);
}
}
if (iLastAlive == 0)
{
//Kill any minions that are still alive
for (int i = 1; i <= MaxClients; i++)
{
if (IsClientInGame(i) && IsPlayerAlive(i) && i != iVictim && GetClientTeam(i) == iVictimTeam)
{
SDKHooks_TakeDamage(i, 0, i, 99999.0);
ForcePlayerSuicide(i);
}
}
}
}
if (g_bRoundStarted && !bDeadRinger)
g_iClientOwner[iVictim] = 0;
return Plugin_Changed;
}
public void Event_PlayerInventoryUpdate(Event event, const char[] sName, bool bDontBroadcast)
{
if (!g_bEnabled) return;
int iClient = GetClientOfUserId(event.GetInt("userid"));
if (GetClientTeam(iClient) <= 1) return;
TF2_CheckClientWeapons(iClient);
if (SaxtonHale_IsValidAttack(iClient))
{
/*Balance specific weapons*/
TFClassType nClass = TF2_GetPlayerClass(iClient);
for (int iSlot = 0; iSlot <= WeaponSlot_InvisWatch; iSlot++)
{
int iWeapon = TF2_GetItemInSlot(iClient, iSlot);
if (iWeapon <= MaxClients)
{
//No weapon in this slot, may be removed from GiveNamedItem hook
//Generate default weapon index for class and slot
int iIndex = g_iDefaultWeaponIndex[view_as<int>(nClass)][iSlot];
if (iIndex >= 0)
iWeapon = TF2_CreateAndEquipWeapon(iClient, iIndex, .bAttrib = true);
}
if (iWeapon > MaxClients)
{
// Balance weapons, not including 1st round
if (g_iTotalRoundPlayed > 0)
{
int iIndex = GetEntProp(iWeapon, Prop_Send, "m_iItemDefinitionIndex");
for (int i = 0; i <= 1; i++)
{
char sAttrib[255], atts[32][32];
// Give attribs in class slot and specific index
switch (i)
{
case 0: g_ConfigClass[nClass][iSlot].GetAttrib(sAttrib, sizeof(sAttrib));
case 1: g_ConfigIndex.GetAttrib(iIndex, sAttrib, sizeof(sAttrib));
}
int count = ExplodeString(sAttrib, " ; ", atts, 32, 32);
if (count > 1)
{
for (int j = 0; j < count; j+= 2)
TF2Attrib_SetByDefIndex(iWeapon, StringToInt(atts[j]), StringToFloat(atts[j+1]));
TF2Attrib_ClearCache(iWeapon);
}
// Set clip size to weapon in both class slot and specific index
int iClip = -1;
switch (i)
{
case 0: iClip = g_ConfigClass[nClass][iSlot].GetClip();
case 1: iClip = g_ConfigIndex.GetClip(iIndex);
}
if (iClip > -1)
SetEntProp(iWeapon, Prop_Send, "m_iClip1", iClip);
}
}
}
}
}
if (g_iTotalRoundPlayed <= 0) return;
Tags_ResetClient(iClient);
TagsCore_RefreshClient(iClient);
if (SaxtonHale_IsValidAttack(iClient))
TagsCore_CallAll(iClient, TagsCall_Spawn);
}
public void Event_PlayerHurt(Event event, const char[] sName, bool bDontBroadcast)
{
if (!g_bEnabled) return;
if (g_iTotalRoundPlayed <= 0) return;
int iClient = GetClientOfUserId(event.GetInt("userid"));
if (GetClientTeam(iClient) <= 1) return;
SaxtonHaleBase boss = SaxtonHaleBase(iClient);
if (boss.bValid)
{
int iAttacker = GetClientOfUserId(event.GetInt("attacker"));
int iDamageAmount = event.GetInt("damageamount");
if (0 < iAttacker <= MaxClients && IsClientInGame(iAttacker) && iClient != iAttacker && TF2_GetClientTeam(iAttacker) == TFTeam_Attack)
{
boss.CallFunction("AddRage", iDamageAmount);
//Damage if main boss, assist damage if minion
if (!boss.bMinion)
g_iPlayerDamage[iAttacker] += iDamageAmount;
else
g_iPlayerAssistDamage[iAttacker] += iDamageAmount;
int iAttackTeam = GetClientTeam(iAttacker);
//Award assist damage if Client has a owner
int iOwner = g_iClientOwner[iAttacker];
if (0 < iOwner <= MaxClients && IsClientInGame(iOwner))
g_iPlayerAssistDamage[iOwner] += iDamageAmount;
for (int i = 1; i <= MaxClients; i++)
{
if (IsClientInGame(i) && GetClientTeam(i) == iAttackTeam && i != iAttacker)
{
if (g_bClientAreaOfEffect[i][iAttacker])
{
//Under area of effect
g_iPlayerAssistDamage[i] += iDamageAmount;
continue;
}
int iSecondaryWep = GetPlayerWeaponSlot(i, WeaponSlot_Secondary);
char weaponSecondaryClass[32];
if (iSecondaryWep >= 0)
GetEdictClassname(iSecondaryWep, weaponSecondaryClass, sizeof(weaponSecondaryClass));
//Award damage assit to healers
if (strcmp(weaponSecondaryClass, "tf_weapon_medigun") != 0)
continue;
int iHealTarget = GetEntPropEnt(iSecondaryWep, Prop_Send, "m_hHealingTarget");
if (iHealTarget == iAttacker)
{
g_iPlayerAssistDamage[i] += iDamageAmount;
}
else if (iHealTarget > MaxClients) //Buildings
{
char sClassname[64];
GetEdictClassname(iHealTarget, sClassname, sizeof(sClassname));
//Check if healer is healing sentry gun, with attacker as builder
if (strcmp(sClassname, "obj_sentrygun") == 0 && GetEntPropEnt(iHealTarget, Prop_Send, "m_hBuilder") == iAttacker)
{
g_iPlayerAssistDamage[i] += iDamageAmount;
}
}
}
}
}
}
}
public void Event_BuffBannerDeployed(Event event, const char[] sName, bool bDontBroadcast)
{
if (!g_bEnabled) return;
if (g_iTotalRoundPlayed <= 0) return;
int iClient = GetClientOfUserId(event.GetInt("buff_owner"));
if (GetClientTeam(iClient) <= 1 || SaxtonHale_IsValidBoss(iClient)) return;
TagsCore_CallAll(iClient, TagsCall_Banner);
}
public void Event_UberDeployed(Event event, const char[] sName, bool bDontBroadcast)
{
if (!g_bEnabled) return;
if (g_iTotalRoundPlayed <= 0) return;
int iClient = GetClientOfUserId(GetEventInt(event, "userid"));
if (GetClientTeam(iClient) <= 1 || SaxtonHale_IsValidBoss(iClient)) return;
TagsCore_CallAll(iClient, TagsCall_Uber);
}
public Action Event_Jarated(UserMsg msg_id, Handle msg, const int[] players, int playersNum, bool reliable, bool init)
{
if (!g_bEnabled) return Plugin_Continue;
if (g_iTotalRoundPlayed <= 0) return Plugin_Continue;
int iThrower = BfReadByte(msg);
int iVictim = BfReadByte(msg);
if (GetClientTeam(iThrower) <= 1 || SaxtonHale_IsValidBoss(iThrower)) return Plugin_Continue;
SaxtonHaleBase bossVictim = SaxtonHaleBase(iVictim);
if (GetClientTeam(iVictim) <= 1 || !bossVictim.bValid) return Plugin_Continue;
TagsParams tParams = new TagsParams();
tParams.SetInt("victim", iVictim);
//Possible crash if called in same frame
DataPack data = new DataPack();
data.WriteCell(GetClientUserId(iThrower));
data.WriteCell(tParams);
RequestFrame(Frame_CallJarate, data);
return Plugin_Continue;
}