-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmm_attribute_teamporter.sp
1491 lines (1247 loc) · 41.7 KB
/
mm_attribute_teamporter.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
#pragma semicolon 1
#include <tf2_stocks>
#include <tf2attributes>
#include <sdkhooks>
#include <berobot_constants>
#include <berobot>
//#include <sendproxy>
#include <dhooks>
#include <sdktools>
//#include <collisionhook>
#include <tf2_isPlayerInSpawn>
#include <morecolors>
#include <tfobjects>
//#pragma newdecls required
#define PLUGIN_VERSION "1.0"
#define ENGIE_SPAWN_SOUND "vo/announcer_mvm_engbot_arrive02.mp3"
#define ENGIE_SPAWN_SOUND2 "vo/announcer_mvm_engbot_arrive03.mp3"
/*
#define TELEPORTER_ACTIVATE1 "vo/announcer_mvm_eng_tele_activated01.mp3"
#define TELEPORTER_ACTIVATE2 "vo/announcer_mvm_eng_tele_activated02.mp3"
#define TELEPORTER_ACTIVATE3 "vo/announcer_mvm_eng_tele_activated03.mp3"
#define TELEPORTER_ACTIVATE4 "vo/announcer_mvm_eng_tele_activated04.mp3"
#define TELEPORTER_ACTIVATE5 "vo/announcer_mvm_eng_tele_activated05.mp3"
*/
//Easier to have all the sounds we want in a single variable array for better access
static const char TeleActivateSounds[][256] =
{
"vo/announcer_mvm_eng_tele_activated01.mp3",
"vo/announcer_mvm_eng_tele_activated02.mp3",
"vo/announcer_mvm_eng_tele_activated03.mp3",
"vo/announcer_mvm_eng_tele_activated04.mp3",
"vo/announcer_mvm_eng_tele_activated05.mp3"
};
#define TELEPORTER_SPAWN "mvm/mvm_tele_deliver.wav"
#define TELEPORTER_ACTIVATE "mvm/mvm_tele_activate.wav"
#define TELE_INCORRECT_PLACEMENT_WARNING "ui/rd_2base_alarm.wav"
#define TF_OBJECT_TELEPORTER 1
#define TF_TELEPORTER_ENTR 0
// #define DEBUG
//new g_offsCollisionGroup;
/*
///
/// unused variables, keeping these here in case they were meant to be used at some point. Otherwise they just cause warnings in the compiler
///
bool AnnouncerQuiet;
int engieid = -1;
int g_iMaxEntities;
int BossTeleporter;
int g_iObjectParticle[2048];
bool teleportercheck;
bool engibotactive;
int EngieTeam = 2;
*/
bool g_Teleported[MAXPLAYERS + 1];
float vecSpawns[2][3];
int g_iPadType[2048];
char g_szOffsetStartProp[64];
int g_iOffsetMatchingTeleporter = -1;
float g_drawtime[MAXPLAYERS + 1] = 0.0;
int g_Recharge[MAXPLAYERS + 1] = 0;
int g_RechargeCap = 200;
bool g_TouchHooked[MAXPLAYERS + 1] = false;
enum //Teleporter states
{
TELEPORTER_STATE_BUILDING = 0, // Building, not active yet
TELEPORTER_STATE_IDLE, // Does not have a matching teleporter yet
TELEPORTER_STATE_READY, // Found match, charged and ready
TELEPORTER_STATE_SENDING, // Teleporting a player away
TELEPORTER_STATE_RECEIVING,
TELEPORTER_STATE_RECEIVING_RELEASE,
TELEPORTER_STATE_RECHARGING, // Waiting for recharge
TELEPORTER_STATE_UPGRADING // Upgrading
}
enum //Custom ObjectType
{
PadType_None = 0,
PadType_Boost,
PadType_Jump,
PadType_Boss
}
enum // Return values for tele check
{
TELE_WRONGTEAM = 0,
TELE_IS_BUILDING,
TELE_CARRIED,
TELE_NOTEXIT,
TELE_SAPPER,
TELE_NOT_BOSS,
TELE_RECHARGING,
TELE_READY,
TELE_NO_TELE
}
enum struct ObjectPointer
{
int reference; //reference
void set(int entity)
{
if (IsValidEntity(entity) && entity > 0)
this.reference = EntIndexToEntRef(entity);
else
this.reference = INVALID_ENT_REFERENCE;
}
int get()
{
return EntRefToEntIndex(this.reference);
}
void GetPos(float pos[3])
{
if (this.valid())
GetEntPropVector(this.get(), Prop_Data, "m_vecOrigin", pos);
}
void GetAng(float angles[3])
{
if (this.valid())
GetEntPropVector(this.get(), Prop_Send, "m_angRotation", angles);
}
bool valid()
{
int ent = this.get();
if (IsValidEntity(ent) && ent > 0)
{
// if (GetTeleporterStatus(ent) == TELE_READY)
// {
return true;
// }
}
return false;
}
}
ObjectPointer PlayerTele[MAXPLAYERS + 1];
int SelectedIndex[MAXPLAYERS + 1];
// enum //TFOBjectType
// {
// TFObject_CartDispenser = 0,
// TFObject_Dispenser,
// TFObject_Teleporter,
// TFObject_Sentry,
// TFObject_Sapper
// }
// TFObjectMode
// enum
// {
// TFObjectMode_None = 0,
// TFObjectMode_Entrance,
// TFObjectMode_Exit,
// }
//List of teleporters used to determine the teamporter exists
int g_teleporters[MAXPLAYERS+1] = {-1, ...};
public Plugin myinfo =
{
name = "[Manned Machines] Teamporter attribute",
author = "HiGPS",
description = "Adds Teamporter functionality for robots",
version = PLUGIN_VERSION,
url = "www.sourcemod.com"
}
public void OnPluginStart()
{
LoadTranslations("common.phrases");
//g_offsCollisionGroup = FindSendPropInfo("DT_BaseEntity", "m_CollisionGroup");
HookEvent("player_builtobject", ObjectBuilt, EventHookMode_Post);
HookEvent("player_carryobject", ObjectCarry, EventHookMode_Post);
//HookEvent("player_upgradedobject", ObjectCarry, EventHookMode_Post);
Handle hGameConf = LoadGameConfigFile("tf2.teleporters");
if (hGameConf == INVALID_HANDLE)
SetFailState("[EngiPads] Unable to load gamedata file 'tf2.teleporters.txt'");
bool bFoundProp = GameConfGetKeyValue(hGameConf, "StartProp", g_szOffsetStartProp, sizeof(g_szOffsetStartProp));
g_iOffsetMatchingTeleporter = GameConfGetOffset(hGameConf, "m_hMatchingTeleporter");
if (!bFoundProp || g_iOffsetMatchingTeleporter < 0)
SetFailState("[EngiPads] Unable to get m_hMatchingTeleporter offset from 'tf2.teleporters.txt'. Check gamedata!");
CloseHandle(hGameConf);
AddCommandListener(CommandListener_Build, "build");
HookEvent("player_spawn", OnPlayerSpawn, EventHookMode_Post);
for(int i = 1; i <= MaxClients+1; i++)
{
if (IsValidClient(i))
{
SDKHook(i, SDKHook_Touch, OnTouch);
}
}
// HookEvent("player_death", Event_Death, EventHookMode_Post);
}
public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
{
return APLRes_Success;
}
int g_iLaserSprite;
int g_iHaloSprite;
public void OnMapStart()
{
// HookEvent("player_spawn", OnPlayerSpawn, EventHookMode_Post);
//sound and model precaching should always be done in OnMapStart
int size = sizeof TeleActivateSounds;
for (int i = 0; i < size; i++)
PrecacheSound(TeleActivateSounds[i], true);
PrecacheSound(TELEPORTER_SPAWN, true);
PrecacheSound(TELEPORTER_ACTIVATE, true);
PrecacheSound(TELE_INCORRECT_PLACEMENT_WARNING, true);
g_iLaserSprite = PrecacheModel("materials/sprites/laserbeam.vmt");
g_iHaloSprite = PrecacheModel("materials/sprites/halo01.vmt");
}
// public Action Event_Death(Event event, const char[] name, bool dontBroadcast)
// {
// //int attacker = GetClientOfUserId(GetEventInt(event, "attacker"));
// int victim = GetClientOfUserId(GetEventInt(event, "userid"));
// if (IsValidClient(victim))
// {
// g_TouchHooked[victim] = false;
// SDKUnhook(victim, SDKHook_Touch, OnTouch);
// }
// }
// public void OnClientDisconnect_Post(int client)
// {
// if (IsValidClient(client))
// {
// g_TouchHooked[client] = false;
// SDKUnhook(client, SDKHook_Touch, OnTouch);
// }
// }
public void ObjectBuilt(Event event, const char[] name, bool dontBroadcast)
{
int iBuilder = GetClientOfUserId(event.GetInt("userid"));
int iObj = event.GetInt("index");
if (IsValidClient(iBuilder) && IsAnyRobot(iBuilder))
{
#if defined DEBUG
PrintToChatAll("Found robot builder!");
#endif
if (view_as<TFObjectType>(event.GetInt("object")) == TFObject_Teleporter)
{
g_teleporters[iBuilder] = EntIndexToEntRef(iObj);
//PrintToChatAll("Iobj %i", iObj);
#if defined DEBUG
PrintToChatAll("Built builder teleporter!");
#endif
SetEntPropFloat(iObj, Prop_Send, "m_flModelScale", 1.0);
CheckTeleportClamping(iObj, iBuilder);
SetEntProp(iObj, Prop_Send, "m_iHighestUpgradeLevel", 3); //Set Pads to level 3 for cosmetic reasons related to recharging
SetEntProp(iObj, Prop_Send, "m_iUpgradeLevel", 3);
SetEntProp(iObj, Prop_Send, "m_bMiniBuilding", true);
//Setting m_bMiniBuilding tries to set the skin to a 'mini' skin. Since teles don't have one, reset the skin.
SetEntProp(iObj, Prop_Send, "m_iTimesUsed", 0);
RequestFrame(ResetSkin, iObj);
TF2_SetMatchingTeleporter(iObj, iObj);
SetVariantInt(RoundFloat(500.0));
AcceptEntityInput(iObj, "AddHealth", iObj); //Spawns at 50% HP.
SetEntProp(iObj, Prop_Send, "m_iTimesUsed", 0);
//Set teleporter to itself - does not work yet
// int iObjParti = CreatePadParticle(iObj, "teleporter_mvm_bot_persist");
// g_iObjectParticle[iObj] = EntIndexToEntRef(iObjParti);
//AcceptEntityInput(iObjParti, "Start");
float position[3];
GetEntPropVector(iObj, Prop_Data, "m_vecOrigin", position);
int attach = CreateEntityByName("trigger_push");
TeleportEntity(attach, position, NULL_VECTOR, NULL_VECTOR);
if (TF2_GetClientTeam(iBuilder) == TFTeam_Blue)
{
TE_Particle("teleported_mvm_bot", position, _, _, attach, 1,0);
}else
{
TE_Particle("teleported_mvm_bot_dust", position, _, _, attach, 1,0);
// TE_Particle("teleported_mvm_bot", position, _, _, attach, 1,0);
}
//TE_Particle("teleporter_mvm_bot_persist", position, _, _, attach, 1,0);
//TE_Particle("particles/teleported_mvm_bot_red", position, _, _, attach, 1,0);
g_iPadType[iObj] = PadType_Boss;
#if defined DEBUG
PrintToChatAll("SetPadtype to %i", g_iPadType[iObj]);
#endif
//Doesn't work for some reason
//EmitGameSoundToAll("Announcer.MVM_Engineer_Teleporter_Activated");
int size = sizeof TeleActivateSounds;
int soundswitch = GetRandomInt(0, size - 1);
EmitSoundToAll(TeleActivateSounds[soundswitch]);
/*switch(soundswitch)
{
case 1: EmitSoundToAll(TELEPORTER_ACTIVATE1);
case 2: EmitSoundToAll(TELEPORTER_ACTIVATE2);
case 3: EmitSoundToAll(TELEPORTER_ACTIVATE3);
case 4: EmitSoundToAll(TELEPORTER_ACTIVATE4);
case 5: EmitSoundToAll(TELEPORTER_ACTIVATE5);
}
*/
}
}
}
stock void TF2_SetMatchingTeleporter(int iTele, int iMatch) //Set the matching teleporter entity of a given Teleporter
{
if (IsValidEntity(iTele) && HasEntProp(iTele, Prop_Send, g_szOffsetStartProp))
{
//PrintToChatAll("Matching telepoters");
int iOffs = FindSendPropInfo("CObjectTeleporter", g_szOffsetStartProp) + g_iOffsetMatchingTeleporter;
SetEntDataEnt2(iTele, iOffs, iMatch, true);
}
}
public void OnClientPutInServer(int client)
{
SDKHook(client, SDKHook_Touch, OnTouch);
}
public void OnClientDisconnected(int client)
{
SDKUnhook(client, SDKHook_Touch, OnTouch);
}
public void ObjectCarry(Event event, const char[] name, bool dontBroadcast)
{
// if (view_as<TFObjectType>(event.GetInt("object")) != TFObject_Teleporter)
// return;
int iBuilder = GetClientOfUserId(event.GetInt("userid"));
int iObj = event.GetInt("index");
//int entRef = EntIndexToEntRef(iObj);
//PrintToChatAll("iObj %i", iObj);
if (IsValidClient(iBuilder) && IsAnyRobot(iBuilder))
{
// SetEntProp(iObj, Prop_Send, "m_iHighestUpgradeLevel", 3);
// SetEntProp(iObj, Prop_Send, "m_iUpgradeLevel", 3);
if (view_as<TFObjectType>(event.GetInt("object")) != TFObject_Teleporter)SetEntPropFloat(iObj, Prop_Send, "m_flModelScale", 1.0);
// SetEntPropFloat(iObj, Prop_Send, "m_flPercentageConstructed", 1.0);
//SetEntProp(iObj, Prop_Send, "m_CollisionGroup", 2);
//SetEntPropFloat(iObj, Prop_Send, "m_bDisposableBuilding", 1.0);
// DispatchKeyValue(iObj, "defaultupgrade", "2");
//SetEntPropFloat(iObj, Prop_Send, "m_iUpgradeMetalRequired ", 0.1);
//SDKHook(iObj, SDKHook_ShouldCollide, ShouldCollide );
//CH_PassFilter(iBuilder, iObj, false);
//SetEntData(iObj, g_offsCollisionGroup, 2, 4, false);
}
}
bool g_spawnclamp[MAXPLAYERS + 1] = false;
public Action OnPlayerSpawn(Event event, const char[] name, bool dontBroadcast)
{
int client = GetClientOfUserId(event.GetInt("userid"));
if (g_Teleported[client])
return Plugin_Continue;
#if defined DEBUG
PrintToChatAll("%N spawned", client);
#endif
if (!IsAnyRobot(client))
{
g_TouchHooked[client] = false;
#if defined DEBUG
PrintToChatAll("%N spawned and was not a robot", client);
#endif
return Plugin_Changed;
}
if (IsAnyRobot(client)){
g_Recharge[client] = 0;
g_TouchHooked[client] = true;
// FindRoboExit(client);
}
// int team = GetClientTeam(client);
// // if (team != EngieTeam)
// // return Plugin_Continue;
// float angles[3], pos[3];
// if (GetTeamporterTransform(team, angles, pos) && !g_spawnclamp[client])
// {
// MC_PrintToChatEx(client, client, "{orange}==[TEAMPORTER ACTIVE]==");
// MC_PrintToChatEx(client, client, "{teamcolor}==[HOLD CROUCH TO CHARGE TELEPORT IN SPAWN!]==");
// //EmitSoundToAll(TELEPORTER_ACTIVATE, client, _,_,_,0.3);
// EmitSoundToClient(client, TELEPORTER_ACTIVATE);
// g_spawnclamp[client] = true;
// CreateTimer(1.5, SpawnSound_Clamp, client);
// }
return Plugin_Continue;
}
bool g_b_hud_drawn[MAXPLAYERS + 1];
public Action OnTouch(int client, int ent)
{
if (IsValidClient(client) && IsClientInGame(client))
{
char entname[MAX_NAME_LENGTH];
GetEntityClassname(ent, entname, sizeof(entname));
if (!StrContains(entname, "func_respawnroom"))
{
// PrintToChatAll("%N is touching %s", client, entname);
if (IsAnyRobot(client) && TF2Spawn_IsClientInSpawn(client) && TeamHasRoboEngineer(client))
{
UpdateCharge(client);
DrawHUD(client);
// PrintCenterText(client, "Touching Spawn Robo");
// g_b_CanGetTeled[client] = true;
// g_b_hud_drawn[client] = true;
}
else if (!IsAnyRobot(client) && TF2_GetPlayerClass(client) == TFClass_Spy)
{
int EntTeamNum = GetEntProp(ent, Prop_Send, "m_iTeamNum");
int clientTeam = GetClientTeam(client);
if (EntTeamNum != clientTeam)
{
UpdateCharge(client);
DrawHUD(client);
// g_b_hud_drawn[client] = true;
// PrintCenterText(client, "Touching Enemy Spawn Spy");
// g_b_CanGetTeled[client] = true;
}
}
}
}
return Plugin_Continue;
}
// public Action Teleport_Player_old(int client)
// {
// if (g_Teleported[client])
// return Plugin_Continue;
// #if defined DEBUG
// PrintToChatAll("%N spawned", client);
// #endif
// int team = GetClientTeam(client);
// // if (team != EngieTeam)
// // return Plugin_Continue;
// float angles[3], pos[3];
// if (GetTeamporterTransform(team, angles, pos) == 1)
// {
// pos[2] += 15.0;
// // Don't get stuck inside of teleporter
// #if defined DEBUG
// PrintToChatAll("%N was teleported", client);
// #endif
// TeleportEntity(client, pos, angles, NULL_VECTOR);
// EmitSoundToAll(TELEPORTER_SPAWN, client, _,_,_, 0.3);
// CreateTimer(0.5, Teleport_Clamp, client);
// g_Recharge[client] = 1;
// g_Teleported[client] = true;
// float oober = 3.0;
// TF2_AddCondition(client, TFCond_Ubercharged, oober);
// TF2_AddCondition(client, TFCond_TeleportedGlow, 5.0);
// g_spawnclamp[client] = false;
// }
// return Plugin_Continue;
// }
//This should find the nearest teleporter exit built by a robo engie and give its rotation and position
int GetTeamporterTransform(int team, float angles[3], float pos[3])
{
//PrintToChatAll("Got here1");
int j = 1;
int ent = -1;
int tele;
int status = 0;
int i = (team == 2 ? 1 : 0);
float vecSpawn[3];
float vecIsActuallyGoingToSpawn[3] = {-99999.0, -99999.0, -99999.0};
float dist, otherdist = GetVectorDistance(vecIsActuallyGoingToSpawn, vecSpawns[i]);
//g_teleporters[client]
// while ((ent = FindEntityByClassname(ent, "obj_teleporter")) != -1)
while(j++ <= MaxClients+1)
{
// PrintToChatAll("Got here");
if (IsValidClient(j) && IsClientInGame(j))
{
if(IsValidEntity(g_teleporters[j])){
// PrintToChatAll("ITERATING in WHILE %N, %i", j, g_teleporters[j]);
continue;
}
ent = EntRefToEntIndex(g_teleporters[j]);
//PrintToChatAll("Got here");
if (GetEntProp(ent, Prop_Send, "m_iTeamNum") != team)
continue;
if (GetEntProp(ent, Prop_Send, "m_bBuilding"))
{
status = 2;
continue;
}
if (GetEntProp(ent, Prop_Send, "m_bCarried")) // If being carried
continue;
if (GetEntProp(ent, Prop_Send, "m_iObjectMode") != 1) // If not exit
continue;
if (GetEntProp(ent, Prop_Send, "m_bHasSapper")){ //has sapper
status = 3;
continue;
}
if (g_iPadType[ent] != PadType_Boss)
continue;
if (TF2_GetBuildingState(ent) != TELEPORTER_STATE_READY)
continue;
// if (TF2_GetBuildingState(ent) == TELEPORTER_STATE_READY)
// continue;
// int state = TF2_GetBuildingState(ent);
// PrintToChatAll("%i state", state);
GetEntPropVector(ent, Prop_Send, "m_vecOrigin", vecSpawn);
dist = GetVectorDistance(vecSpawn, vecSpawns[i]);
if (dist < otherdist)
{
otherdist = dist;
vecIsActuallyGoingToSpawn = vecSpawn;
pos = vecSpawn;
GetEntPropVector(ent, Prop_Send, "m_angRotation", angles); // Force players to look in the direction of teleporter on spawn
tele = ent;
}
}
// If no teleporters found
//if (GetVectorDistance(vecIsActuallyGoingToSpawn, vecSpawns[i]) >= 70000)
if (status == 3)
{
// PrintToChatAll("IsSapped");
return 3;
}
if (status == 2)
{
// PrintToChatAll("IsBuilding");
return 2;
}
if (!tele)
{
#if defined DEBUG
PrintToChatAll("No teleporters found!");
#endif
// PrintToChatAll("No teleporters found!");
return 0;
}
return 1;
}
}
int GetTeleporterStatus(int ent){
int team = GetEntProp(ent, Prop_Data, "m_iTeamNum");
if (GetEntProp(ent, Prop_Send, "m_iTeamNum") != team)
return TELE_WRONGTEAM;
if (GetEntProp(ent, Prop_Send, "m_bBuilding"))
{
// PrintToChatAll("Building");
return TELE_IS_BUILDING;
}
if (GetEntProp(ent, Prop_Send, "m_bCarried"))
{
// PrintToChatAll("Carried"); // If being carried
return TELE_CARRIED;
}
if (GetEntProp(ent, Prop_Send, "m_iObjectMode") != 1) // If not exit
{
// PrintToChatAll("Not Exit");
return TELE_NOTEXIT;
}
if (GetEntProp(ent, Prop_Send, "m_bHasSapper"))
{ //has sapper
// PrintToChatAll("Is Sapped");
return TELE_SAPPER;
}
if (g_iPadType[ent] != PadType_Boss)
{
// PrintToChatAll("Not boss");
return TELE_NOT_BOSS;
}
if (TF2_GetBuildingState(ent) != TELEPORTER_STATE_READY)
{
// PrintToChatAll("Tele was not ready");
return TELE_RECHARGING;
}
//PrintToChatAll("Good To GO!");
return TELE_READY;
}
public Action Teleport_Clamp(Handle timer, int client)
{
g_Teleported[client] = false;
}
public Action SpawnSound_Clamp(Handle timer, int client)
{
g_spawnclamp[client] = false;
}
public Action OnPlayerRunCmd(int client, int& buttons, int& impulse, float vel[3], float angles[3], int& weapon, int& subtype, int& cmdnum, int& tickcount, int& seed, int mouse[2])
{
if (CanUseTele(client) && buttons & (IN_DUCK))
{
if(g_Recharge[client] >= g_RechargeCap && g_b_hud_drawn[client] && g_drawtime[client] + 1.0 >= GetEngineTime())
{
Teleport_Player(client);
}
// else if (g_Recharge[client] >= g_RechargeCap && g_b_hud_drawn[client] && !TF2Spawn_IsClientInSpawn(client) && !IsAnyRobot(client))
// {
// Teleport_Player(client);
// }
}
}
//Charging the tele to spawn
void UpdateCharge(int client)
{
// if we are already at max charge, no need to check anything
if(CanUseTele(client))
{
if(IsFakeClient(client))
{
// Teleport_Player(client);
}
if(g_Recharge[client] >= g_RechargeCap)
{
g_Recharge[client] = g_RechargeCap;
}else
{
g_Recharge[client]++;
}
}
}
#define CHAR_FULL "■"
#define CHAR_EMPTY "□"
bool b_hud_clamp[MAXPLAYERS + 1] = false;
public Action DrawHUD(int client)
{
if (IsClientInGame(client) && IsValidClient(client)){
char sHUDText[128];
char sProgress[32];
int iPercents = RoundToCeil(float(g_Recharge[client]) / float(g_RechargeCap) * 100.0);
for (int j = 1; j <= 10; j++)
{
if (iPercents >= j * 10)StrCat(sProgress, sizeof(sProgress), CHAR_FULL);
else StrCat(sProgress, sizeof(sProgress), CHAR_EMPTY);
}
// int team = GetClientTeam(client);
// float angles[3], pos[3];
// Format(sHUDText, sizeof(sHUDText), "Charging Teamporter: %d%%%% \n%s ", iPercents, sProgress);
// SetHudTextParams(-1.0, -0.2, 0.1, 255, 255, 255, 255);
ObjectPointer teleporters[32];
ObjectPointer farthest;
GetFarthestTele(client, farthest, teleporters);
if(iPercents >= 100)
{
//Charge is 100% check for teleporters
// CreateTeleMenu(client, teleporters);
// GetActiveSelection(client, PlayerTele[client], farthest);
// ObjectPointer tele;
// tele = PlayerTele[client];
// char description[256];
if (farthest.valid())
{
//Check if teleporters are in the correct status
int teleporter = farthest.get();
switch(GetTeleporterStatus(teleporter))
{
case TELE_IS_BUILDING:
{
// PrintCenterTextAll("Ready");
Format(sHUDText, sizeof sHUDText, "Teamporter Ready!\nTeamporter is building");
SetHudTextParams(-1.0, -0.2, 0.1, 0, 130, 130, 255);
g_b_hud_drawn[client] = false;
}
case TELE_CARRIED:
{
// PrintCenterTextAll("Ready");
Format(sHUDText, sizeof sHUDText, "Teamporter Ready!\nTeamporter is being carried");
SetHudTextParams(-1.0, -0.2, 0.1, 130, 130, 0, 255);
g_b_hud_drawn[client] = false;
}
case TELE_SAPPER:
{
// PrintCenterTextAll("Ready");
Format(sHUDText, sizeof sHUDText, "Teamporter Ready!\nTeamporter is Disabled / Sapped");
SetHudTextParams(-1.0, -0.2, 0.1, 133, 0, 130, 255);
g_b_hud_drawn[client] = false;
}
case TELE_RECHARGING:
{
// PrintCenterTextAll("Ready");
Format(sHUDText, sizeof sHUDText, "Teamporter Ready!\nEngipad Teamporter is Recharging...");
SetHudTextParams(-1.0, -0.2, 0.1, 50, 50, 100, 255);
g_b_hud_drawn[client] = false;
}
case TELE_READY:
{
// PrintCenterTextAll("Ready");
Format(sHUDText, sizeof(sHUDText), "Teamporter Ready!\nCrouch to Teleport!");
TF2_AddCondition(client, TFCond_TeleportedGlow, 1.0);
SetHudTextParams(-1.0, -0.2, 0.1, 0, 255, 0, 255);
g_b_hud_drawn[client] = true;
g_drawtime[client] = GetEngineTime();
}
// case TELE_WRONGTEAM:
// {
// // PrintCenterTextAll("Ready");
// Format(sHUDText, sizeof(sHUDText), "Wrong Team!\nCrouch to Teleport!");
// TF2_AddCondition(client, TFCond_TeleportedGlow, 1.0);
// SetHudTextParams(-1.0, -0.2, 0.1, 0, 255, 0, 255);
// }
// default:
// {
// Format(sHUDText, sizeof(sHUDText), "Teamporter Ready!\nNo active Teleporter");
// SetHudTextParams(-1.0, -0.2, 0.1, 255, 0, 0, 255);
// }
}
//PrintCenterText(client, description);
// return Plugin_Continue;
}else
{
Format(sHUDText, sizeof(sHUDText), "Teamporter Ready!\nNo active Teleporter");
SetHudTextParams(-1.0, -0.2, 0.1, 255, 0, 0, 255);
}
// if(iPercents >= 100)
// {
// if (GetTeamporterTransform(team, angles, pos))
// {
// if (GetTeamporterTransform(team, angles, pos) == 2){
// Format(sHUDText, sizeof(sHUDText), "Teamporter Ready!\nTeamporter is building");
// SetHudTextParams(-1.0, -0.2, 0.1, 0, 130, 130, 255);
// }else if (GetTeamporterTransform(team, angles, pos) == 3){
// Format(sHUDText, sizeof(sHUDText), "Teamporter Ready!\nTeamporter is sapped");
// SetHudTextParams(-1.0, -0.2, 0.1, 133, 0, 130, 255);
// }else{
// Format(sHUDText, sizeof(sHUDText), "Teamporter Ready!\nCrouch to Teleport!");
// TF2_AddCondition(client, TFCond_TeleportedGlow, 1.0);
// SetHudTextParams(-1.0, -0.2, 0.1, 0, 255, 0, 255);
// }
// if (!g_spawnclamp[client])
// {
// EmitSoundToClient(client, TELEPORTER_ACTIVATE, client, SNDCHAN_AUTO, SNDLEVEL_NORMAL, SND_NOFLAGS, 0.35);
// g_spawnclamp[client] = true;
// }
// }else if (!GetTeamporterTransform(team, angles, pos))
// {
// Format(sHUDText, sizeof(sHUDText), "Teamporter Ready!\nNo active Teleporter");
// SetHudTextParams(-1.0, -0.2, 0.1, 255, 0, 0, 255);
// }
// } else {
// SetHudTextParams(-1.0, -0.2, 0.1, 255, 255, 255, 255);
// }
}else
{
Format(sHUDText, sizeof(sHUDText), "Charging Teamporter: %d%%%% \n%s ", iPercents, sProgress);
SetHudTextParams(-1.0, -0.2, 0.1, 255, 255, 255, 255);
if (farthest.valid())
{
//Check if teleporters are in the correct status
int teleporter = farthest.get();
switch(GetTeleporterStatus(teleporter))
{
case TELE_IS_BUILDING:
{
Format(sHUDText, sizeof(sHUDText), "%s\nTeamporter is building", sHUDText);
SetHudTextParams(-1.0, -0.2, 0.1, 0, 130, 130, 255);
g_b_hud_drawn[client] = false;
}
case TELE_CARRIED:
{
Format(sHUDText, sizeof(sHUDText), "%s\nTeamporter is being carried", sHUDText);
SetHudTextParams(-1.0, -0.2, 0.1, 130, 130, 0, 255);
g_b_hud_drawn[client] = false;
}
case TELE_SAPPER:
{
Format(sHUDText, sizeof(sHUDText), "%s\nTeamporter is Disabled / Sapped", sHUDText);
SetHudTextParams(-1.0, -0.2, 0.1, 133, 0, 130, 255);
g_b_hud_drawn[client] = false;
}
case TELE_RECHARGING:
{
Format(sHUDText, sizeof(sHUDText), "%s\nEngipad Teamporter is Recharging...", sHUDText);
SetHudTextParams(-1.0, -0.2, 0.1, 50, 50, 100, 255);
g_b_hud_drawn[client] = false;
}
// case TELE_READY:
// {
// Format(sHUDText, sizeof(sHUDText), "%s\nTeamporter ready!", sHUDText);
// SetHudTextParams(-1.0, -0.2, 0.1, 0, 255, 0, 255);
// }
// case TELE_WRONGTEAM:
// {
// // PrintCenterTextAll("Ready");
// Format(sHUDText, sizeof(sHUDText), "Wrong Team!\nCrouch to Teleport!");
// TF2_AddCondition(client, TFCond_TeleportedGlow, 1.0);
// SetHudTextParams(-1.0, -0.2, 0.1, 0, 255, 0, 255);
// }
// default:
// {
// Format(sHUDText, sizeof(sHUDText), "Teamporter Ready!\nNo active Teleporter");
// SetHudTextParams(-1.0, -0.2, 0.1, 255, 0, 0, 255);
// }
}
//PrintCenterText(client, description);
// return Plugin_Continue;
}else
{
Format(sHUDText, sizeof(sHUDText), "%s\nNo active Teleporter",sHUDText);
SetHudTextParams(-1.0, -0.2, 0.1, 255, 0, 0, 255);
g_b_hud_drawn[client] = false;
}
}
ShowHudText(client, -2, sHUDText);
b_hud_clamp[client] = false;
}
}
stock void TE_Particle(char[] Name, float origin[3] = NULL_VECTOR, float start[3] = NULL_VECTOR, float angles[3] = NULL_VECTOR, entindex=-1, attachtype=-1, attachpoint=-1, bool resetParticles=true, customcolors = 0, float color1[3] = NULL_VECTOR, float color2[3] = NULL_VECTOR, controlpoint = -1, controlpointattachment = -1, float controlpointoffset[3] = NULL_VECTOR)
{
// find string table
int tblidx = FindStringTable("ParticleEffectNames");
if (tblidx == INVALID_STRING_TABLE)
{
LogError("Could not find string table: ParticleEffectNames");
return;
}
float delay = 3.0;
// find particle index
char tmp[256];
int count = GetStringTableNumStrings(tblidx);
int stridx = INVALID_STRING_INDEX;
for (int i = 0; i < count; i++)
{
ReadStringTable(tblidx, i, tmp, sizeof(tmp));
if (StrEqual(tmp, Name, false))
{
stridx = i;
break;
}
}
if (stridx == INVALID_STRING_INDEX)
{
LogError("Could not find particle: %s", Name);
return;
}
TE_Start("TFParticleEffect");
TE_WriteFloat("m_vecOrigin[0]", origin[0]);
TE_WriteFloat("m_vecOrigin[1]", origin[1]);
TE_WriteFloat("m_vecOrigin[2]", origin[2]);
TE_WriteFloat("m_vecStart[0]", start[0]);
TE_WriteFloat("m_vecStart[1]", start[1]);
TE_WriteFloat("m_vecStart[2]", start[2]);
TE_WriteVector("m_vecAngles", angles);
TE_WriteNum("m_iParticleSystemIndex", stridx);
if (entindex !=- 1)
{
TE_WriteNum("entindex", entindex);
}
if (attachtype != -1)
{
TE_WriteNum("m_iAttachType", attachtype);
}
if (attachpoint != -1)
{
TE_WriteNum("m_iAttachmentPointIndex", attachpoint);
}
TE_WriteNum("m_bResetParticles", resetParticles ? 1 : 0);
if(customcolors)
{
TE_WriteNum("m_bCustomColors", customcolors);
TE_WriteVector("m_CustomColors.m_vecColor1", color1);
if(customcolors == 2)
{
TE_WriteVector("m_CustomColors.m_vecColor2", color2);
}
}
if(controlpoint != -1)
{
TE_WriteNum("m_bControlPoint1", controlpoint);
if(controlpointattachment != -1)
{
TE_WriteNum("m_ControlPoint1.m_eParticleAttachment", controlpointattachment);
TE_WriteFloat("m_ControlPoint1.m_vecOffset[0]", controlpointoffset[0]);