-
Notifications
You must be signed in to change notification settings - Fork 22
/
zp_weapon_turret.sp
2827 lines (2340 loc) · 76.3 KB
/
zp_weapon_turret.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
/**
* ============================================================================
*
* Zombie Plague
*
*
* Copyright (C) 2015-2023 qubka (Nikita Ushakov)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* ============================================================================
**/
#include <sourcemod>
#include <sdktools>
#include <sdkhooks>
#include <zombieplague>
#pragma newdecls required
#pragma semicolon 1
/**
* @brief Record plugin info.
**/
public Plugin myinfo =
{
name = "[ZP] Weapon: Turret",
author = "qubka (Nikita Ushakov), Pelipoika",
description = "Addon of custom weapons",
version = "2.0",
url = "https://forums.alliedmods.net/showthread.php?t=290657"
}
// Decal index
int gDecal[5]; int gTrail;
// Sound index
int gSoundShoot; int gSoundUpgrade; ConVar gKnockback;
// Weapon index
int gWeapon;
// Item index
int gItem;
// Platform
EngineOS gPlatform;
/**
* @section Variables to store virtual SDK adresses.
**/
Handle hSDKCallLookupPoseParameter;
Handle hSDKCallLookupSequence;
Handle hSDKCallStudioFrameAdvance;
Handle hSDKCallAddLayeredSequence;
int Animating_StudioHdr;
int AnimatingOverlay_Count;
/**
* @endsection
**/
/**
* @section Information about the weapon.
**/
#define WEAPON_IDLE_TIME 1.63
/**
* @endsection
**/
/**
* @section Properties of the turret.
**/
#define SENTRY_EYE_OFFSET_LEVEL_1 32.0
#define SENTRY_EYE_OFFSET_LEVEL_2 40.0
#define SENTRY_EYE_OFFSET_LEVEL_3 46.0
#define SENTRY_SHOOTER_OFFSET_LEVEL 70.0
/**
* @endsection
**/
/**
* @section Properties of the gibs shooter.
**/
#define METAL_GIBS_AMOUNT 5.0
#define METAL_GIBS_DELAY 0.2
#define METAL_GIBS_SPEED 200.0
#define METAL_GIBS_VARIENCE 2.0
#define METAL_GIBS_LIFE 5.0
#define METAL_GIBS_DURATION 6.0
/**
* @endsection
**/
/**
* @section Sentry models.
**/
#define SENTRY_MODEL_LEVEL_1 "models/buildables/sentry1.mdl"
#define SENTRY_MODEL_LEVEL_1_UPGRADE "models/buildables/sentry1_heavy.mdl"
#define SENTRY_MODEL_LEVEL_2 "models/buildables/sentry2.mdl"
#define SENTRY_MODEL_LEVEL_2_UPGRADE "models/buildables/sentry2_heavy.mdl"
#define SENTRY_MODEL_LEVEL_3 "models/buildables/sentry3_fix2.mdl"
#define SENTRY_MODEL_LEVEL_3_UPGRADE "models/buildables/sentry3_heavy.mdl"
#define SENTRY_ROCKET_MODEL "models/buildables/sentry3_rockets.mdl"
#define SENTRY_BLUEPRINT_MODEL "models/buildables/sentry1_blueprint.mdl"
#define SENTRY_MODEL_LEVEL_1_GIB_1 "models/buildables/gibs/sentry1_gib1.mdl"
#define SENTRY_MODEL_LEVEL_1_GIB_2 "models/buildables/gibs/sentry1_gib2.mdl"
#define SENTRY_MODEL_LEVEL_1_GIB_3 "models/buildables/gibs/sentry1_gib3.mdl"
#define SENTRY_MODEL_LEVEL_1_GIB_4 "models/buildables/gibs/sentry1_gib4.mdl"
#define SENTRY_MODEL_LEVEL_2_GIB_1 "models/buildables/gibs/sentry2_gib1.mdl"
#define SENTRY_MODEL_LEVEL_2_GIB_2 "models/buildables/gibs/sentry2_gib2.mdl"
#define SENTRY_MODEL_LEVEL_2_GIB_3 "models/buildables/gibs/sentry2_gib3.mdl"
#define SENTRY_MODEL_LEVEL_2_GIB_4 "models/buildables/gibs/sentry2_gib4.mdl"
#define SENTRY_MODEL_LEVEL_3_GIB_1 "models/buildables/gibs/sentry3_gib1.mdl"
/**
* @endsection
**/
/**
* @section Sentry states.
**/
enum
{
SENTRY_STATE_SEARCHING,
SENTRY_STATE_ATTACKING
};
/**
* @endsection
**/
/**
* @section Sentry modes.
**/
enum
{
SENTRY_MODE_NORMAL,
SENTRY_MODE_AGRESSIVE,
SENTRY_MODE_ROCKET
};
/**
* @endsection
**/
/**
* @section Sentry sounds.
**/
enum
{
SENTRY_SOUND_EMPTY = 1,
SENTRY_SOUND_FINISH,
SENTRY_SOUND_SCAN,
SENTRY_SOUND_SCAN2,
SENTRY_SOUND_SCAN3,
SENTRY_SOUND_SHOOT,
SENTRY_SOUND_SHOOT2,
SENTRY_SOUND_SHOOT3,
SENTRY_SOUND_SHOOT4,
SENTRY_SOUND_SPOT,
SENTRY_SOUND_SPOT2,
SENTRY_SOUND_ROCKET,
SENTRY_SOUND_EXPLOAD,
SENTRY_SOUND_UPGRADE
};
/**
* @sectionend
**/
/*__________________________________________________________________________________________________*/
// Animation sequences
enum
{
ANIM_IDLE,
ANIM_DRAW
};
// Effect modes
enum
{
EFFECT_CREATE,
EFFECT_KILL,
EFFECT_UPDATE,
EFFECT_PLACE
};
// Cvars
ConVar hCvarSentryRewards;
ConVar hCvarSentryPickup;
ConVar hCvarSentryAttackNpc;
ConVar hCvarSentryAttackVisibililty;
ConVar hCvarSentryBulletDamage;
ConVar hCvarSentryBulletRange;
ConVar hCvarSentryBulletDistance;
ConVar hCvarSentryBulletRadius;
ConVar hCvarSentryBulletTurn;
ConVar hCvarSentryBulletThink;
ConVar hCvarSentryBulletSpeed;
ConVar hCvarSentryRocketDelay;
ConVar hCvarSentryRocketReload;
ConVar hCvarSentryRocketSpeed;
ConVar hCvarSentryRocketDamage;
ConVar hCvarSentryRocketRadius;
ConVar hCvarSentryRocketTrail;
ConVar hCvarSentryRocketExp;
ConVar hCvarSentryControlMenu;
ConVar hCvarSentryControlUpgradeRatio;
ConVar hCvarSentryControlRefillRatio;
ConVar hCvarSentryDeathEffect;
/**
* @brief Called when the plugin is fully initialized and all known external references are resolved.
* This is only called once in the lifetime of the plugin, and is paired with OnPluginEnd().
**/
public void OnPluginStart()
{
hCvarSentryRewards = CreateConVar("zp_weapon_sentry_rewards", "1", "Give rewards for damaging to the owner?", 0, true, 0.0, true, 1.0);
hCvarSentryPickup = CreateConVar("zp_weapon_sentry_pickup", "1", "Can pickup?", 0, true, 0.0, true, 1.0);
hCvarSentryAttackNpc = CreateConVar("zp_weapon_sentry_attack_npc", "0", "Attack npc? (chicken, ect)", 0, true, 0.0, true, 1.0);
hCvarSentryAttackVisibililty = CreateConVar("zp_weapon_sentry_attack_visibility", "50.0", "Min alpha to see target", 0, true, 0.0);
hCvarSentryBulletDamage = CreateConVar("zp_weapon_sentry_bullet_damage ", "20.0", "Bullet damage", 0, true, 0.0);
hCvarSentryBulletRange = CreateConVar("zp_weapon_sentry_bullet_range", "1100.0", "Shoot range", 0, true, 0.0);
hCvarSentryBulletDistance = CreateConVar("zp_weapon_sentry_bullet_distance", "8192.0", "Bullet distance", 0, true, 0.0);
hCvarSentryBulletRadius = CreateConVar("zp_weapon_sentry_bullet_radius", "5.0", "Damage radius", 0, true, 0.0);
hCvarSentryBulletTurn = CreateConVar("zp_weapon_sentry_bullet_turn", "2.0", "Turn rate", 0, true, 0.0);
hCvarSentryBulletThink = CreateConVar("zp_weapon_sentry_bullet_think", "0.05", "Think rate", 0, true, 0.0);
hCvarSentryBulletSpeed = CreateConVar("zp_weapon_sentry_bullet_speed", "0.2", "Shoot delay", 0, true, 0.0);
hCvarSentryRocketDelay = CreateConVar("zp_weapon_sentry_rocket_delay", "3.0", "Rocket shoot delay", 0, true, 0.0);
hCvarSentryRocketReload = CreateConVar("zp_weapon_sentry_rocket_reload", "1.8", "Rocket reload", 0, true, 0.0);
hCvarSentryRocketSpeed = CreateConVar("zp_weapon_sentry_rocket_speed", "1000.0", "Projectile speed", 0, true, 0.0);
hCvarSentryRocketDamage = CreateConVar("zp_weapon_sentry_rocket_damage", "300.0", "Projectile damage", 0, true, 0.0);
hCvarSentryRocketRadius = CreateConVar("zp_weapon_sentry_rocket_radius", "400.0", "Damage radius", 0, true, 0.0);
hCvarSentryRocketTrail = CreateConVar("zp_weapon_sentry_rocket_trail", "sentry_rocket", "Particle effect for the trail (''-default)");
hCvarSentryRocketExp = CreateConVar("zp_weapon_sentry_rocket_explosion", "expl_coopmission_skyboom", "Particle effect for the explosion (''-default)");
hCvarSentryControlMenu = CreateConVar("zp_weapon_sentry_control_menu", "10", "", 0, true, 0.0);
hCvarSentryControlUpgradeRatio = CreateConVar("zp_weapon_sentry_control_upgrade_ratio", "0.5", "", 0, true, 0.0);
hCvarSentryControlRefillRatio = CreateConVar("zp_weapon_sentry_control_refill_ratio", "0.1 ", "", 0, true, 0.0);
hCvarSentryDeathEffect = CreateConVar("zp_weapon_sentry_death", "explosion_hegrenade_interior", "Particle effect for the death (''-off)");
AutoExecConfig(true, "zp_weapon_dronegun", "sourcemod/zombieplague");
}
/**
* @brief Called after a library is added that the current plugin references optionally.
* A library is either a plugin name or extension name, as exposed via its include file.
**/
public void OnLibraryAdded(const char[] sLibrary)
{
if (!strcmp(sLibrary, "zombieplague", false))
{
GameData hConfig = LoadGameConfigFile("plugin.zombieplague");
if (!hConfig)
{
SetFailState("Failed to load zombieplague gamedata.");
return;
}
if ((gPlatform = view_as<EngineOS>(hConfig.GetOffset("OS"))) == OS_Unknown) SetFailState("Failed to get offset: \"OS\"");
if ((Animating_StudioHdr = hConfig.GetOffset("CBaseAnimating::StudioHdr")) == -1) SetFailState("Failed to get offset: \"CBaseAnimating::StudioHdr\"");
int iOffset_hLightingOrigin;
if ((iOffset_hLightingOrigin = FindSendPropInfo("CBaseAnimating", "m_hLightingOrigin")) < 1) SetFailState("Failed to find send prop: \"m_hLightingOrigin\"");
Animating_StudioHdr += iOffset_hLightingOrigin;
delete hConfig;
/*__________________________________________________________________________________________________*/
hConfig = LoadGameConfigFile("plugin.turret");
if (!hConfig)
{
SetFailState("Failed to load turret gamedata.");
return;
}
/*_________________________________________________________________________________________________________________________________________*/
{
StartPrepSDKCall(SDKCall_Entity);
PrepSDKCall_SetFromConf(hConfig, SDKConf_Signature, "CBaseAnimating::LookupPoseParameter");
PrepSDKCall_AddParameter(SDKType_PlainOldData, SDKPass_Plain);
PrepSDKCall_AddParameter(SDKType_String, SDKPass_Pointer);
PrepSDKCall_SetReturnInfo(SDKType_PlainOldData, SDKPass_Plain);
if ((hSDKCallLookupPoseParameter = EndPrepSDKCall()) == null) SetFailState("Failed to load SDK call \"CBaseAnimating::LookupPoseParameter\". Update signature in \"plugin.turret\"");
}
/*__________________________________________________________________________________________________*/
{
StartPrepSDKCall(gPlatform == OS_Windows ? SDKCall_Entity : SDKCall_Raw);
PrepSDKCall_SetFromConf(hConfig, SDKConf_Signature, "CBaseAnimating::LookupSequence");
PrepSDKCall_AddParameter(SDKType_String, SDKPass_Pointer);
PrepSDKCall_SetReturnInfo(SDKType_PlainOldData, SDKPass_Plain);
if ((hSDKCallLookupSequence = EndPrepSDKCall()) == null) SetFailState("Failed to load SDK call \"CBaseAnimating::LookupSequence\". Update signature in \"plugin.turret\"");
}
/*__________________________________________________________________________________________________*/
if ((AnimatingOverlay_Count = hConfig.GetOffset("CBaseAnimatingOverlay::Count")) == -1) SetFailState("Failed to get offset: \"CBaseAnimatingOverlay::Count\". Update offset in \"plugin.turret\"");
/*__________________________________________________________________________________________________*/
{
StartPrepSDKCall(SDKCall_Entity);
PrepSDKCall_SetFromConf(hConfig, SDKConf_Signature, "CBaseAnimatingOverlay::StudioFrameAdvance");
if ((hSDKCallStudioFrameAdvance = EndPrepSDKCall()) == null) SetFailState("Failed to load SDK call \"CBaseAnimatingOverlay::StudioFrameAdvance\". Update signature in \"plugin.turret\"");
}
/*__________________________________________________________________________________________________*/
{
StartPrepSDKCall(SDKCall_Entity);
PrepSDKCall_SetFromConf(hConfig, SDKConf_Signature, "CBaseAnimatingOverlay::AddLayeredSequence");
PrepSDKCall_AddParameter(SDKType_PlainOldData, SDKPass_Plain);
PrepSDKCall_AddParameter(SDKType_PlainOldData, SDKPass_Plain);
PrepSDKCall_SetReturnInfo(SDKType_PlainOldData, SDKPass_Plain);
if ((hSDKCallAddLayeredSequence = EndPrepSDKCall()) == null) SetFailState("Failed to load SDK call \"CBaseAnimatingOverlay::AddLayeredSequence\". Update signature in \"plugin.turret\"");
}
/*__________________________________________________________________________________________________*/
delete hConfig;
LoadTranslations("zombieplague.phrases");
LoadTranslations("turret.phrases");
if (ZP_IsMapLoaded())
{
ZP_OnEngineExecute();
}
}
}
/**
* @brief Called after a zombie core is loaded.
**/
public void ZP_OnEngineExecute()
{
gWeapon = ZP_GetWeaponNameID("turret");
gItem = ZP_GetExtraItemNameID("turret");
gSoundShoot = ZP_GetSoundKeyID("turret_sounds");
if (gSoundShoot == -1) SetFailState("[ZP] Custom sound key ID from name : \"turret_sounds\" wasn't find");
gSoundUpgrade = ZP_GetSoundKeyID("turret_up_sounds");
if (gSoundUpgrade == -1) SetFailState("[ZP] Custom sound key ID from name : \"turret_up_sounds\" wasn't find");
gKnockback = FindConVar("zp_knockback");
if (gKnockback == null) SetFailState("[ZP] Custom cvar key ID from name : \"zp_knockback\" wasn't find");
}
/**
* @brief The map is starting.
**/
public void OnMapStart()
{
gTrail = PrecacheModel("materials/sprites/laserbeam.vmt", true);
PrecacheModel("materials/sprites/xfireball3.vmt", true); /// for env_explosion
PrecacheModel("models/props_office/file_cabinet_03.mdl", true);
PrecacheModel("models/weapons/w_eq_fraggrenade_dropped.mdl", true);
PrecacheSound("survival/turret_death_01.wav", true);
PrecacheSound("survival/turret_takesdamage_01.wav", true);
PrecacheSound("survival/turret_takesdamage_02.wav", true);
PrecacheSound("survival/turret_takesdamage_03.wav", true);
gDecal[0] = PrecacheDecal("decals/concrete/shot1.vmt", true);
gDecal[1] = PrecacheDecal("decals/concrete/shot2.vmt", true);
gDecal[2] = PrecacheDecal("decals/concrete/shot3.vmt", true);
gDecal[3] = PrecacheDecal("decals/concrete/shot4.vmt", true);
gDecal[4] = PrecacheDecal("decals/concrete/shot5.vmt", true);
}
//*********************************************************************
//* Don't modify the code below this line unless *
//* you know _exactly_ what you are doing!!! *
//*********************************************************************
#define ANIM_LAYER_ACTIVE 0x0001
#define ANIM_LAYER_AUTOKILL 0x0002
#define ANIM_LAYER_KILLME 0x0004
#define ANIM_LAYER_DONTRESTORE 0x0008
#define ANIM_LAYER_CHECKACCESS 0x0010
#define ANIM_LAYER_DYING 0x0020
#define ANIM_LAYER_NOEVENTS 0x0040
enum //CAnimationLayer
{
m_fFlags = 0,
m_bSequenceFinished = 4,
m_bLooping = 5,
m_nSequence = 8,
m_flCycle = 12,
m_flPlaybackRate = 16,
m_flPrevCycle = 20,
m_flWeight = 24,
m_flWeightDeltaRate = 28,
m_flBlendIn = 32,
m_flBlendOut = 36,
m_flKillRate = 40,
m_flKillDelay = 44,
m_flLayerAnimtime = 48,
m_flLayerFadeOuttime = 52,
/*
??? = 56,
??? = 60,
??? = 64,
*/
m_nActivity = 68,
m_nPriority = 72,
m_nOrder = 76,
m_flLastEventCheck = 80,
m_flLastAccess = 84,
m_pOwnerEntity = 88,
CAnimationLayer_Size = 92
};
methodmap CAnimationOverlay
{
public CAnimationOverlay(int address)
{
return view_as<CAnimationOverlay>(address);
}
property Address Address
{
public get()
{
return view_as<Address>(this);
}
}
property bool isNull
{
public get()
{
return this.Address == Address_Null;
}
}
public any Get(int iOffset, int iLayer)
{
return LoadFromAddress(this.Address + view_as<Address>(iOffset + CAnimationLayer_Size * iLayer), NumberType_Int32);
}
public void Set(int iOffset, int iLayer, any iValue)
{
StoreToAddress(this.Address + view_as<Address>(iOffset + CAnimationLayer_Size * iLayer), iValue, NumberType_Int32);
}
public bool IsActive(int iLayer) { return ((this.Get(m_fFlags, iLayer) & ANIM_LAYER_ACTIVE) != 0); }
public bool IsAutokill(int iLayer) { return ((this.Get(m_fFlags, iLayer) & ANIM_LAYER_AUTOKILL) != 0); }
public bool IsKillMe(int iLayer) { return ((this.Get(m_fFlags, iLayer) & ANIM_LAYER_KILLME) != 0); }
public bool IsDying(int iLayer) { return ((this.Get(m_fFlags, iLayer) & ANIM_LAYER_DYING) != 0); }
public bool NoEvents(int iLayer) { return ((this.Get(m_fFlags, iLayer) & ANIM_LAYER_NOEVENTS) != 0); }
public void KillMe(int iLayer) { int iFlags = this.Get(m_fFlags, iLayer); this.Set(m_fFlags, iLayer, (iFlags |= ANIM_LAYER_KILLME)); }
public void AutoKill(int iLayer) { int iFlags = this.Get(m_fFlags, iLayer); this.Set(m_fFlags, iLayer, (iFlags |= ANIM_LAYER_AUTOKILL)); }
public void Dying(int iLayer) { int iFlags = this.Get(m_fFlags, iLayer); this.Set(m_fFlags, iLayer, (iFlags |= ANIM_LAYER_DYING)); }
public void Dead(int iLayer) { int iFlags = this.Get(m_fFlags, iLayer); this.Set(m_fFlags, iLayer, (iFlags &= ~ANIM_LAYER_DYING)); }
public void Loop(int iLayer) { int iFlags = this.Get(m_fFlags, iLayer); this.Set(m_fFlags, iLayer, (iFlags &= ~ANIM_LAYER_AUTOKILL)); }
public void RemoveLayer(int iLayer, float flKillRate, float flKillDelay)
{
this.Set(m_flKillRate, iLayer, flKillRate > 0.0 ? this.Get(m_flWeight, iLayer) / flKillRate : 100.0);
this.Set(m_flKillDelay, iLayer, flKillDelay);
this.KillMe(iLayer);
}
public void SetLayerAutokill(int iLayer, bool bAutokill)
{
if (bAutokill)
{
this.AutoKill(iLayer);
}
else
{
this.Loop(iLayer);
}
}
public bool IsAlive(int iLayer) { int iFlags = this.Get(m_fFlags, iLayer); return (((iFlags & ANIM_LAYER_ACTIVE) != 0) || ((iFlags & ANIM_LAYER_KILLME) == 0)); }
public int GetLayerSequence(int iLayer) { return (this.Get(m_nSequence, iLayer)); }
};
methodmap SentryGun /** Regards to Pelipoika **/
{
public SentryGun(int owner, const float vPosition[3], const float vAngle[3], int iHealth, int iAmmo, int iRocket, int iSkin, int iLevel)
{
int entity = UTIL_CreateMonster("turret_npc", vPosition, vAngle, SENTRY_MODEL_LEVEL_1, NPC_GAG | NPC_WAITFORSCRIPT | NPC_DONTDROPWEAPONS | NPC_IGNOREPLAYERPUSH);
if (entity != -1)
{
static float vGoal[3]; static float vCurrent[3];
int iRightBound = RoundToNearest(AngleMod(vAngle[1] - 50.0));
int iLeftBound = RoundToNearest(AngleMod(vAngle[1] + 50.0));
if (iRightBound > iLeftBound)
{
iRightBound = iLeftBound;
iLeftBound = RoundToNearest(AngleMod(vAngle[1] - 50.0));
}
SetEntProp(entity, Prop_Data, "m_iSpeedModSpeed", iRightBound);
SetEntProp(entity, Prop_Data, "m_iSpeedModRadius", iLeftBound);
vGoal[1] = float(iRightBound);
vGoal[0] = vCurrent[0] = 0.0;
vCurrent[1] = AngleMod(vAngle[1]);
SetEntPropVector(entity, Prop_Data, "m_vecLastPosition", vCurrent);
SetEntPropVector(entity, Prop_Data, "m_vecStoredPathGoal", vGoal);
SetEntProp(entity, Prop_Data, "m_bSpeedModActive", true);
SetEntProp(entity, Prop_Data, "m_bIsAutoaimTarget", true);
SetEntProp(entity, Prop_Data, "m_iInteractionState", SENTRY_STATE_SEARCHING);
/**__________________________________________________________**/
SetEntityMoveType(entity, MOVETYPE_NONE);
/*SetEntProp(entity, Prop_Data, "m_CollisionGroup", COLLISION_GROUP_NONE);
SetEntProp(entity, Prop_Data, "m_usSolidFlags", FSOLID_NOT_SOLID);
SetEntProp(entity, Prop_Data, "m_nSolidType", SOLID_NONE);*/
SetEntProp(entity, Prop_Data, "m_takedamage", DAMAGE_NO);
SetEntProp(entity, Prop_Data, "m_iHealth", iHealth);
SetEntProp(entity, Prop_Data, "m_iMaxHealth", iHealth);
SetEntProp(entity, Prop_Send, "m_nSkin", iSkin);
SetEntProp(entity, Prop_Send, "m_nBody", 2);
SetEntPropEnt(entity, Prop_Data, "m_hOwnerEntity", owner);
SetEntProp(entity, Prop_Data, "m_iTeamNum", ZP_IsPlayerZombie(owner) ? TEAM_ZOMBIE : TEAM_HUMAN);
SetEntProp(entity, Prop_Data, "m_iAmmo", iAmmo);
SetEntProp(entity, Prop_Data, "m_iMySquadSlot", iRocket);
SetEntProp(entity, Prop_Data, "m_iHammerID", iLevel);
SetEntProp(entity, Prop_Data, "m_iDesiredWeaponState", SENTRY_MODE_NORMAL);
SetEntPropFloat(entity, Prop_Data, "m_flSoundWaitTime", 0.0);
UTIL_SetRenderColor(entity, Color_Alpha, 0);
//AcceptEntityInput(entity, "DisableDraw");
AcceptEntityInput(entity, "DisableShadow");
AcceptEntityInput(entity, "DisableReceivingFlashlight");
//vPosition[2] -= 35.0;
int upgrade = UTIL_CreateDynamic("upgrade", vPosition, vAngle, SENTRY_MODEL_LEVEL_1_UPGRADE, "build");
if (upgrade != -1)
{
SetVariantString("!activator");
AcceptEntityInput(upgrade, "SetParent", entity, upgrade);
SetEntProp(upgrade, Prop_Send, "m_nSkin", iSkin);
SetEntProp(upgrade, Prop_Send, "m_nBody", 2);
SetEntPropEnt(upgrade, Prop_Data, "m_hOwnerEntity", entity);
ZP_EmitSoundToAll(gSoundUpgrade, 1, upgrade, SNDCHAN_STATIC);
CreateTimer(5.0, SentryActivateHook, EntIndexToEntRef(upgrade), TIMER_FLAG_NO_MAPCHANGE);
}
int physics = UTIL_CreatePhysics("turret_body", vPosition, vAngle, "models/props_office/file_cabinet_03.mdl", PHYS_FORCESERVERSIDE | PHYS_MOTIONDISABLED | PHYS_NOTAFFECTBYROTOR);
if (physics != -1)
{
SetVariantString("!activator");
AcceptEntityInput(physics, "SetParent", entity, physics);
SetEntityMoveType(physics, MOVETYPE_NONE);
SetEntProp(physics, Prop_Data, "m_CollisionGroup", COLLISION_GROUP_PLAYER);
SetEntProp(physics, Prop_Data, "m_nSolidType", SOLID_VPHYSICS);
SetEntProp(physics, Prop_Data, "m_iTeamNum", GetEntProp(entity, Prop_Data, "m_iTeamNum"));
SetEntProp(physics, Prop_Data, "m_iHammerID", -1);
SetEntPropEnt(physics, Prop_Data, "m_hOwnerEntity", entity);
SetEntPropEnt(entity, Prop_Data, "m_hInteractionPartner", physics);
AcceptEntityInput(physics, "DisableDraw");
AcceptEntityInput(physics, "DisableShadow");
if (iHealth > 0)
{
SetEntProp(physics, Prop_Data, "m_takedamage", DAMAGE_EVENTS_ONLY);
SetEntProp(physics, Prop_Data, "m_iHealth", iHealth);
SetEntProp(physics, Prop_Data, "m_iMaxHealth", iHealth);
SDKHook(physics, SDKHook_OnTakeDamage, SentryDamageHook);
}
else
{
SetEntProp(physics, Prop_Data, "m_takedamage", DAMAGE_NO);
}
}
//SDKHook(entity, SDKHook_Touch, SentryTouchHook);
}
return view_as<SentryGun>(entity);
}
/*__________________________________________________________________________________________________*/
property int Index
{
public get()
{
return view_as<int>(this);
}
}
property float NextSound
{
public get()
{
return GetEntPropFloat(this.Index, Prop_Data, "m_flSoundWaitTime");
}
public set(float flDelay)
{
SetEntPropFloat(this.Index, Prop_Data, "m_flSoundWaitTime", flDelay);
}
}
property float NextAttack
{
public get()
{
return GetEntPropFloat(this.Index, Prop_Data, "m_flLastAttackTime");
}
public set(float flDelay)
{
SetEntPropFloat(this.Index, Prop_Data, "m_flLastAttackTime", flDelay);
}
}
property float NextRocket
{
public get()
{
return GetEntPropFloat(this.Index, Prop_Data, "m_flNextWeaponSearchTime");
}
public set(float flDelay)
{
SetEntPropFloat(this.Index, Prop_Data, "m_flNextWeaponSearchTime", flDelay);
}
}
property float TurnRate
{
public get()
{
return GetEntPropFloat(this.Index, Prop_Data, "m_flNextDecisionTime");
}
public set(float flRate)
{
SetEntPropFloat(this.Index, Prop_Data, "m_flNextDecisionTime", flRate);
}
}
property int Enemy
{
public get()
{
return GetEntPropEnt(this.Index, Prop_Data, "m_hEnemy");
}
public set(int entity)
{
SetEntPropEnt(this.Index, Prop_Data, "m_hEnemy", entity);
}
}
property int Skin
{
public get()
{
return GetEntProp(this.Index, Prop_Send, "m_nSkin");
}
public set(int iSkin)
{
SetEntPropEnt(this.Index, Prop_Send, "m_nSkin", iSkin);
}
}
property int Team
{
public get()
{
return GetEntProp(this.Index, Prop_Data, "m_iTeamNum");
}
public set(int iTeam)
{
SetEntPropEnt(this.Index, Prop_Data, "m_iTeamNum", iTeam);
}
}
property int Health
{
public get()
{
return GetEntProp(this.Index, Prop_Data, "m_iHealth");
}
public set(int iHealth)
{
SetEntProp(this.Index, Prop_Data, "m_iHealth", iHealth);
}
}
property int State
{
public get()
{
return GetEntProp(this.Index, Prop_Data, "m_iInteractionState");
}
public set(int iState)
{
SetEntProp(this.Index, Prop_Data, "m_iInteractionState", iState);
}
}
property int RightBound
{
public get()
{
return GetEntProp(this.Index, Prop_Data, "m_iSpeedModSpeed");
}
public set(int iBound)
{
SetEntProp(this.Index, Prop_Data, "m_iSpeedModSpeed", iBound);
}
}
property int LeftBound
{
public get()
{
return GetEntProp(this.Index, Prop_Data, "m_iSpeedModRadius");
}
public set(int iBound)
{
SetEntProp(this.Index, Prop_Data, "m_iSpeedModRadius", iBound);
}
}
property bool TurningRight
{
public get()
{
return view_as<bool>(GetEntProp(this.Index, Prop_Data, "m_bSpeedModActive"));
}
public set(bool bState)
{
SetEntProp(this.Index, Prop_Data, "m_bSpeedModActive", bState);
}
}
property int Ammo
{
public get()
{
return GetEntProp(this.Index, Prop_Data, "m_iAmmo");
}
public set(int iAmmo)
{
SetEntProp(this.Index, Prop_Data, "m_iAmmo", iAmmo);
}
}
property int Body
{
public get()
{
return GetEntProp(this.Index, Prop_Send, "m_nBody");
}
public set(int iBody)
{
SetEntProp(this.Index, Prop_Send, "m_nBody", iBody);
}
}
property int Rockets
{
public get()
{
return GetEntProp(this.Index, Prop_Data, "m_iMySquadSlot");
}
public set(int iRocket)
{
SetEntProp(this.Index, Prop_Data, "m_iMySquadSlot", iRocket);
}
}
property bool Lock
{
public get()
{
return view_as<bool>(GetEntProp(this.Index, Prop_Data, "m_bIsAutoaimTarget"));
}
public set(bool bLock)
{
SetEntProp(this.Index, Prop_Data, "m_bIsAutoaimTarget", bLock);
}
}
property int Owner
{
public get()
{
return GetEntPropEnt(this.Index, Prop_Data, "m_hOwnerEntity");
}
public set(int entity)
{
SetEntPropEnt(this.Index, Prop_Data, "m_hOwnerEntity", entity);
}
}
property int UpgradeState
{
public get()
{
return GetEntProp(this.Index, Prop_Data, "m_iHammerID");
}
public set(int iLevel)
{
SetEntProp(this.Index, Prop_Data, "m_iHammerID", iLevel);
}
}
property int UpgradeLevel
{
public get()
{
return GetEntProp(this.Index, Prop_Data, "m_iDesiredWeaponState");
}
public set(int iLevel)
{
SetEntProp(this.Index, Prop_Data, "m_iDesiredWeaponState", iLevel);
}
}
property int Physics
{
public get()
{
return GetEntPropEnt(this.Index, Prop_Data, "m_hInteractionPartner");
}
public set(int physics)
{
SetEntPropEnt(this.Index, Prop_Data, "m_hInteractionPartner", physics);
}
}
/*__________________________________________________________________________________________________*/
public void GetCurAngles(float vOutput[3])
{
GetEntPropVector(this.Index, Prop_Data, "m_vecLastPosition", vOutput);
}
public void SetCurAngles(const float vInput[3])
{
SetEntPropVector(this.Index, Prop_Data, "m_vecLastPosition", vInput);
}
public void GetGoalAngles(float vOutput[3])
{
GetEntPropVector(this.Index, Prop_Data, "m_vecStoredPathGoal", vOutput);
}
public void SetGoalAngles(const float vInput[3])
{
SetEntPropVector(this.Index, Prop_Data, "m_vecStoredPathGoal", vInput);
}
public void GetAbsAngles(float vOutput[3])
{
GetEntPropVector(this.Index, Prop_Data, "m_angAbsRotation", vOutput);
}
public void GetGunPosition(float vOutput[3])
{
GetAbsOrigin(this.Index, vOutput);
switch (this.UpgradeLevel)
{
case SENTRY_MODE_NORMAL : vOutput[2] += SENTRY_EYE_OFFSET_LEVEL_1;
case SENTRY_MODE_AGRESSIVE : vOutput[2] += SENTRY_EYE_OFFSET_LEVEL_2;
case SENTRY_MODE_ROCKET : vOutput[2] += SENTRY_EYE_OFFSET_LEVEL_3;
}
}
public void GetLauncherPosition(float vOutput[3])
{
GetAbsOrigin(this.Index, vOutput);
vOutput[2] += SENTRY_SHOOTER_OFFSET_LEVEL;
}
/*__________________________________________________________________________________________________*/
public CAnimationOverlay CBaseAnimatingOverlay()
{
static int iOffset;
if (!iOffset) iOffset = FindDataMapInfo(this.Index, "m_AnimOverlay");
return CAnimationOverlay(GetEntData(this.Index, iOffset));
}
public int AnimOverlayCount()
{
static int iOffset;
if (!iOffset) iOffset = FindDataMapInfo(this.Index, "m_AnimOverlay") + AnimatingOverlay_Count;
return GetEntData(this.Index, iOffset);
}
public void SetPoseParameter(int iParameter, float flStart, float flEnd, float flValue)
{
float flCtl = (flValue - flStart) / (flEnd - flStart);
if (flCtl < 0) flCtl = 0.0;
if (flCtl > 1) flCtl = 1.0;
SetEntPropFloat(this.Index, Prop_Send, "m_flPoseParameter", flCtl, iParameter);
}
/*__________________________________________________________________________________________________*/
public int FindGestureLayer(const char[] sAnim)
{
int iSequence = this.LookupSequence(sAnim);
if (iSequence < 0)
{
return -1;
}
CAnimationOverlay pOverlay = this.CBaseAnimatingOverlay();
if (pOverlay.isNull)
{
return -1;
}
int iCount = this.AnimOverlayCount();
for (int i = 0; i < iCount; i++)
{
if (!pOverlay.IsAlive(i))
{
continue;
}
if (pOverlay.GetLayerSequence(i) == iSequence)
{
return i;
}
}
return -1;
}
public int AddGesture(const char[] sAnim, bool bAutoKill = true)
{
int iSequence = this.LookupSequence(sAnim);
if (iSequence < 0)
{
return -1;
}
CAnimationOverlay pOverlay = this.CBaseAnimatingOverlay();