-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathtfpets.sp
More file actions
2791 lines (2322 loc) · 91.6 KB
/
Copy pathtfpets.sp
File metadata and controls
2791 lines (2322 loc) · 91.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <sdktools>
#include <sdkhooks>
#include <tf2_stocks>
#include <PathFollower>
#include <PathFollower_Nav>
#include <dhooks>
#include <customkeyvalues>
#include <CBaseAnimatingOverlay>
#pragma newdecls required;
#define RAD2DEG(%1) ((%1) * (180.0 / FLOAT_PI))
#define DEG2RAD(%1) ((%1) * FLOAT_PI / 180.0)
#define EF_BONEMERGE (1 << 0)
#define EF_PARENT_ANIMATES (1 << 9)
enum ParticleAttachment
{
PATTACH_ABSORIGIN = 0, // Create at absorigin, but don't follow
PATTACH_ABSORIGIN_FOLLOW, // Create at absorigin, and update to follow the entity
PATTACH_CUSTOMORIGIN, // Create at a custom origin, but don't follow
PATTACH_POINT, // Create on attachment point, but don't follow
PATTACH_POINT_FOLLOW, // Create on attachment point, and update to follow the entity
PATTACH_WORLDORIGIN, // Used for control points that don't attach to an entity
PATTACH_ROOTBONE_FOLLOW, // Create at the root bone of the entity, and update to follow
MAX_PATTACH_TYPES,
};
enum
{
TF_AMMO_DUMMY = 0,
TF_AMMO_PRIMARY,
TF_AMMO_SECONDARY,
TF_AMMO_METAL,
TF_AMMO_GRENADES1,
TF_AMMO_GRENADES2,
TF_AMMO_COUNT,
};
char s_skeletonHatModels[][] =
{
"models/player/items/demo/crown.mdl",
"models/player/items/all_class/skull_scout.mdl",
"models/workshop/player/items/scout/hw2013_boston_bandy_mask/hw2013_boston_bandy_mask.mdl",
"models/workshop/player/items/demo/hw2013_blackguards_bicorn/hw2013_blackguards_bicorn.mdl",
"models/player/items/heavy/heavy_big_chief.mdl"
//"models/player/items/all_class/xms_santa_hat_sniper.mdl"
}
//SDKCalls
Handle g_hMyNextBotPointer;
Handle g_hGetLocomotionInterface;
Handle g_hGetBodyInterface;
Handle g_hRun;
Handle g_hApproach;
Handle g_hFaceTowards;
Handle g_hResetSequence;
Handle g_hGetVelocity;
Handle g_hSetVelocity;
Handle g_hStudioFrameAdvance;
Handle g_hJump;
Handle g_hDispatchAnimEvents;
Handle g_hGetMaxAcceleration;
Handle g_hGetGroundSpeed;
Handle g_hGetVectors;
Handle g_hGetGroundMotionVector;
Handle g_hLookupPoseParameter;
Handle g_hSetPoseParameter;
Handle g_hGetPoseParameter;
Handle g_hLookupSequence;
Handle g_hAddGestureSequence;
Handle g_hSDKWorldSpaceCenter;
Handle g_hStudio_FindAttachment;
Handle g_hGetAttachment;
//Stuck detection
Handle g_hStuckMonitor;
Handle g_hClearStuckStatus;
Handle g_hIsStuck;
//Player SDKCalls
Handle g_hGetMaxAmmo;
Handle g_hGetAmmoCount;
//PluginBot DHooks
Handle g_hGetEntity;
Handle g_hGetBot;
//DHooks
Handle g_hGetFrictionSideways;
Handle g_hGetStepHeight;
Handle g_hGetGravity;
Handle g_hGetGroundNormal;
Handle g_hShouldCollideWith;
Handle g_hGetSolidMask;
Handle g_hStartActivity;
Handle g_hGetHullWidth;
Handle g_hGetHullHeight;
Handle g_hGetStandHullHeight;
Handle g_hGetCrouchHullHeight;
public Plugin myinfo =
{
name = "[TF2] Advanced Pets",
author = "Pelipoika",
description = "",
version = "1.0",
url = ""
};
methodmap BaseNPC
{
property int index
{
public get()
{
return view_as<int>(this);
}
}
public int ExtractStringValueAsInt(const char[] key)
{
char buffer[64];
bool bExists = GetCustomKeyValue(this.index, key, buffer, sizeof(buffer));
return bExists ? StringToInt(buffer) : -1;
}
public float ExtractStringValueAsFloat(const char[] key)
{
char buffer[64];
bool bExists = GetCustomKeyValue(this.index, key, buffer, sizeof(buffer));
return bExists ? StringToFloat(buffer) : -1.0;
}
property bool Pathing
{
public get() { return !!this.ExtractStringValueAsInt("Pathing"); }
public set(bool bOnOff)
{
if (PF_Exists(this.index))
{
bOnOff ? PF_StartPathing(this.index) : PF_StopPathing(this.index);
}
char buff[8];
IntToString(bOnOff, buff, sizeof(buff));
SetCustomKeyValue(this.index, "Pathing", buff, true);
}
}
property int Weapon
{
public get()
{
return EntRefToEntIndex(this.ExtractStringValueAsInt("Weapon"));
}
public set(int iInt)
{
char buff[32];
IntToString(iInt == INVALID_ENT_REFERENCE ? -1 : EntIndexToEntRef(iInt), buff, sizeof(buff));
SetCustomKeyValue(this.index, "Weapon", buff, true);
}
}
property bool DoingSpecial
{
public get() { return !!this.ExtractStringValueAsInt("DoingSpecial"); }
public set(bool bOnOff) { char buff[8]; IntToString(bOnOff, buff, sizeof(buff)); SetCustomKeyValue(this.index, "DoingSpecial", buff, true); }
}
property float MoveSpeed
{
public get() { return this.ExtractStringValueAsFloat("MoveSpeed"); }
public set(float flNextTime) { char buff[8]; FloatToString(flNextTime, buff, sizeof(buff)); SetCustomKeyValue(this.index, "MoveSpeed", buff, true); }
}
property float OutOfRange
{
public get() { return this.ExtractStringValueAsFloat("OutOfRange"); }
public set(float flNextTime) { char buff[8]; FloatToString(flNextTime, buff, sizeof(buff)); SetCustomKeyValue(this.index, "OutOfRange", buff, true); }
}
property float SpecialTime
{
public get() { return this.ExtractStringValueAsFloat("SpecialTime"); }
public set(float flNextTime) { char buff[8]; FloatToString(flNextTime, buff, sizeof(buff)); SetCustomKeyValue(this.index, "SpecialTime", buff, true); }
}
public void GetSpecialPos(float pos[3])
{
char sVal[8];
GetCustomKeyValue(this.index, "special_x", sVal, sizeof(sVal));
pos[0] = StringToFloat(sVal);
GetCustomKeyValue(this.index, "special_y", sVal, sizeof(sVal));
pos[1] = StringToFloat(sVal);
GetCustomKeyValue(this.index, "special_z", sVal, sizeof(sVal));
pos[2] = StringToFloat(sVal);
}
public void SetSpecialPos(float pos[3])
{
char sVal[8];
FloatToString(pos[0], sVal, sizeof(sVal));
SetCustomKeyValue(this.index, "special_x", sVal, true);
FloatToString(pos[1], sVal, sizeof(sVal));
SetCustomKeyValue(this.index, "special_y", sVal, true);
FloatToString(pos[2], sVal, sizeof(sVal));
SetCustomKeyValue(this.index, "special_z", sVal, true);
}
public BaseNPC(float vecPos[3], float vecAng[3], const char[] model, const char[] modelscale = "1.0", const char[] health = "100", bool bGroundNormal = true)
{
BaseNPC npc = view_as<BaseNPC>(CreateEntityByName("base_boss"));
DispatchKeyValueVector(npc.index, "origin", vecPos);
DispatchKeyValueVector(npc.index, "angles", vecAng);
DispatchKeyValue(npc.index, "model", model);
DispatchKeyValue(npc.index, "modelscale", modelscale);
DispatchKeyValue(npc.index, "health", health);
DispatchSpawn(npc.index);
CreateParticle("ghost_appearation", vecPos, vecAng);
//CreateParticle("xms_snowburst", vecPos, vecAng);
Address pNB = SDKCall(g_hMyNextBotPointer, npc);
Address pLocomotion = SDKCall(g_hGetLocomotionInterface, pNB);
DHookRaw(g_hGetStepHeight, true, pLocomotion);
DHookRaw(g_hGetGravity, true, pLocomotion);
DHookRaw(g_hShouldCollideWith, true, pLocomotion);
DHookRaw(g_hGetMaxAcceleration, true, pLocomotion);
DHookRaw(g_hGetFrictionSideways, true, pLocomotion);
if(bGroundNormal)
DHookRaw(g_hGetGroundNormal, true, pLocomotion)
Address pBody = SDKCall(g_hGetBodyInterface, pNB);
DHookRaw(g_hGetSolidMask, true, pBody);
DHookRaw(g_hStartActivity, true, pBody);
DHookRaw(g_hGetHullWidth, true, pBody);
DHookRaw(g_hGetHullHeight, true, pBody);
DHookRaw(g_hGetStandHullHeight, true, pBody);
DHookRaw(g_hGetCrouchHullHeight, true, pBody);
SetEntityFlags(npc.index, FL_NOTARGET);
SetEntData(npc.index, FindSendPropInfo("CTFBaseBoss", "m_lastHealthPercentage") + 28, false, 4, true); //ResolvePlayerCollisions
SetEntProp(npc.index, Prop_Data, "m_takedamage", 0);
SetEntProp(npc.index, Prop_Data, "m_lifeState", 1);
SetEntProp(npc.index, Prop_Data, "m_nSolidType", 0);
ActivateEntity(npc.index);
SDKHook(npc.index, SDKHook_Think, BasicPetThink);
//Fix collisions
SetEntPropVector(npc.index, Prop_Send, "m_vecMaxs", view_as<float>( { 6.5, 6.5, 34.0 } ));
SetEntPropVector(npc.index, Prop_Data, "m_vecMaxs", view_as<float>( { 6.5, 6.5, 34.0 } ));
SetEntPropVector(npc.index, Prop_Send, "m_vecMins", view_as<float>( { -6.5, -6.5, 0.0 } ));
SetEntPropVector(npc.index, Prop_Data, "m_vecMins", view_as<float>( { -6.5, -6.5, 0.0 } ));
npc.DoingSpecial = false;
npc.Pathing = false;
npc.SpecialTime = 0.0;
npc.Weapon = INVALID_ENT_REFERENCE;
return npc;
}
public Address GetLocomotionInterface()
{
return SDKCall(g_hGetLocomotionInterface, SDKCall(g_hMyNextBotPointer, this.index));
}
public Address GetBodyInterface()
{
return SDKCall(g_hGetBodyInterface, SDKCall(g_hMyNextBotPointer, this.index));
}
public Address GetStudioHdr()
{
return view_as<Address>(GetEntData(this.index, 283 * 4));
}
public float GetPoseParameter(int iParameter)
{
return SDKCall(g_hGetPoseParameter, this.index, iParameter);
}
public void SetPoseParameter(int iParameter, float value)
{
Address pStudioHdr = this.GetStudioHdr();
if(pStudioHdr == Address_Null)
return;
SDKCall(g_hSetPoseParameter, this.index, pStudioHdr, iParameter, value);
}
public int LookupPoseParameter(const char[] szName)
{
Address pStudioHdr = this.GetStudioHdr();
if(pStudioHdr == Address_Null)
return -1;
return SDKCall(g_hLookupPoseParameter, this.index, pStudioHdr, szName);
}
public int LookupSequence(const char[] anim)
{
Address pStudioHdr = this.GetStudioHdr();
if(pStudioHdr == Address_Null)
return -1;
return SDKCall(g_hLookupSequence, pStudioHdr, anim);
}
public void SetAnimation(const char[] anim)
{
int iSequence = this.LookupSequence(anim);
if(iSequence >= 0)
SDKCall(g_hResetSequence, this.index, iSequence);
}
public bool IsPlayingGesture(const char[] anim)
{
int iSequence = this.LookupSequence(anim);
if(iSequence >= 0)
return IsPlayingGesture(this.index, iSequence);
return false;
}
public int PlayGesture(const char[] anim, bool autokill = true)
{
int iSequence = this.LookupSequence(anim);
if(iSequence < 0)
return -1;
return SDKCall(g_hAddGestureSequence, this.index, iSequence, autokill);
}
public void CreatePather(int iTarget, float flStep, float flJump, float flDrop, int iSolid, float flAhead, float flRePath, float flHull)
{
PF_Create(this.index, flStep, flJump, flDrop, 0.6, iSolid, flAhead, flRePath, flHull);
PF_SetGoalEntity(this.index, iTarget);
PF_EnableCallback(this.index, PFCB_Approach, PluginBot_Approach);
PF_EnableCallback(this.index, PFCB_ClimbUpToLedge, PluginBot_Jump);
PF_EnableCallback(this.index, PFCB_GetPathCost, PluginBot_PathCost);
PF_EnableCallback(this.index, PFCB_OnMoveToFailure, PluginBot_PathFail);
//PF_EnableCallback(this.index, PFCB_OnContact, PluginBot_OnContact);
PF_EnableCallback(this.index, PFCB_OnActorEmoted, PluginBot_OnActorEmoted);
}
public void Approach(const float vecGoal[3])
{
SDKCall(g_hApproach, this.GetLocomotionInterface(), vecGoal, 0.1);
}
public void FaceTowards(const float vecGoal[3], float speed = 250.0)
{
//Sad!
ConVar flTurnRate = FindConVar("tf_base_boss_max_turn_rate");
float flPrevValue = flTurnRate.FloatValue;
flTurnRate.FloatValue = speed;
SDKCall(g_hFaceTowards, this.GetLocomotionInterface(), vecGoal);
flTurnRate.FloatValue = flPrevValue;
}
public void Jump()
{
SDKCall(g_hJump, this.GetLocomotionInterface());
}
public void Update()
{
SDKCall(g_hStudioFrameAdvance, this.index);
SDKCall(g_hRun, this.GetLocomotionInterface());
SDKCall(g_hStuckMonitor, this.GetLocomotionInterface());
bool bStuck = SDKCall(g_hIsStuck, this.GetLocomotionInterface());
if(bStuck)
{
int iOwner = GetEntPropEnt(this.index, Prop_Send, "m_hOwnerEntity");
this.DoingSpecial = false;
PF_SetGoalEntity(this.index, iOwner);
SDKCall(g_hClearStuckStatus, this.GetLocomotionInterface(), "Un-Stuck");
TeleportEntity(this.index, WorldSpaceCenter(iOwner), NULL_VECTOR, NULL_VECTOR);
}
}
public void GetVelocity(float vecOut[3])
{
SDKCall(g_hGetVelocity, this.GetLocomotionInterface(), vecOut);
}
public void SetVelocity(const float vec[3])
{
SDKCall(g_hSetVelocity, this.GetLocomotionInterface(), vec);
}
public int FindAttachment(const char[] pAttachmentName)
{
Address pStudioHdr = this.GetStudioHdr();
if(pStudioHdr == Address_Null)
return -1;
return SDKCall(g_hStudio_FindAttachment, pStudioHdr, pAttachmentName) + 1;
}
public void GetAttachment(const char[] szName, float absOrigin[3], float absAngles[3])
{
SDKCall(g_hGetAttachment, this.index, this.FindAttachment(szName), absOrigin, absAngles);
}
public int EquipItem(const char[] attachment, const char[] model, const char[] anim = "", int skin = 0, float flScale = 1.0)
{
int item = CreateEntityByName("prop_dynamic");
DispatchKeyValue(item, "model", model);
DispatchKeyValueFloat(item, "modelscale", flScale == 1.0 ? GetEntPropFloat(this.index, Prop_Send, "m_flModelScale") : flScale);
DispatchSpawn(item);
SetEntProp(item, Prop_Send, "m_nSkin", skin);
SetEntProp(item, Prop_Send, "m_hOwnerEntity", this.index);
SetEntProp(item, Prop_Send, "m_fEffects", EF_BONEMERGE|EF_PARENT_ANIMATES);
if(!StrEqual(anim, ""))
{
SetVariantString(anim);
AcceptEntityInput(item, "SetAnimation");
}
SetVariantString("!activator");
AcceptEntityInput(item, "SetParent", this.index);
SetVariantString(attachment);
AcceptEntityInput(item, "SetParentAttachmentMaintainOffset");
return item;
}
}
methodmap PetMedic < BaseNPC
{
property int BeamEntity
{
public get()
{
return EntRefToEntIndex(this.ExtractStringValueAsInt("BeamEntity"));
}
public set(int iInt)
{
char buff[32];
IntToString(iInt == INVALID_ENT_REFERENCE ? -1 : EntIndexToEntRef(iInt), buff, sizeof(buff));
SetCustomKeyValue(this.index, "BeamEntity", buff, true);
}
}
property bool Healing
{
public get() { return !!this.ExtractStringValueAsInt("Healing"); }
public set(bool bOnOff) { char buff[8]; IntToString(bOnOff, buff, sizeof(buff)); SetCustomKeyValue(this.index, "Healing", buff, true); }
}
property float NextHealTime
{
public get() { return this.ExtractStringValueAsFloat("NextHealTime"); }
public set(float flNextTime) { char buff[8]; FloatToString(flNextTime, buff, sizeof(buff)); SetCustomKeyValue(this.index, "NextHealTime", buff, true); }
}
public PetMedic(int client, float vecPos[3], float vecAng[3], const char[] model)
{
PetMedic pet = view_as<PetMedic>(BaseNPC(vecPos, vecAng, model, "0.5"));
SetEntProp(pet.index, Prop_Send, "m_nSkin", GetClientTeam(client) - 2);
SetEntPropEnt(pet.index, Prop_Send, "m_hOwnerEntity", client);
pet.Healing = false;
pet.BeamEntity = INVALID_ENT_REFERENCE;
pet.NextHealTime = 0.0;
//REQUIRED
SetCustomKeyValue(pet.index, "MoveAnim", "run_SECONDARY", true);
pet.MoveSpeed = 150.0;
SetCustomKeyValue(pet.index, "IdleAnim", "stand_SECONDARY", true);
pet.OutOfRange = 300.0;
//////////
pet.CreatePather(client, 18.0, 64.0, 1000.0, MASK_NPCSOLID | MASK_PLAYERSOLID, 50.0, 0.5, 1.0);
pet.SetAnimation("run_SECONDARY");
pet.Pathing = true;
SDKUnhook(pet.index, SDKHook_Think, BasicPetThink);
SDKHook(pet.index, SDKHook_Think, PetMedicThink);
SDKHook(pet.index, SDKHook_Think, Blend9Think);
//pet.EquipItem("head", "models/player/items/all_class/xms_santa_hat_medic.mdl");
return pet;
}
public void StartHealing(int iEnt)
{
int client = GetEntPropEnt(this.index, Prop_Send, "m_hOwnerEntity");
int iWeapon = this.Weapon;
if(iWeapon != INVALID_ENT_REFERENCE)
{
this.BeamEntity = TF2_CreateBeam(iWeapon, "muzzle", client, "flag", GetClientTeam(client) == 2 ? "medicgun_beam_red" : "medicgun_beam_blue");
this.Healing = true;
EmitSoundToAll(")weapons/medigun_heal.wav", this.index, SNDCHAN_WEAPON);
}
}
public void StopHealing()
{
int iBeam = this.BeamEntity;
if(iBeam != INVALID_ENT_REFERENCE)
{
int iBeamTarget = GetEntPropEnt(iBeam, Prop_Send, "m_hOwnerEntity");
if(IsValidEntity(iBeamTarget))
{
AcceptEntityInput(iBeamTarget, "ClearParent");
AcceptEntityInput(iBeamTarget, "Kill");
}
AcceptEntityInput(iBeam, "ClearParent");
AcceptEntityInput(iBeam, "Kill");
EmitSoundToAll(")weapons/medigun_no_target.wav", this.index, SNDCHAN_WEAPON);
StopSound(this.index, SNDCHAN_WEAPON, ")weapons/medigun_heal.wav");
this.Healing = false;
}
}
}
methodmap PetTank < BaseNPC
{
property int LeftTrack
{
public get()
{
return EntRefToEntIndex(this.ExtractStringValueAsInt("LeftTrack"));
}
public set(int iInt)
{
char buff[32];
IntToString(iInt == INVALID_ENT_REFERENCE ? -1 : EntIndexToEntRef(iInt), buff, sizeof(buff));
SetCustomKeyValue(this.index, "LeftTrack", buff, true);
}
}
property int RightTrack
{
public get()
{
return EntRefToEntIndex(this.ExtractStringValueAsInt("RightTrack"));
}
public set(int iInt)
{
char buff[32];
IntToString(iInt == INVALID_ENT_REFERENCE ? -1 : EntIndexToEntRef(iInt), buff, sizeof(buff));
SetCustomKeyValue(this.index, "RightTrack", buff, true);
}
}
property int Bomb
{
public get()
{
return EntRefToEntIndex(this.ExtractStringValueAsInt("Bomb"));
}
public set(int iInt)
{
char buff[32];
IntToString(iInt == INVALID_ENT_REFERENCE ? -1 : EntIndexToEntRef(iInt), buff, sizeof(buff));
SetCustomKeyValue(this.index, "Bomb", buff, true);
}
}
property bool Deploying
{
public get() { return !!this.ExtractStringValueAsInt("Deploying"); }
public set(bool bOnOff) { char buff[8]; IntToString(bOnOff, buff, sizeof(buff)); SetCustomKeyValue(this.index, "Deploying", buff, true); }
}
public PetTank(int client, float vecPos[3], float vecAng[3], const char[] model)
{
PetTank pet = view_as<PetTank>(BaseNPC(vecPos, vecAng, model, "0.15", _, false));
SetEntProp(pet.index, Prop_Send, "m_nSkin", GetRandomInt(0, 1));
SetEntPropEnt(pet.index, Prop_Send, "m_hOwnerEntity", client);
pet.LeftTrack = INVALID_ENT_REFERENCE;
pet.RightTrack = INVALID_ENT_REFERENCE;
pet.Bomb = INVALID_ENT_REFERENCE;
pet.Deploying = false;
pet.MoveSpeed = 150.0;
pet.OutOfRange = 300.0;
pet.CreatePather(client, 18.0, 64.0, 1000.0, MASK_NPCSOLID | MASK_PLAYERSOLID, 50.0, 0.5, 1.0);
pet.SetAnimation("movement");
pet.Pathing = true;
EmitSoundToAll(")mvm/mvm_tank_start.wav", pet.index);
//EmitSoundToAll(")mvm/mvm_tank_loop.wav", pet.index, _, _, _, 0.20);
TF2_CreateParticle(pet.index, "smoke_attachment", "buildingdamage_smoke3");
SDKUnhook(pet.index, SDKHook_Think, BasicPetThink);
SDKHook(pet.index, SDKHook_Think, PetTankThink);
return pet;
}
}
methodmap PetEngineer < BaseNPC
{
property int GettingAmmo
{
public get() { return this.ExtractStringValueAsInt("GettingAmmo"); }
public set(int iInt) { char buff[8]; IntToString(iInt, buff, sizeof(buff)); SetCustomKeyValue(this.index, "GettingAmmo", buff, true); }
}
property bool CarryingAmmo
{
public get() { return !!this.ExtractStringValueAsInt("CarryingAmmo"); }
public set(bool bOnOff) { char buff[8]; IntToString(bOnOff, buff, sizeof(buff)); SetCustomKeyValue(this.index, "CarryingAmmo", buff, true); }
}
property int AmmoRef
{
public get()
{
return EntRefToEntIndex(this.ExtractStringValueAsInt("AmmoRef"));
}
public set(int iInt)
{
char buff[32];
IntToString(iInt == INVALID_ENT_REFERENCE ? -1 : EntIndexToEntRef(iInt), buff, sizeof(buff));
SetCustomKeyValue(this.index, "AmmoRef", buff, true);
}
}
property float NextAmmoCheckTime
{
public get() { return this.ExtractStringValueAsFloat("NextAmmoCheckTime"); }
public set(float flNextTime) { char buff[8]; FloatToString(flNextTime, buff, sizeof(buff)); SetCustomKeyValue(this.index, "NextAmmoCheckTime", buff, true); }
}
public PetEngineer(int client, float vecPos[3], float vecAng[3])
{
PetEngineer pet = view_as<PetEngineer>(BaseNPC(vecPos, vecAng, "models/bots/engineer/bot_engineer.mdl", "0.5"));
SetEntProp(pet.index, Prop_Send, "m_nSkin", GetClientTeam(client) - 2);
SetEntPropEnt(pet.index, Prop_Send, "m_hOwnerEntity", client);
//REQUIRED IF YOU'RE GOING TO USE Blend9Think
SetCustomKeyValue(pet.index, "MoveAnim", "Run_MELEE", true);
pet.MoveSpeed = 115.0;
SetCustomKeyValue(pet.index, "IdleAnim", "Stand_MELEE", true);
pet.OutOfRange = 300.0;
//////////
pet.GettingAmmo = false;
pet.CarryingAmmo = false;
pet.AmmoRef = INVALID_ENT_REFERENCE;
pet.NextAmmoCheckTime = 0.0;
pet.CreatePather(client, 18.0, 64.0, 1000.0, MASK_NPCSOLID | MASK_PLAYERSOLID, 50.0, 0.5, 1.0);
pet.SetAnimation("Stand_PRIMARY");
pet.Pathing = true;
//Unhook because we have our own think function.
SDKUnhook(pet.index, SDKHook_Think, BasicPetThink);
//You can implement your own pet functions here.
SDKHook(pet.index, SDKHook_Think, PetEngineerThink);
//Controls 9 way blend animation managing
SDKHook(pet.index, SDKHook_Think, Blend9Think);
//pet.EquipItem("head", "models/player/items/all_class/xms_santa_hat_engineer.mdl");
return view_as<PetEngineer>(pet);
}
public void StopAmmoHunt()
{
int client = GetEntPropEnt(this.index, Prop_Send, "m_hOwnerEntity");
PF_SetGoalEntity(this.index, client);
this.GettingAmmo = false;
this.Pathing = true;
SetCustomKeyValue(this.index, "MoveAnim", "Run_MELEE", true);
this.MoveSpeed = 150.0;
SetCustomKeyValue(this.index, "IdleAnim", "Stand_MELEE", true);
this.OutOfRange = 300.0;
AcceptEntityInput(this.Weapon, "Kill");
this.Weapon = this.EquipItem("head", "models/weapons/w_models/w_wrench.mdl", _, GetClientTeam(client) - 2);
SetVariantString("1.0");
AcceptEntityInput(this.Weapon, "SetModelScale");
}
}
methodmap PetMerasmus < BaseNPC
{
public PetMerasmus(int client, float vecPos[3], float vecAng[3])
{
BaseNPC pet = BaseNPC(vecPos, vecAng, "models/bots/merasmus/merasmus.mdl", "0.25");
SetEntProp(pet.index, Prop_Send, "m_nSkin", GetRandomInt(1, 2));
SetEntPropEnt(pet.index, Prop_Send, "m_hOwnerEntity", client);
SetEntProp(pet.index, Prop_Send, "m_nBody", 2);
//REQUIRED
SetCustomKeyValue(pet.index, "MoveAnim", "run_MELEE", true);
pet.MoveSpeed = 150.0;
SetCustomKeyValue(pet.index, "IdleAnim", "Stand_MELEE", true);
pet.OutOfRange = 300.0;
//////////
pet.CreatePather(client, 18.0, 64.0, 1000.0, MASK_NPCSOLID | MASK_PLAYERSOLID, 50.0, 0.5, 1.0);
pet.SetAnimation("run_MELEE");
pet.Pathing = true;
SDKUnhook(pet.index, SDKHook_Think, BasicPetThink);
SDKHook(pet.index, SDKHook_Think, Blend9Think);
SDKHook(pet.index, SDKHook_Think, PetMerasmusThink);
//pet.EquipItem("head", "models/player/items/all_class/xms_santa_hat_sniper.mdl");
return view_as<PetMerasmus>(pet);
}
}
methodmap PetSkeletonKing < BaseNPC
{
public PetSkeletonKing(int client, float vecPos[3], float vecAng[3])
{
BaseNPC pet = BaseNPC(vecPos, vecAng, "models/bots/skeleton_sniper_boss/skeleton_sniper_boss.mdl", "0.65");
SetEntProp(pet.index, Prop_Send, "m_nSkin", GetRandomInt(0, 3));
SetEntPropEnt(pet.index, Prop_Send, "m_hOwnerEntity", client);
//REQUIRED
SetCustomKeyValue(pet.index, "MoveAnim", "run_MELEE", true);
pet.MoveSpeed = 150.0;
SetCustomKeyValue(pet.index, "IdleAnim", "stand_MELEE", true);
pet.OutOfRange = 300.0;
//////////
pet.CreatePather(client, 18.0, 64.0, 1000.0, MASK_NPCSOLID | MASK_PLAYERSOLID, 50.0, 0.5, 1.0);
pet.Pathing = true;
SDKUnhook(pet.index, SDKHook_Think, BasicPetThink);
SDKHook(pet.index, SDKHook_Think, Blend9Think);
SDKHook(pet.index, SDKHook_Think, PetSkeleKingThink);
return view_as<PetSkeletonKing>(pet);
}
}
methodmap PetMiniMe < BaseNPC
{
public PetMiniMe(int client, float vecPos[3], float vecAng[3])
{
char strModel[PLATFORM_MAX_PATH];
GetEntPropString(client, Prop_Data, "m_ModelName", strModel, PLATFORM_MAX_PATH);
BaseNPC pet = BaseNPC(vecPos, vecAng, strModel, "0.5");
// SetEntProp(pet.index, Prop_Data, "m_nBody", 2);
SetEntProp(pet.index, Prop_Send, "m_nSkin", GetClientTeam(client) - 2);
SetEntProp(pet.index, Prop_Send, "m_hOwnerEntity", client);
SetEntPropEnt(pet.index, Prop_Send, "m_hOwnerEntity", client);
//REQUIRED
SetCustomKeyValue(pet.index, "MoveAnim", "run_MELEE", true);
pet.MoveSpeed = 150.0;
SetCustomKeyValue(pet.index, "IdleAnim", "stand_MELEE", true);
pet.OutOfRange = 300.0;
//////////
pet.CreatePather(client, 18.0, 64.0, 1000.0, MASK_NPCSOLID | MASK_PLAYERSOLID, 50.0, 0.5, 1.0);
pet.Pathing = true;
SDKHook(pet.index, SDKHook_Think, Blend9Think);
//Mirror wearables
int iWearable = -1;
while ((iWearable = FindEntityByClassname(iWearable, "tf_wearable*")) != -1)
{
if(!GetEntProp(iWearable, Prop_Send, "m_bDisguiseWearable") && GetEntPropEnt(iWearable, Prop_Send, "m_hOwnerEntity") == client)
{
GetEntPropString(iWearable, Prop_Data, "m_ModelName", strModel, PLATFORM_MAX_PATH);
int iItem = pet.EquipItem("head", strModel, _, GetClientTeam(client) - 2);
SetVariantString("1.0");
AcceptEntityInput(iItem, "SetModelScale");
}
}
int iMelee = GetPlayerWeaponSlot(client, 2);
int table = FindStringTable("modelprecache");
ReadStringTable(table, GetEntProp(iMelee, Prop_Send, "m_iWorldModelIndex"), strModel, PLATFORM_MAX_PATH);
iMelee = pet.EquipItem("head", strModel, _, GetClientTeam(client) - 2);
SetVariantString("1.0");
AcceptEntityInput(iMelee, "SetModelScale");
return view_as<PetMiniMe>(pet);
}
}
methodmap PetYeti < BaseNPC
{
public PetYeti(int client, float vecPos[3], float vecAng[3])
{
BaseNPC pet = BaseNPC(vecPos, vecAng, "models/player/heavy.mdl", "0.5");
SetEntProp(pet.index, Prop_Send, "m_nRenderFX", 6);
SetEntProp(pet.index, Prop_Send, "m_nSkin", GetRandomInt(0, 3));
SetEntPropEnt(pet.index, Prop_Send, "m_hOwnerEntity", client);
//REQUIRED
SetCustomKeyValue(pet.index, "MoveAnim", "run_MELEE", true);
pet.MoveSpeed = 150.0;
SetCustomKeyValue(pet.index, "IdleAnim", "stand_MELEE", true);
pet.OutOfRange = 300.0;
//////////
pet.CreatePather(client, 18.0, 64.0, 1000.0, MASK_NPCSOLID | MASK_PLAYERSOLID, 50.0, 0.5, 1.0);
pet.Pathing = true;
SDKUnhook(pet.index, SDKHook_Think, BasicPetThink);
SDKHook(pet.index, SDKHook_Think, Blend9Think);
SDKHook(pet.index, SDKHook_Think, PetYetiThink);
pet.EquipItem("head", "models/player/items/taunts/yeti/yeti.mdl");
//pet.EquipItem("head", "models/player/items/all_class/xms_santa_hat_heavy.mdl");
return view_as<PetYeti>(pet);
}
}
methodmap PetDeskBoy < BaseNPC
{
public PetDeskBoy(int client, float vecPos[3], float vecAng[3])
{
BaseNPC pet = BaseNPC(vecPos, vecAng, "models/player/engineer.mdl", "0.5");
SetEntProp(pet.index, Prop_Send, "m_nSkin", GetClientTeam(client) - 2);
SetEntPropEnt(pet.index, Prop_Send, "m_hOwnerEntity", client);
//REQUIRED
SetCustomKeyValue(pet.index, "MoveAnim", "taunt_russian", true);
pet.MoveSpeed = 150.0;
SetCustomKeyValue(pet.index, "IdleAnim", "taunt_russian", true);
pet.OutOfRange = 300.0;
//////////
int iSequenceMove = SDKCall(g_hLookupSequence, pet.GetStudioHdr(), "taunt_russian");
SDKCall(g_hResetSequence, pet.index, iSequenceMove);
pet.CreatePather(client, 18.0, 64.0, 1000.0, MASK_NPCSOLID | MASK_PLAYERSOLID, 50.0, 0.5, 1.0);
pet.Pathing = true;
//SDKUnhook(pet.index, SDKHook_Think, BasicPetThink);
SDKHook(pet.index, SDKHook_Think, DeskBoyThink);
//pet.EquipItem("head", "models/player/items/all_class/xms_santa_hat_engineer.mdl");
return view_as<PetDeskBoy>(pet);
}
}
methodmap PetBuster < BaseNPC
{
public PetBuster(int client, float vecPos[3], float vecAng[3])
{
BaseNPC pet = BaseNPC(vecPos, vecAng, "models/bots/demo/bot_sentry_buster.mdl", "0.5");
SetEntPropEnt(pet.index, Prop_Send, "m_hOwnerEntity", client);
//REQUIRED
SetCustomKeyValue(pet.index, "MoveAnim", "Run_MELEE", true);
pet.MoveSpeed = 150.0;
SetCustomKeyValue(pet.index, "IdleAnim", "Stand_MELEE", true);
pet.OutOfRange = 300.0;
//////////
pet.CreatePather(client, 18.0, 64.0, 1000.0, MASK_NPCSOLID | MASK_PLAYERSOLID, 50.0, 0.5, 1.0);
pet.Pathing = true;
SDKUnhook(pet.index, SDKHook_Think, BasicPetThink);
SDKHook(pet.index, SDKHook_Think, Blend9Think);
SDKHook(pet.index, SDKHook_Think, SentryBusterThink);
return view_as<PetBuster>(pet);
}
}
//Stop when near owner
//Adjust speed near owner
//Run update
public void BasicPetThink(int iEntity)
{
int client = GetEntPropEnt(iEntity, Prop_Send, "m_hOwnerEntity");
if(client <= 0 || client > MaxClients || !IsClientInGame(client))
{
AcceptEntityInput(iEntity, "Kill");
return;
}
BaseNPC npc = view_as<BaseNPC>(iEntity);
npc.Update();
float flOrigin[3], flAbsAngles[3];
GetEntPropVector(iEntity, Prop_Send, "m_vecOrigin", flOrigin);
GetEntPropVector(iEntity, Prop_Data, "m_angRotation", flAbsAngles);
float flMoveSpeed = npc.MoveSpeed;
float flOutOfRange = npc.OutOfRange;
float flCPos[3]; GetClientAbsOrigin(client, flCPos);
float flDistance = GetVectorDistance(flCPos, flOrigin);
//We don't wanna fall too behind.
SetEntPropFloat(iEntity, Prop_Data, "m_speed", (flDistance >= flOutOfRange) ? (flMoveSpeed * 2) : (flMoveSpeed));
//Do something
if(npc.DoingSpecial)
{
npc.DoingSpecial = false;
PF_SetGoalEntity(npc.index, client);
PrintToChat(client, "No.");
}
if(flDistance <= (flOutOfRange / 2))
{
if(npc.Pathing)
{
npc.Pathing = false;
}
}
else
{
if(!npc.Pathing)
{
npc.Pathing = true;
}
}
}
public void PetYetiThink(int iEntity)
{
int client = GetEntPropEnt(iEntity, Prop_Send, "m_hOwnerEntity");
if(client <= 0 || client > MaxClients || !IsClientInGame(client))
{
AcceptEntityInput(iEntity, "Kill");
return;
}
//taunt_demo_nuke_shroomcloud
PetYeti npc = view_as<PetYeti>(iEntity);
npc.Update();
float flOrigin[3], flAbsAngles[3];
GetEntPropVector(iEntity, Prop_Send, "m_vecOrigin", flOrigin);
GetEntPropVector(iEntity, Prop_Data, "m_angRotation", flAbsAngles);
float flMoveSpeed = npc.MoveSpeed;
float flOutOfRange = npc.OutOfRange;
float flCPos[3]; GetClientAbsOrigin(client, flCPos);
float flDistance = GetVectorDistance(flCPos, flOrigin);
//We don't wanna fall too behind.
SetEntPropFloat(iEntity, Prop_Data, "m_speed", (flDistance >= flOutOfRange) ? (flMoveSpeed * 2) : (flMoveSpeed));
//Stomp
if(npc.DoingSpecial)
{
float SpecialPos[3];
npc.GetSpecialPos(SpecialPos);
if(GetVectorDistance(SpecialPos, flOrigin) <= 20.0 || !npc.Pathing)
{
if(npc.Pathing)
{
npc.PlayGesture("taunt_yeti", false);
npc.SpecialTime = GetGameTime() + 5.3;
}
npc.Pathing = false;
float SpecialTime = npc.SpecialTime - GetGameTime();
if(SpecialTime <= 0.0)
{
CreateParticle("weightdrop", flOrigin, flAbsAngles);
Explode(client, flOrigin, 100.0, 100.0, "", "");
npc.SpecialTime = GetGameTime() + 10.0; //Don't repeat
}
//Needed because sometimes if i'm just calling !IsPlayingGesture it might miss it due to autokill.
int iSequence = npc.LookupSequence("taunt_yeti");
int iLayer = FindGestureLayer(npc.index, iSequence);
if(iLayer != -1)
{
CBaseAnimatingOverlay overlay = CBaseAnimatingOverlay(npc.index);
CAnimationLayer layer = overlay.GetLayer(iLayer);
float flCycle = layer.Get(m_flCycle);
if(flCycle >= 1.0)
{