-
Notifications
You must be signed in to change notification settings - Fork 7
/
berobot_handler.sp
2914 lines (2316 loc) · 91.4 KB
/
berobot_handler.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
#define PLUGIN_NAME "Giant Robot Plugin Handler"
#define PLUGIN_DESCRIPTION "Handles backstab modifier as well as other functions for the giant robot plugins"
#define PLUGIN_AUTHOR "Fragancia & Heavy Is GPS"
#define PLUGIN_VERSION "1.0.0"
#define PLUGIN_URL "bmod.tf"
#define RED 3
#define BLUE 2
#define SPECTATE 1
#define UNASSIGNED 0
#include <berobot_constants>
#include <berobot>
#include <berobot_core_restrictions>
#include <morecolors>
#include <sdkhooks>
#include <sdktools>
#include <sm_logger>
#include <sourcemod>
#include <tf2>
#include <tf2_stocks>
#include <tf_ontakedamage>
#include <tf2_isPlayerInSpawn>
#include <particle>
// #include <stocksoup/memory>
// #include <stocksoup/tf/entity_prop_stocks>
// #include <stocksoup/tf/tempents_stocks>
// #include <stocksoup/tf/weapon>
#include <dhooks>
#include <tf2attributes>
char LOG_TAGS[][] = {"VERBOSE", "INFO", "ERROR"};
enum (<<= 1)
{
SML_VERBOSE = 1,
SML_INFO,
SML_ERROR,
}
#include <berobot_core>
#pragma newdecls required
#pragma semicolon 1
#define RESISTANCE "player/resistance_medium4.wav"
enum //Convar names
{
CV_g_Rtr_precent,
CV_flSpyBackStabModifier,
CV_bDebugMode,
CV_flYoutuberMode,
CV_g_RoboCapTeam,
CV_g_RoboCap,
CV_g_RoboTeamMode,
CV_g_RoboMode,
CV_g_RoboStartTeam,
CV_g_Enable,
CV_g_AprilEnable,
CV_PluginVersion
}
enum {
dmg_method_on_target,
dmg_method_off_target
}
/* Global Variables */
/* Global Handles */
//Handle g_hGameConf;
/* Dhooks */
/* Convar Handles */
ConVar g_cvCvarList[CV_PluginVersion + 1];
/* Convar related global variables */
bool g_cv_bDebugMode;
bool g_BossMode = false;
bool g_cv_BlockTeamSwitch = false;
bool g_SpectateSelection = false;
bool g_WaitingForPlayers = true;
bool g_cv_Volunteered[MAXPLAYERS + 1];
char g_cv_RobotPicked[MAXPLAYERS + 1][NAMELENGTH];
bool g_Voted[MAXPLAYERS + 1];
bool g_GoingToDie[MAXPLAYERS + 1] = {false, ...};
int g_TimeBombTime[MAXPLAYERS+1] = { 0, ... };
int g_PlayerHealth[MAXPLAYERS +1] = {-1, ...};
GlobalForward _enabledChangedForward;
GlobalForward _clientResetting;
GlobalForward _modeResetRequestedForward;
GlobalForward _wasRandomRobotForward;
// float g_CV_flSpyBackStabModifier;
float g_Rtr_percent;
int g_CV_flYoutuberMode;
int g_Enable;
int g_RoboCapTeam;
int g_RoboTeam;
int g_HumanTeam;
int g_RoboCap;
int g_RoboTeamMode;
int g_RoboStartTeam;
int g_RoboMode;
int g_iVotes;
int g_iVotesNeeded;
int g_AprilEnable;
float g_f_Damage_Bonus = 1.0;
float g_f_previous_dmg_bonus = -1.0;
//bool g_IsAprilRTD[MAXPLAYERS + 1] = false;
float g_cr_cooldown[MAXPLAYERS + 1] = {0.0,...};
bool b_g_high_power = false;
int g_RoundCount;
// int g_TankCount;
// int b_is_koth;
// int koth_caps;
ArrayList g_Volunteers;
// Handle g_SDKCallInternalGetEffectBarRechargeTime;
// Handle g_SDKCallIsBaseEntityWeapon;
//In Global Scope
Handle g_hRegen;
Handle g_hGameConf;
Handle g_hIsDeflectable;
//Handle g_m_bTeamsSwitched;
//In OnPluginStart
// Global scope
public Plugin myinfo =
{
name = PLUGIN_NAME,
author = PLUGIN_AUTHOR,
description = PLUGIN_DESCRIPTION,
version = PLUGIN_VERSION,
url = PLUGIN_URL
};
public void OnPluginStart()
{
SMLoggerInit(LOG_TAGS, sizeof(LOG_TAGS), SML_ERROR, SML_FILE);
SMLogTag(SML_INFO, "berobot_handler started at %i", GetTime());
/* Convars */
//
g_cvCvarList[CV_PluginVersion] = CreateConVar("sm_mm_version", PLUGIN_VERSION, "Plugin Version.", FCVAR_NOTIFY | FCVAR_DONTRECORD | FCVAR_CHEAT);
//Gamemode cvar
g_cvCvarList[CV_g_Enable] = CreateConVar("sm_mm_enable", "0", "0 = Manned Machines disabled, 1 = Manned Machines enabled", FCVAR_NOTIFY, true, 0.0, true, 1.0);
g_cvCvarList[CV_g_AprilEnable] = CreateConVar("sm_mm_april_enable", "0", "0 = Manned Machines april fools disabled, 1 = Manned Machines april fools enabled", FCVAR_NOTIFY, true, 0.0, true, 1.0);
g_cvCvarList[CV_bDebugMode] = CreateConVar("sm_mm_debug", "0", "Enable Debugging for Manned Machines Mode", FCVAR_NOTIFY, true, 0.0, true, 1.0);
g_cvCvarList[CV_g_RoboCapTeam] = CreateConVar(CONVAR_ROBOCAP_TEAM, "6", "The total amount of giant robots on a team");
g_cvCvarList[CV_g_RoboCap] = CreateConVar("sm_robocap", "1", "The amount of giant robots allowed per robot-type");
g_cvCvarList[CV_g_RoboTeamMode] = CreateConVar("sm_both_teams_have_robots", "0", "0 = One Team consists only of robots, 1 = Both teams have bots");
g_cvCvarList[CV_g_RoboMode] = CreateConVar("sm_robo_mode", "0", "0 = Starts the mode when waiting for players is over, 1 = Start game by reaching enough volunteers");
g_cvCvarList[CV_g_RoboStartTeam] = CreateConVar("sm_robot_random_start_team", "1", "0 = Robots always start on red, 1 = Robot team is randomly picked RED or BLUE, 2 = Robots Always starts on blue");
g_cvCvarList[CV_g_Rtr_precent] = CreateConVar("sm_mm_needed_rtr_ratio", "0.5", "The ratio of votes needed to start the mode with !rtr 1.0 = 100% 0.0 = 0%");
//Gameplay cvar
g_cvCvarList[CV_flSpyBackStabModifier] = CreateConVar("sm_robo_backstab_damage", "83.3", "Backstab damage that will be multipled by crit multiplier");
g_cvCvarList[CV_flYoutuberMode] = CreateConVar("sm_mm_yt_mode", "0", "Uses youtuber mode for the official mode to set youtubers as the proper classes");
/* Convar global variables init */
g_Enable = GetConVarInt(g_cvCvarList[CV_g_Enable]);
g_AprilEnable = GetConVarInt(g_cvCvarList[CV_g_AprilEnable]);
g_cv_bDebugMode = GetConVarBool(g_cvCvarList[CV_bDebugMode]);
//g_CV_flSpyBackStabModifier = GetConVarFloat(g_cvCvarList[CV_flSpyBackStabModifier]);
g_Rtr_percent = GetConVarFloat(g_cvCvarList[CV_g_Rtr_precent]);
g_RoboCapTeam = GetConVarInt(g_cvCvarList[CV_g_RoboCapTeam]);
g_RoboCap = GetConVarInt(g_cvCvarList[CV_g_RoboCap]);
g_RoboTeamMode = GetConVarInt(g_cvCvarList[CV_g_RoboTeamMode]);
g_RoboStartTeam = GetConVarInt(g_cvCvarList[CV_g_RoboStartTeam]);
g_RoboMode = GetConVarInt(g_cvCvarList[CV_g_RoboMode]);
g_CV_flYoutuberMode = GetConVarInt(g_cvCvarList[CV_flYoutuberMode]);
/* Convar Change Hooks */
g_cvCvarList[CV_bDebugMode].AddChangeHook(CvarChangeHook);
g_cvCvarList[CV_g_Enable].AddChangeHook(CvarChangeHook);
g_cvCvarList[CV_g_AprilEnable].AddChangeHook(CvarChangeHook);
g_cvCvarList[CV_flSpyBackStabModifier].AddChangeHook(CvarChangeHook);
g_cvCvarList[CV_flYoutuberMode].AddChangeHook(CvarChangeHook);
g_cvCvarList[CV_g_RoboCapTeam].AddChangeHook(CvarChangeHook);
g_cvCvarList[CV_g_RoboCap].AddChangeHook(CvarChangeHook);
g_cvCvarList[CV_g_RoboTeamMode].AddChangeHook(CvarChangeHook);
g_cvCvarList[CV_g_RoboStartTeam].AddChangeHook(CvarChangeHook);
g_cvCvarList[CV_g_RoboMode].AddChangeHook(CvarChangeHook);
g_cvCvarList[CV_g_Rtr_precent].AddChangeHook(CvarChangeHook);
_enabledChangedForward = new GlobalForward("MM_OnEnabledChanged", ET_Ignore, Param_Cell);
_clientResetting = new GlobalForward("MM_OnClientResetting", ET_Ignore, Param_Cell);
_modeResetRequestedForward = new GlobalForward("MM_ModeResetRequested", ET_Ignore);
_wasRandomRobotForward = new GlobalForward("MM_WasRandomRobotForward", ET_Ignore, Param_Cell);
RegAdminCmd("sm_makerobot", Command_BeRobot, ADMFLAG_SLAY, "Become a robot");
RegAdminCmd("sm_mr", Command_BeRobot, ADMFLAG_SLAY, "Become a robot");
RegAdminCmd("sm_boss_mode", Command_YT_Robot_Start, ADMFLAG_SLAY, "Sets up the team and starts the robot");
RegAdminCmd("sm_selection_mode", Command_Robot_Selection, ADMFLAG_SLAY, "Forces selection mode");
RegAdminCmd("sm_me_boss", Command_Me_Boss, ADMFLAG_SLAY, "Checks if you are a boss");
RegAdminCmd("sm_random_robot", Command_SetRandomRobot, ADMFLAG_SLAY, "Checks if you are a boss");
RegAdminCmd("sm_toggle_team_switch", Command_ToggleTeamSwitch, ADMFLAG_SLAY, "Toggles allowing teamswitch");
RegConsoleCmd("sm_rtr", Command_RoboVote, "Votes to begin a mode");
RegConsoleCmd("sm_rocktherobot", Command_RoboVote, "Votes to begin a mode");
RegConsoleCmd("sm_changerobot", Command_ChangeRobot, "change your robot");
RegConsoleCmd("sm_chngrbt", Command_ChangeRobot, "change your robot");
RegConsoleCmd("sm_cr", Command_ChangeRobot, "change your robot");
RegConsoleCmd("sm_bot", Command_ChangeRobot, "change your robot");
RegConsoleCmd("sm_robot", Command_ChangeRobot, "change your robot");
RegConsoleCmd("sm_mount", Command_MountRobot, "get a taunt mount for your robot");
RegConsoleCmd("sm_mt", Command_MountRobot, "get a taunt mount for your robot");
RegConsoleCmd("sm_car", Command_MountRobot, "get a taunt mount for your robot");
RegConsoleCmd("sm_w", Command_TauntHuman, "get a taunt mount for your robot");
RegConsoleCmd("sm_showstats", Command_ShowStats, "Shows stats in the MvM upgrade menu");
RegConsoleCmd("sm_showstat", Command_ShowStats, "Shows stats in the MvM upgrade menu");
RegConsoleCmd("sm_mystat", Command_ShowStats, "Shows stats in the MvM upgrade menu");
RegConsoleCmd("sm_mystats", Command_ShowStats, "Shows stats in the MvM upgrade menu");
//April Fools
//RegConsoleCmd("sm_rtd", Command_RTDRobot, "become random robot");
AddCommandListener(Block_Kill, "kill");
AddCommandListener(Block_Kill, "explode");
//AddCommandListener(cmd_blocker, "autoteam");
AddCommandListener(cmd_blocker, "changeclass");
AddCommandListener(cmd_blocker, "joinclass");
AddCommandListener(cmd_blocker, "join_class");
// AddCommandListener(cmd_blocker, "load_itempreset 0");
// AddCommandListener(cmd_blocker, "load_itempreset 1");
// AddCommandListener(cmd_blocker, "load_itempreset 2");
AddCommandListener(cmd_blocker, "tf_respawn_on_loadoutchanges 1");
/* Hooks */
HookEvent("teamplay_round_start", Event_teamplay_round_start, EventHookMode_Post);
HookEvent("teamplay_round_start", Event_Waiting_Abouttoend, EventHookMode_Post);
// SetTeamCoinsFor(1,2);
// HookEvent("teamplay_point_captured", Event_Teamplay_Point_Captured, EventHookMode_Post);
HookEvent("player_death", Event_Death, EventHookMode_Post);
HookEvent("player_spawn", Event_PlayerSpawn, EventHookMode_Post);
// HookEvent("post_inventory_application", Event_post_inventory_application, EventHookMode_Post);
g_Volunteers = new ArrayList(ByteCountToCells(g_RoboCapTeam));
g_Volunteers.Clear();
//Loading code where robots can't use resupply lockers
g_hGameConf = LoadGameConfigFile("sm-tf2.games");
if(g_hGameConf == null)
SetFailState("Failed to setup gamedata!");
g_hRegen = DHookCreateDetour(Address_Null, CallConv_THISCALL, ReturnType_Void, ThisPointer_CBaseEntity);
if(g_hRegen == null)
SetFailState("Failed to setup OnRegenerate hook!");
if(!DHookSetFromConf(g_hRegen, g_hGameConf, SDKConf_Signature, "Regenerate"))
SetFailState("Failed to config Regenerate signature!");
DHookAddParam(g_hRegen, HookParamType_Bool);
if(!DHookEnableDetour(g_hRegen, false, OnRegenerate))
SetFailState("Failed to detour OnRegenerate!");
// g_hGameConf = LoadGameConfigFile("bm_charge_airblast_immunity_data");
// //IsDeflectable
// // g_hIsDeflectable = DHookCreate(0, HookType_Entity, ReturnType_Bool, ThisPointer_CBaseEntity, IsPlayerDeflectable);
// // if(g_hIsDeflectable == null) SetFailState("Failed to setup hook for CTFPlayer::IsDeflectable!");
// if(!DHookSetFromConf(g_hIsDeflectable, g_hGameConf, SDKConf_Virtual, "CTFPlayer::IsDeflectable"))
// SetFailState("Failed to find CTFPlayer::IsDeflectable offset in the gamedata!");
// //Finds players to hook for IsDeflectable
// // FindAndHookPlayers();
delete g_hGameConf;
}
// void FindAndHookPlayers()
// {
// for(int i = 1; i <= MaxClients+1; i++)
// {
// if(IsValidClient(i))
// {
// DHookEntity(g_hIsDeflectable, false, i);
// }
// }
// }
public void MM_robotChangedInSpawn(int client)
{
// PrintToChatAll("Robot changed in spawn for %N", client);
CreateTimer(1.0, Timer_SetHealth_Changed, client);
}
public void OnClientPutInServer(int client)
{
// DHookEntity(g_hIsDeflectable, false, client);
g_PlayerHealth[client] = -1;
}
// public MRESReturn IsPlayerDeflectable(int pThis, Handle hReturn, Handle hParams)
// {
// //PrintToChatAll("Shouldn't airblast target %N", pThis);
// //int clientID = GetClientOfUserId(pThis);
// // if(IsTank(pThis))
// // {
// // // PrintToChatAll("Shouldn't airblast target %N", pThis);
// // DHookSetReturn(hReturn, false);
// // EmitSoundToAll(RESISTANCE, pThis);
// // return MRES_Override;
// // }
// return MRES_Ignored;
// }
public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
{
CreateNative("GetRobotCap", Native_GetRobotCap);
CreateNative("GetRobotCountPerTeam", Native_GetRobotCountPerTeam);
CreateNative("SetVolunteers", Native_SetVolunteers);
CreateNative("EnsureRobotCount", Native_EnsureRobotCount);
CreateNative("IsEnabled", Native_IsEnabled);
CreateNative("IsYTEnabled", Native_IsYTEnabled);
CreateNative("IsActive", Native_IsActive);
CreateNative("UnmakeRobot", Native_UnmakeRobot);
CreateNative("RedrawChooseRobotMenu", Native_RedrawChooseRobotMenu);
CreateNative("RedrawChooseRobotMenuFor", Native_RedrawChooseRobotMenuFor);
CreateNative("SetRandomRobot", Native_SetRandomRobot);
CreateNative("SetRobot", Native_SetRobot);
CreateNative("ForceRobot", Native_ForceRobot);
CreateNative("GetRobotTeam", Native_GetRobotTeam);
CreateNative("AddPlayerHealth", Native_AddPlayerHealth);
// CreateNative("GetRobotCount", Native_GetCurrentRobotCount);
// CreateNative("GetHumanCount", Native_GetCurrentHumanCount);
return APLRes_Success;
}
public void OnMapStart()
{
g_WaitingForPlayers = true;
g_RoundCount = 0;
ResetMode();
g_RoboTeam = -1;
PrecacheSound(RESISTANCE);
// b_is_koth = GameRules_GetProp("m_bPlayingKoth");
// koth_caps = 0;
}
public void ResetMode()
{
g_cv_BlockTeamSwitch = false;
g_BossMode = false;
g_SpectateSelection = false;
g_iVotes = 0;
g_Volunteers.Clear();
for(int i = 0; i <= MAXPLAYERS; i++)
{
g_cv_Volunteered[i] = false;
g_cv_RobotPicked[i] = "";
g_Voted[i] = false;
}
int totalplayers = RoundToCeil(float(GetClientCount(false)) * g_Rtr_percent);
g_iVotesNeeded = totalplayers;
//g_iVotesNeeded = 6;
Call_StartForward(_modeResetRequestedForward);
Call_Finish();
}
public void OnClientDisconnect_Post(int client)
{
Reset(client);
}
void Reset(int client)
{
if(!g_cv_Volunteered[client])
return;
char robotName[NAMELENGTH];
robotName = g_cv_RobotPicked[client];
g_cv_Volunteered[client] = false;
g_cv_RobotPicked[client] = "";
int index = FindValueInArray(g_Volunteers, client);
if (index >= 0)
g_Volunteers.Erase(index);
Call_StartForward(_clientResetting);
Call_PushCell(client);
Call_Finish();
RedrawChooseRobotMenu();
EnsureRobotCount();
}
/* Publics */
public Action Event_PlayerSpawn(Event event, const char[] name, bool dontBroadcast)
{
int client = GetClientOfUserId(GetEventInt(event, "userid"));
// RequestFrame(RobotTeamCheck, client);
if (!g_AprilEnable) RequestFrame(RobotTeamCheck, client);//dont check robo teams if april fools mode is on
if (IsAnyRobot(client)){
//PrintToChatAll("%N spawned, checking if boss", client);
// if (!g_AprilEnable) RequestFrame(RobotTeamCheck, client);//dont check robo teams if april fools mode is on
// else
// {
// MC_PrintToChatEx(client, client, "{teamcolor}You're a robot on the robot team!");
// }
MC_PrintToChatEx(client, client, "{teamcolor}Type {orange}!bot{teamcolor} or {orange}change class{teamcolor} in spawn to change robot!");
MC_PrintToChatEx(client, client, "{teamcolor}Type {orange}!car{teamcolor} get a car to move faster!");
if(g_cv_bDebugMode)PrintToChatAll("%N spawned, with %i health from previous life", client, g_PlayerHealth[client]);
//FakeClientCommand(client, "tf_respawn_on_loadoutchanges 0");
if (g_PlayerHealth[client] > 0){
//PrintToChatAll("Player didn't die, setting health!");
CreateTimer(1.0, Timer_SetHealth, client);
}
}
if (!IsAnyRobot(client)){
if (g_AprilEnable && g_BossMode && g_Enable)
{
CreateTimer(0.1, SetRandomRobot_Timer, client);
}
}
// int Humans = GetTeamClientCount(g_HumanTeam);
// if (!IsBoss(client)){
// SetEntProp(client, Prop_Send, "m_bGlowEnabled", 0);
// } // int Robots = GetTeamClientCount(g_RoboTeam);
// PrintToChatAll("Human players %i, robot players %i", Humans, Robots);
}
// public Action Boss_check(Handle timer, any client)
// {
// if (IsValidClient(client) && IsPlayerAlive(client))
// {
// //int clientId = GetClientUserId(client);
// if (IsAnyRobot(client))
// {
// MC_PrintToChatEx(client, client, "{teamcolor}Type {orange}!cr{teamcolor} to change robot!");
// if (IsBoss(client))
// {
// // PrintToChatAll("Setting boss to %N", client);
// ServerCommand("sm_setbosshud #%i", client);
// }
// // else
// // {
// // PrintToChatAll("Did not find boss on %N", client);
// // }
// }
// }
// }
// bool IsBoss(client)
// {
// char robotName[NAMELENGTH];
// Robot robot;
// GetRobot(client, robotName, NAMELENGTH);
// GetRobotDefinition(robotName, robot);
// if (StrEqual(robot.role,"ZBOSS"))
// {
// PrintToChatAll("Robot role in handler: %s", robot.role);
// return true;
// }else
// {
// return false;
// }
// }
public Action Event_Death(Event event, const char[] name, bool dontBroadcast)
{
int attacker = GetClientOfUserId(GetEventInt(event, "attacker"));
int victim = GetClientOfUserId(GetEventInt(event, "userid"));
int assister = GetClientOfUserId(GetEventInt(event, "assister"));
//EmitSoundToAll("Announcer.MVM_General_Destruction",victim, 7);
//EmitAmbientGameSound("Announcer.MVM_General_Destruction");
// EmitGameSoundToAll("Announcer.MVM_General_Destruction", victim);
//EmitGameSoundToAll("Announcer.MVM_General_Destruction");
//EmitGameSoundToAll("Announcer.MVM_Engineer_Teleporter_Activated");
//PrintToChatAll("You died %N", victim);
//GetRobotNames();
//EmitGameSoundToAll("Announcer.MVM_General_Destruction");
// if (!IsAnyRobot(victim) && IsAnyRobot(attacker))
// {
// //PrintChatAll("You are not a robot %N", victim);
// if (TF2_GetPlayerClass(victim) == TFClass_Scout){
// CreateTimer(6.0, Timer_Respawn, victim);
// }
// }
//Removes the robot ragdoll and causes explosion
if (IsAnyRobot(victim))
{
// int clientIndex = -1;
//To deal with players using loadout switches to gain health back
g_PlayerHealth[victim] = -1;
CreateTimer(0.0, RemoveBody, victim);
float position[3];
GetEntPropVector(victim, Prop_Data, "m_vecOrigin", position);
int attach = CreateEntityByName("trigger_push");
TeleportEntity(attach, position, NULL_VECTOR, NULL_VECTOR);
// if (IsBoss(victim)){
// TE_Particle("fireSmokeExplosion2", position, _, _, attach, 1,0);
// }else{
TE_Particle("hightower_explosion", position, _, _, attach, 1,0);
// EmitGameSoundToAll("Announcer.MVM_General_Destruction");
// }
// }
// KillRune();
}
// if (!IsAnyRobot(victim) && IsAnyRobot(attacker))
// {
// // for(int i = 1; i <= MaxClients; i++)
// // {
// // if (IsValidClient(i) && !IsAnyRobot(i))
// // {
// // // clientIndex = GetClien(i);
// // ServerCommand("sm_addpoints #%d 5", GetClientUserId(i));
// // MC_PrintToChat(i, "{orange} gained 5 powerup points{white} when robot died");
// // }
// // }
// // clientIndex = GetClientOfUserId(attacker);
// // int death_flags = GetEventInt(event, "death_flags");
// // if((death_flags & TF_DEATHFLAG_DEADRINGER) != TF_DEATHFLAG_DEADRINGER) // Not a dead ringer death?
// // {
// // ServerCommand("sm_addpoints #%d 7", GetClientUserId(victim));
// // MC_PrintToChat(victim, "{orange}You gained 7 Power Points");
// // }
// // if(IsValidClient(attacker))MC_PrintToChat(attacker, "{orange}Got 15 powerup points{white} for killing robot");
// // // clientIndex = GetClientOfUserId(assister);
// // ServerCommand("sm_addpoints #%d 15", assister);
// // if(IsValidClient(assister))MC_PrintToChat(assister, "{orange}Got 15 points{white} for assisting robot death");
// }
// if (g_AprilEnable && g_IsAprilRTD[victim])
// {
// char weapon_logname[MAX_NAME_LENGTH];
// GetEventString(event, "weapon_logclassname", weapon_logname, sizeof(weapon_logname));
// //PrintToChatAll("Weapon_Logname was %s", weapon_logname);
// if (StrEqual(weapon_logname, "player", true) || StrEqual(weapon_logname, "trigger", true) || StrEqual(weapon_logname, "world", true))
// {
// //PrintToChatAll("Logname %s, STILL RTD", weapon_logname);
// g_IsAprilRTD[victim] = true;
// }else
// {
// //PrintToChatAll("Logname %s, NO LONGER RTD", weapon_logname);
// g_IsAprilRTD[victim] = false;
// }
// }
// fireSmokeExplosion//
//
g_GoingToDie[victim] = false;
}
public Action RemoveBody(Handle timer, any client)
{
if (HasEntProp(client, Prop_Send, "m_hRagdoll"))
{
int BodyRagdoll = GetEntPropEnt(client, Prop_Send, "m_hRagdoll");
if(IsValidEdict(BodyRagdoll))
{
AcceptEntityInput(BodyRagdoll, "kill");
}
}
}
// public Action Timer_Respawn(Handle timer, any client)
// {
// //PrintToChatAll("Timebomb: %i", g_TimeBombTime[client]);
// if (IsValidClient(client) && !IsPlayerAlive(client))
// {
// TF2_RespawnPlayer(client);
// //PrintHintText(client,"You have instant respawn as scout");
// }
// }
public Action SetRandomRobot_Timer(Handle timer, any client)
{
if (!IsAnyRobot(client))
{
Internal_SetRandomRobot(client);
}
}
//
//
// bool b_TankCheckClamp = false;
// public Action Event_post_inventory_application(Event event, const char[] name, bool dontBroadcast)
// {
// int client = GetClientOfUserId(GetEventInt(event, "userid"));
// if (IsTank(client) && !b_TankCheckClamp)
// {
// CreateTimer(3.0, Timer_TankCheck);
// b_TankCheckClamp = true;
// }
// }
// public Action Timer_TankCheck(Handle timer)
// {
// int TankCount = 0;
// for(int i = 1; i <= MaxClients; i++)
// {
// if (IsTank(i))
// {
// if(g_cv_bDebugMode)PrintToChatAll("%N was a tank", i);
// TankCount++;
// }
// }
// if (TankCount == 1)
// {
// EmitGameSoundToAll("Announcer.MVM_Tank_Alert_Spawn");
// }
// if (TankCount == 2)
// {
// EmitGameSoundToAll("Announcer.MVM_Tank_Alert_Another");
// }
// if (TankCount > 2)
// {
// EmitGameSoundToAll("Announcer.MVM_Tank_Alert_Multiple");
// }
// if(g_cv_bDebugMode)PrintToChatAll("Tank count was %i", TankCount);
// b_TankCheckClamp = false;
// }
public Action Timer_Regen(Handle timer, any client)
{
TF2_RegeneratePlayer(client);
}
public Action Timer_SetHealth(Handle timer, any client)
{
// PrintToChatAll("Set normal hp");
SetRoboSpawnHealth(client, false);
}
public Action Timer_SetHealth_Changed(Handle timer, any client)
{
// PrintToChatAll("Changed in spawn");
SetRoboSpawnHealth(client, true);
}
void SetRoboSpawnHealth(int client, bool changed_in_spawn)
{
int currenthealth = GetClientHealth(client);
if (g_cv_bDebugMode)PrintToChatAll("Current health %i", currenthealth);
if (g_cv_bDebugMode)PrintToChatAll("g_Player health for %N was %i", client, g_PlayerHealth[client]);
if (g_PlayerHealth[client] < currenthealth && g_PlayerHealth[client] != -1)
{
if (!IsBoss(client) || !changed_in_spawn)
{
TF2_SetHealth(client, g_PlayerHealth[client]);
}
}
}
public Action Event_Waiting_Abouttoend(Event event, const char[] name, bool dontBroadcast)
{
if(g_Enable && g_RoundCount == 0){
// PrintToChatAll("==Waiting for other players==");
g_RoundCount++;
g_WaitingForPlayers = true;
}else if(g_Enable && g_RoundCount == 1 && !g_BossMode){
// PrintToChatAll("== Not waiting for players !rtr available!");
g_WaitingForPlayers = false;
g_RoundCount++;
Command_Robot_Selection(1, 1);
//MC_PrintToChatAll("[{orange}SM{default}]{orange} Type !rtr to vote to start Manned Machines");
}
int totalplayers = RoundToCeil(float(GetClientCount(false)) * g_Rtr_percent);
g_iVotesNeeded = totalplayers;
// PrintToChatAll("Total players: %i", totalplayers);
// PrintToChatAll("Total players: %i", GetClientCount(false));
//view_as<TFTeam>(g_HumanTeam)
//g_iVotesNeeded = int(ivotes_needed);
// if (g_AprilEnable && g_Enable && g_RoundCount == 1 && !g_BossMode){
// CreateTimer(0.5, MakeRobotsApril);
// }
}
// public Action MakeRobotsApril(Handle timer)
// {
// Command_YT_Robot_Start(1, true);
// }
// float g_last_given_boss_coin = 0.0;
// public Action Event_Teamplay_Point_Captured(Event event, char[] name, bool dontBroadcast)
// {
// //int team = GetEventInt(event, "team");
// //PrintToChatAll("Team wws %i", team);
// if (g_Enable && g_BossMode)
// {
// if (!b_is_koth)
// {
// SetTeamCoinsFor(TFTeam_Blue, 1);
// SetTeamCoinsFor(TFTeam_Red, 1);
// }else
// {
// koth_caps++;
// if (koth_caps > 4)
// {
// SetTeamCoinsFor(TFTeam_Blue, 1);
// SetTeamCoinsFor(TFTeam_Red, 1);
// koth_caps = 0;
// }
// }
// }
// }
// public void OnClientConnected(int client)
// {
// // PrintToServer("Removing");
// ServerCommand("sm_removepoints #%d 5000", GetClientUserId(client));
// }
public Action Event_teamplay_round_start(Event event, char[] name, bool dontBroadcast)
{
// int g_powershop = -1;
if (g_Enable && !g_AprilEnable){
MC_PrintToChatAll("{Green}Type {orange}!info{Green} to see more info about this gamemode");
MC_PrintToChatAll("{Green}Visit {orange}bmod.tf/mannedmachines {Green} To get the assetpack to get the most out of this mode");
// Reset the health buffer when a round starts to prevent robots from getting dmg health carried over from last round
for(int i = 1; i <= MaxClients+1; i++)
{
if(IsValidClient(i))
{
g_PlayerHealth[i] = -1;
// PrintCenterText(i,"RESETTING UR HEALTH");
}
}
// Remove Point on player start
// int powerteam = GetRobotTeam();
// switch(powerteam)
// {
// case RED:
// {
// g_powershop = 0;
// }
// case BLUE:
// {
// g_powershop = 1;
// }
// }
// //Powershop
// //0 RED only, 1 BLU only
// PrintToChatAll("Setting to %i", g_powershop);
// ServerCommand("sm_tf2ps_shop_restriction %i",g_powershop);
if (GameRules_GetProp("m_bSwitchedTeamsThisRound"))
{
if(g_cv_bDebugMode) PrintToChatAll("Teamswitch detected!");
ResetCoins();
// PrintToChatAll("attempting reset");
//Logic to handle resetting you if you are a paid robot, uses a copied function from berobot_teamcomptips.sp, should be optimized later
for(int i = 0; i <= MaxClients; i++)
{
if(IsAnyRobot(i))
{
char robotName[NAMELENGTH];
GetRobot(i, robotName, sizeof(robotName));
if (IsPaidRobot(i, robotName))
{
TrashRobot(i);
Internal_SetRandomRobot(i);
}
}
}
switch(g_RoboTeam)
{
case RED:
{
if(g_cv_bDebugMode)PrintToChatAll("RoboTeam was RED changing to BLUE...");
g_RoboTeam = BLUE;
g_HumanTeam = RED;
}
case BLUE:
{
if(g_cv_bDebugMode)PrintToChatAll("RoboTeam was BLU changing to RED...");
g_RoboTeam = RED;
g_HumanTeam = BLUE;
}
}
}
}
//Powershop
//0 RED only, 1 BLU only
// ServerCommand("sm_plugins unload /TF2PowerShop/");
// ServerCommand("sm_plugins load /TF2PowerShop/");
return Plugin_Continue;
}
public MRESReturn OnRegenerate(int pThis, Handle hReturn, Handle hParams)
{
//Activates when doing OnRegenerate (touchihng resupply locker) and then ignoring it if you are a boss
if(isMiniBoss(pThis) && IsPlayerAlive(pThis)){
//PrintToChatAll("1");
PrintCenterText(pThis,"Error: Unable to use human lockers");
// int args;
// Command_ShowStats(pThis, 1);
//sets the robot health when touch
// int maxhealth = GetEntProp(GetPlayerResourceEntity(), Prop_Send, "m_iMaxHealth", _, pThis);
// SetEntityHealth(pThis, maxhealth);
//TF2_AddCondition(pThis, TFCond_HalloweenQuickHeal, 10.0);
return MRES_Supercede;
}
return MRES_Ignored;
}
public void CvarChangeHook(ConVar convar, const char[] sOldValue, const char[] sNewValue)
{
if(convar == g_cvCvarList[CV_bDebugMode])
g_cv_bDebugMode = view_as<bool>(StringToInt(sNewValue));
// if(convar == g_cvCvarList[CV_flSpyBackStabModifier])
// g_CV_flSpyBackStabModifier = StringToFloat(sNewValue);
if(convar == g_cvCvarList[CV_flYoutuberMode])
g_CV_flYoutuberMode = StringToInt(sNewValue);
if(convar == g_cvCvarList[CV_g_Rtr_precent])
g_Rtr_percent = StringToFloat(sNewValue);
if(convar == g_cvCvarList[CV_g_RoboCap])
g_RoboCap = StringToInt(sNewValue);
if(convar == g_cvCvarList[CV_g_RoboCapTeam])
{
g_RoboCapTeam = StringToInt(sNewValue);
if (g_Enable) PrintToChatAll("Current Robots: %i", g_RoboCapTeam);
}
if(convar == g_cvCvarList[CV_g_RoboTeamMode])
g_RoboTeamMode = StringToInt(sNewValue);
if(convar == g_cvCvarList[CV_g_RoboMode])
g_RoboMode = StringToInt(sNewValue);
if(convar == g_cvCvarList[CV_g_Enable])
{
g_Enable = StringToInt(sNewValue);
Call_StartForward(_enabledChangedForward);
Call_PushCell(g_Enable);
Call_Finish();
}
if(convar == g_cvCvarList[CV_g_AprilEnable])
{
g_AprilEnable = StringToInt(sNewValue);
}
}
// public Action TF2_OnTakeDamage(int victim, int &attacker, int &inflictor, float &damage, int &damagetype, int &weapon, float damageForce[3], float damagePosition[3], int damagecustom, CritType &critType)
// {
// if (IsValidClient(attacker) && IsValidClient(victim))
// {
// //Damage bonus is not active, no need to do anything
// }