-
Notifications
You must be signed in to change notification settings - Fork 1
/
api_custom_weapons.sma
2623 lines (2033 loc) · 76.4 KB
/
api_custom_weapons.sma
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 <amxmodx>
#include <hamsandwich>
#include <fakemeta>
#include <engine>
#include <xs>
#include <reapi>
#include <api_custom_weapons>
#define PLUGIN "[API] Custom Weapons"
#define VERSION "0.7.9"
#define AUTHOR "Hedgehog Fog"
#define WALL_PUFF_SPRITE "sprites/wall_puff1.spr"
#define VEC_DUCK_HULL_MIN Float:{-16.0, -16.0, -18.0}
#define VEC_DUCK_HULL_MAX Float:{16.0, 16.0, 18.0}
#define IS_PLAYER(%1) (%1 > 0 && %1 <= MaxClients)
#define TOKEN 743647146
enum _:WeaponListMessage {
WL_WeaponName[32],
WL_PrimaryAmmoType,
WL_PrimaryAmmoMaxAmount,
WL_SecondaryAmmoType,
WL_SecondaryAmmoMaxAmount,
WL_SlotId,
WL_NumberInSlot,
WL_WeaponId,
WL_Flags
}
enum _:Function {
Function_PluginId,
Function_FunctionId
}
new const g_rgszWeaponNames[CSW_LAST_WEAPON + 1][] = {
"",
"weapon_p228",
"weapon_shield",
"weapon_scout",
"weapon_hegrenade",
"weapon_xm1014",
"weapon_c4",
"weapon_mac10",
"weapon_aug",
"weapon_smokegrenade",
"weapon_elite",
"weapon_fiveseven",
"weapon_ump45",
"weapon_sg550",
"weapon_galil",
"weapon_famas",
"weapon_usp",
"weapon_glock18",
"weapon_awp",
"weapon_mp5navy",
"weapon_m249",
"weapon_m3",
"weapon_m4a1",
"weapon_tmp",
"weapon_g3sg1",
"weapon_flashbang",
"weapon_deagle",
"weapon_sg552",
"weapon_ak47",
"weapon_knife",
"weapon_p90"
};
new gmsgWeaponList;
new gmsgDeathMsg;
new g_iszWeaponNames[CSW_LAST_WEAPON + 1];
new bool:g_bWeaponHooks[CSW_LAST_WEAPON + 1];
new g_weaponListDefaults[CSW_LAST_WEAPON + 1][WeaponListMessage];
new Array:g_rgWeapons[CW_Data];
new Trie:g_rgWeaponsMap;
new g_iWeaponCount;
new Float:g_flNextPredictionUpdate[MAX_PLAYERS + 1];
new bool:g_bKnifeHolstered[MAX_PLAYERS + 1];
new g_iszWeaponBox;
new g_pNewWeaponboxEnt = -1;
new g_pKillerItem = -1;
new bool:g_bSupercede;
new bool:g_bPrecache;
new Array:g_irgDecals;
public plugin_precache() {
g_bPrecache = true;
AllocateStrings();
InitStorages();
register_forward(FM_UpdateClientData, "OnUpdateClientData_Post", 1);
register_forward(FM_PrecacheEvent, "OnPrecacheEvent_Post", 1);
register_forward(FM_SetModel, "OnSetModel_Post", 1);
register_forward(FM_DecalIndex, "OnDecalIndex_Post", 1);
RegisterHam(Ham_Spawn, "weaponbox", "OnWeaponboxSpawn", .Post = 0);
RegisterHamPlayer(Ham_Player_PreThink, "OnPlayerPreThink_Post", .Post = 1);
RegisterHamPlayer(Ham_TakeDamage, "OnPlayerTakeDamage", .Post = 0);
RegisterHamPlayer(Ham_TakeDamage, "OnPlayerTakeDamage_Post", .Post = 1);
precache_model(WALL_PUFF_SPRITE);
}
public plugin_init() {
g_bPrecache = false;
register_plugin(PLUGIN, VERSION, AUTHOR);
gmsgWeaponList = get_user_msgid("WeaponList");
gmsgDeathMsg = get_user_msgid("DeathMsg");
register_message(gmsgWeaponList, "OnMessage_WeaponList");
register_message(gmsgDeathMsg, "OnMessage_DeathMsg");
}
public plugin_cfg() {
InitWeaponHooks();
}
public plugin_natives() {
register_library("api_custom_weapons");
register_native("CW_Register", "Native_Register");
register_native("CW_GetHandlerByEntity", "Native_GetHandlerByEntity");
register_native("CW_GetHandler", "Native_GetHandler");
register_native("CW_GetWeaponData", "Native_GetWeaponData");
register_native("CW_GetWeaponStringData", "Native_GetWeaponStringData");
register_native("CW_GiveWeapon", "Native_GiveWeapon");
register_native("CW_HasWeapon", "Native_HasWeapon");
register_native("CW_SpawnWeapon", "Native_SpawnWeapon");
register_native("CW_SpawnWeaponBox", "Native_SpawnWeaponBox");
register_native("CW_Deploy", "Native_Deploy");
register_native("CW_Holster", "Native_Holster");
register_native("CW_ItemPostFrame", "Native_ItemPostFrame");
register_native("CW_Idle", "Native_Idle");
register_native("CW_Reload", "Native_Reload");
register_native("CW_PrimaryAttack", "Native_PrimaryAttack");
register_native("CW_SecondaryAttack", "Native_SecondaryAttack");
register_native("CW_FireBulletsPlayer", "Native_FireBulletsPlayer");
register_native("CW_EjectWeaponBrass", "Native_EjectWeaponBrass");
register_native("CW_PlayAnimation", "Native_PlayAnimation");
register_native("CW_GetPlayer", "Native_GetPlayer");
register_native("CW_DefaultDeploy", "Native_DefaultDeploy");
register_native("CW_DefaultShot", "Native_DefaultShot");
register_native("CW_DefaultShotgunShot", "Native_DefaultShotgunShot");
register_native("CW_DefaultSwing", "Native_DefaultSwing");
register_native("CW_DefaultReload", "Native_DefaultReload");
register_native("CW_DefaultShotgunReload", "Native_DefaultShotgunReload");
register_native("CW_DefaultShotgunIdle", "Native_DefaultShotgunIdle");
register_native("CW_GrenadeDetonate", "Native_GrenadeDetonate");
register_native("CW_GrenadeSmoke", "Native_GrenadeSmoke");
register_native("CW_RemovePlayerItem", "Native_RemovePlayerItem");
register_native("CW_Bind", "Native_Bind");
}
public plugin_end() {
DestroyStorages();
}
// ANCHOR: Natives
public Native_Bind(iPluginId, iArgc) {
new CW:iHandler = CW:get_param(1);
new iBinding = get_param(2);
new szFunctionName[32];
get_string(3, szFunctionName, charsmax(szFunctionName));
Bind(iHandler, iBinding, iPluginId, get_func_id(szFunctionName, iPluginId));
}
public CW:Native_GetHandlerByEntity(iPluginId, iArgc) {
new pEntity = get_param(1);
return GetHandlerByEntity(pEntity);
}
public CW:Native_GetHandler(iPluginId, iArgc) {
static szName[64];
get_string(1, szName, charsmax(szName));
return GetHandler(szName);
}
public any:Native_GetWeaponData(iPluginId, iArgc) {
new CW:iHandler = CW:get_param(1);
new CW_Data:iParam = CW_Data:get_param(2);
return GetData(iHandler, iParam);
}
public Native_GetWeaponStringData(iPluginId, iArgc) {
new CW:iHandler = CW:get_param(1);
new CW_Data:iParam = CW_Data:get_param(2);
static szValue[128];
GetStringData(iHandler, iParam, szValue, charsmax(szValue));
new iLen = get_param(4);
set_string(3, szValue, iLen);
}
public CW:Native_Register(iPluginId, iArgc) {
new szName[64];
get_string(1, szName, charsmax(szName));
new iWeaponId = get_param(2);
new iClipSize = get_param(3);
new iPrimaryAmmoType = get_param(4);
new iPrimaryAmmoMaxAmount = get_param(5);
new iSecondaryAmmoType = get_param(6);
new iSecondaryAmmoMaxAmount = get_param(7);
new iSlotId = get_param(8);
new iPosition = get_param(9);
new iWeaponFlags = get_param(10);
new szIcon[16];
get_string(11, szIcon, charsmax(szIcon));
new CW_Flags:iFlags = CW_Flags:get_param(12);
return RegisterWeapon(iPluginId, szName, iWeaponId, iClipSize, iPrimaryAmmoType, iPrimaryAmmoMaxAmount, iSecondaryAmmoType, iSecondaryAmmoMaxAmount, iSlotId, iPosition, iWeaponFlags, szIcon, iFlags);
}
public Native_GiveWeapon(iPluginId, iArgc) {
new pPlayer = get_param(1);
static szWeapon[64];
get_string(2, szWeapon, charsmax(szWeapon));
new CW:iHandler;
if (TrieGetCell(g_rgWeaponsMap, szWeapon, iHandler)) {
GiveWeapon(pPlayer, iHandler);
}
}
public bool:Native_HasWeapon(iPluginId, iArgc) {
new pPlayer = get_param(1);
static szWeapon[64];
get_string(2, szWeapon, charsmax(szWeapon));
new CW:iHandler;
if (TrieGetCell(g_rgWeaponsMap, szWeapon, iHandler)) {
return HasWeapon(pPlayer, iHandler);
}
return false;
}
public Native_SpawnWeapon(iPluginId, iArgc) {
new CW:iHandler = CW:get_param(1);
return SpawnWeapon(iHandler);
}
public Native_SpawnWeaponBox(iPluginId, iArgc) {
new CW:iHandler = CW:get_param(1);
return SpawnWeaponBox(iHandler);
}
public bool:Native_DefaultDeploy(iPluginId, iArgc) {
new pWeapon = get_param(1);
static szViewModel[64];
get_string(2, szViewModel, charsmax(szViewModel));
static szWeaponModel[64];
get_string(3, szWeaponModel, charsmax(szWeaponModel));
new iAnim = get_param(4);
static szAnimExt[16];
get_string(5, szAnimExt, charsmax(szAnimExt));
return DefaultDeploy(pWeapon, szViewModel, szWeaponModel, iAnim, szAnimExt);
}
public Native_FireBulletsPlayer(iPluginId, iArgc) {
new pWeapon = get_param(1);
new iShots = get_param(2);
static Float:vecSrc[3];
get_array_f(3, vecSrc, sizeof(vecSrc));
static Float:vecDirShooting[3];
get_array_f(4, vecDirShooting, sizeof(vecDirShooting));
static Float:vecSpread[3];
get_array_f(5, vecSpread, sizeof(vecSpread));
new Float:flDistance = get_param_f(6);
new Float:flDamage = get_param_f(7);
new Float:flRangeModifier = get_param_f(8);
new pevAttacker = get_param(9);
static Float:vecOut[3];
FireBulletsPlayer(pWeapon, iShots, vecSrc, vecDirShooting, vecSpread, flDistance, flDamage, flRangeModifier, pevAttacker, vecOut);
set_array_f(10, vecOut, sizeof(vecOut));
}
public bool:Native_EjectWeaponBrass(iPluginId, iArgc) {
new pItem = get_param(1);
new iModelIndex = get_param(2);
new iSoundType = get_param(3);
return EjectWeaponBrass(pItem, iModelIndex, iSoundType);
}
public bool:Native_DefaultShot(iPluginId, iArgc) {
new pItem = get_param(1);
new Float:flDamage = get_param_f(2);
new Float:flRangeModifier = get_param_f(3);
new Float:flRate = get_param_f(4);
static Float:vecSpread[3];
get_array_f(5, vecSpread, sizeof(vecSpread));
new iShots = get_param(6);
new Float:flDistance = get_param_f(7);
return DefaultShot(pItem, flDamage, flRangeModifier, flRate, vecSpread, iShots, flDistance);
}
public bool:Native_DefaultShotgunShot(iPluginId, iArgc) {
new pItem = get_param(1);
new Float:flDamage = get_param_f(2);
new Float:flRangeModifier = get_param_f(3);
new Float:flRate = get_param_f(4);
new Float:flPumpDelay = get_param_f(5);
static Float:vecSpread[3];
get_array_f(6, vecSpread, sizeof(vecSpread));
new iShots = get_param(7);
new Float:flDistance = get_param_f(8);
return DefaultShotgunShot(pItem, flDamage, flRangeModifier, flRate, flPumpDelay, vecSpread, iShots, flDistance);
}
public Native_DefaultSwing(iPluginId, iArgc) {
new pItem = get_param(1);
new Float:flDamage = get_param_f(2);
new Float:flRate = get_param_f(3);
new Float:flDistance = get_param_f(4);
return DefaultSwing(pItem, flDamage, flRate, flDistance);
}
public Native_PlayAnimation(iPluginID, argc) {
new pItem = get_param(1);
new iSequence = get_param(2);
new Float:flDuration = get_param_f(3);
PlayWeaponAnim(pItem, iSequence, flDuration);
}
public Native_GetPlayer(iPluginID, argc) {
new pItem = get_param(1);
return GetPlayer(pItem);
}
public bool:Native_DefaultReload(iPluginId, iArgc) {
new pItem = get_param(1);
new iAnim = get_param(2);
new Float:flDelay = get_param_f(3);
return DefaultReload(pItem, iAnim, flDelay);
}
public bool:Native_DefaultShotgunReload(iPluginId, iArgc) {
new pItem = get_param(1);
new iStartAnim = get_param(2);
new iEndAnim = get_param(3);
new Float:flDelay = get_param_f(4);
new Float:flDuration = get_param_f(5);
return DefaultShotgunReload(pItem, iStartAnim, iEndAnim, flDelay, flDuration);
}
public bool:Native_DefaultShotgunIdle(iPluginId, iArgc) {
new pItem = get_param(1);
new iAnim = get_param(2);
new iReloadEndAnim = get_param(3);
new Float:flDuration = get_param_f(4);
new Float:flReloadEndDuration = get_param_f(5);
static szPumpSound[64];
get_string(6, szPumpSound, charsmax(szPumpSound));
return DefaultShotgunIdle(pItem, iAnim, iReloadEndAnim, flDuration, flReloadEndDuration, szPumpSound);
}
public Native_Deploy(iPluginId, iArgc) {
new pItem = get_param(1);
WeaponDeploy(pItem);
}
public Native_Holster(iPluginId, iArgc) {
new pItem = get_param(1);
WeaponHolster(pItem);
}
public Native_ItemPostFrame(iPluginId, iArgc) {
new pItem = get_param(1);
ItemPostFrame(pItem);
}
public Native_Idle(iPluginId, iArgc) {
new pItem = get_param(1);
WeaponIdle(pItem);
}
public Native_Reload(iPluginId, iArgc) {
new pItem = get_param(1);
Reload(pItem);
}
public Native_PrimaryAttack(iPluginId, iArgc) {
new pItem = get_param(1);
PrimaryAttack(pItem);
}
public Native_SecondaryAttack(iPluginId, iArgc) {
new pItem = get_param(1);
SecondaryAttack(pItem);
}
public Native_GrenadeDetonate(iPluginId, iArgc) {
new pGrenade = get_param(1);
new Float:flRadius = get_param_f(2);
new Float:flMagnitude = get_param_f(3);
GrenadeDetonate(pGrenade, flRadius, flMagnitude);
}
public Native_GrenadeSmoke(iPluginId, iArgc) {
new pGrenade = get_param(1);
GrenadeSmoke(pGrenade);
}
public Native_RemovePlayerItem(iPluginId, iArgc) {
new pItem = get_param(1);
RemovePlayerItem(pItem);
}
// ANCHOR: Forwards
public client_connect(pPlayer) {
g_bKnifeHolstered[pPlayer] = true;
}
public client_disconnected(pPlayer) {
SetWeaponPrediction(pPlayer, true);
}
// ANCHOR: Hook Callbacks
public OnItemDeploy(this) {
new CW:iHandler = GetHandlerByEntity(this);
if (iHandler == CW_INVALID_HANDLER) {
return HAM_IGNORED;
}
WeaponDeploy(this);
return HAM_SUPERCEDE;
}
public OnItemHolster(this) {
new pPlayer = GetPlayer(this);
g_bKnifeHolstered[pPlayer] = IsWeaponKnife(this);
new CW:iHandler = GetHandlerByEntity(this);
if (iHandler == CW_INVALID_HANDLER) {
return HAM_IGNORED;
}
WeaponHolster(this);
return HAM_SUPERCEDE;
}
public OnItemPostFrame(this) {
new CW:iHandler = GetHandlerByEntity(this);
if (iHandler == CW_INVALID_HANDLER) {
return HAM_IGNORED;
}
ItemPostFrame(this);
return HAM_SUPERCEDE;
}
public OnWeaponPrimaryAttack(this) {
new CW:iHandler = GetHandlerByEntity(this);
if (iHandler == CW_INVALID_HANDLER) {
return HAM_IGNORED;
}
g_bSupercede = GetHamReturnStatus() >= HAM_SUPERCEDE;
return HAM_SUPERCEDE;
}
public OnWeaponSecondaryAttack(this) {
new CW:iHandler = GetHandlerByEntity(this);
if (iHandler == CW_INVALID_HANDLER) {
return HAM_IGNORED;
}
g_bSupercede = GetHamReturnStatus() >= HAM_SUPERCEDE;
return HAM_SUPERCEDE;
}
public OnWeaponReload(this) {
new CW:iHandler = GetHandlerByEntity(this);
if (iHandler == CW_INVALID_HANDLER) {
return HAM_IGNORED;
}
g_bSupercede = GetHamReturnStatus() >= HAM_SUPERCEDE;
return HAM_SUPERCEDE;
}
public OnWeaponIdle(this) {
new CW:iHandler = GetHandlerByEntity(this);
if (iHandler == CW_INVALID_HANDLER) {
return HAM_IGNORED;
}
g_bSupercede = GetHamReturnStatus() >= HAM_SUPERCEDE;
return HAM_SUPERCEDE;
}
public OnUpdateClientData_Post(pPlayer, iSendWeapons, pCdHandle) {
if (!is_user_alive(pPlayer)) {
return FMRES_IGNORED;
}
new pItem = get_member(pPlayer, m_pActiveItem);
if (pItem == -1) {
return FMRES_IGNORED;
}
new CW:iHandler = GetHandlerByEntity(pItem);
if (iHandler == CW_INVALID_HANDLER) {
return FMRES_IGNORED;
}
set_cd(pCdHandle, CD_flNextAttack, get_gametime() + 0.001); // block default animation
return FMRES_HANDLED;
}
public OnItemSlot(this) {
new CW:iHandler = GetHandlerByEntity(this);
if (iHandler == CW_INVALID_HANDLER) {
return HAM_IGNORED;
}
new iSlot = GetData(iHandler, CW_Data_SlotId);
SetHamReturnInteger(iSlot + 1);
return HAM_SUPERCEDE;
}
public OnCSItemGetMaxSpeed(this) {
new CW:iHandler = GetHandlerByEntity(this);
if (iHandler == CW_INVALID_HANDLER) {
return HAM_IGNORED;
}
new Float:flMaxSpeed = ExecuteBindedFunction(CWB_GetMaxSpeed, this);
if (_:flMaxSpeed != PLUGIN_CONTINUE) {
SetHamReturnFloat(flMaxSpeed);
return HAM_OVERRIDE;
}
return HAM_IGNORED;
}
public OnItemAddToPlayer_Post(this, pPlayer) {
new pPlayer = GetPlayer(this);
if (!ExecuteHam(Ham_IsPlayer, pPlayer)) {
return HAM_IGNORED;
}
new CW:iHandler = GetHandlerByEntity(this);
if (iHandler == CW_INVALID_HANDLER) {
new iWeaponId = get_member(this, m_iId);
ResetWeaponList(pPlayer, iWeaponId);
} else {
set_member(this, m_Weapon_iPrimaryAmmoType, GetData(iHandler, CW_Data_PrimaryAmmoType));
UpdateWeaponList(pPlayer, iHandler);
}
return HAM_HANDLED;
}
public OnSpawn_Post(this) {
new CW:iHandler = GetHandlerByEntity(this);
if (iHandler == CW_INVALID_HANDLER) {
return HAM_IGNORED;
}
ExecuteBindedFunction(CWB_Spawn, this);
return HAM_IGNORED;
}
public OnWeaponboxSpawn(this) {
g_pNewWeaponboxEnt = this;
}
public OnPlayerPreThink_Post(pPlayer) {
if (get_gametime() < g_flNextPredictionUpdate[pPlayer]) {
return HAM_IGNORED;
}
new iObsMode = pev(pPlayer, pev_iuser1);
new pObsTarget = pev(pPlayer, pev_iuser2);
new pActiveItem = iObsMode == OBS_IN_EYE
? IS_PLAYER(pObsTarget) ? get_member(pObsTarget, m_pActiveItem) : -1
: get_member(pPlayer, m_pActiveItem);
if (pActiveItem == -1) {
SetWeaponPrediction(pPlayer, false);
return HAM_IGNORED;
}
new CW:iHandler = GetHandlerByEntity(pActiveItem);
SetWeaponPrediction(pPlayer, iHandler == CW_INVALID_HANDLER);
return HAM_HANDLED;
}
public OnPlayerTakeDamage(pPlayer, pInflictor, pAttacker) {
if (pAttacker && ExecuteHam(Ham_IsPlayer, pAttacker) && pInflictor == pAttacker) {
g_pKillerItem = get_member(pAttacker, m_pActiveItem);
} else {
g_pKillerItem = pInflictor;
}
}
public OnPlayerTakeDamage_Post() {
g_pKillerItem = -1;
}
public OnMessage_DeathMsg(iMsgId, iDest, pPlayer) {
if (g_pKillerItem == -1) {
return PLUGIN_CONTINUE;
}
new pKiller = get_msg_arg_int(1);
if (!pKiller) {
return PLUGIN_CONTINUE;
}
if (!ExecuteHam(Ham_IsPlayer, pKiller)) {
return PLUGIN_CONTINUE;
}
if (!is_user_alive(pKiller)) {
return PLUGIN_CONTINUE;
}
new CW:iHandler = GetHandlerByEntity(g_pKillerItem);
if (iHandler == CW_INVALID_HANDLER) {
return PLUGIN_CONTINUE;
}
static szIcon[64];
GetStringData(iHandler, CW_Data_Icon, szIcon, charsmax(szIcon));
if (szIcon[0] == '^0') {
GetStringData(iHandler, CW_Data_Name, szIcon, charsmax(szIcon));
}
set_msg_arg_string(4, szIcon);
return PLUGIN_CONTINUE;
}
public OnSetModel_Post(this, const szModel[]) {
if (!pev_valid(this)) {
return FMRES_IGNORED;
}
if (g_pNewWeaponboxEnt == -1) {
return FMRES_IGNORED;
}
if (this != g_pNewWeaponboxEnt) {
return FMRES_IGNORED;
}
static szClassname[32];
pev(this, pev_classname, szClassname, charsmax(szClassname));
if (!equal(szClassname, "weaponbox")) {
g_pNewWeaponboxEnt = -1;
return FMRES_IGNORED;
}
new pItem = FindWeaponBoxSingleItem(this);
if (pItem == -1) {
return FMRES_IGNORED;
}
new CW:iHandler = GetHandlerByEntity(pItem);
if (iHandler == CW_INVALID_HANDLER) {
return FMRES_IGNORED;
}
ExecuteBindedFunction(CWB_WeaponBoxModelUpdate, pItem, this);
g_pNewWeaponboxEnt = -1;
if (!g_bPrecache) {
if (!ExecuteHamB(Ham_CS_Item_CanDrop, pItem)) {
set_pev(this, pev_flags, pev(this, pev_flags) | FL_KILLME);
dllfunc(DLLFunc_Think, this);
}
}
return FMRES_HANDLED;
}
public OnDecalIndex_Post() {
if (!g_bPrecache) {
return;
}
ArrayPushCell(g_irgDecals, get_orig_retval());
}
public OnWeaponClCmd(pPlayer) {
static szName[64];
read_argv(0, szName, charsmax(szName));
new CW:iHandler;
TrieGetCell(g_rgWeaponsMap, szName, iHandler);
new iWeaponId = GetData(iHandler, CW_Data_Id);
static szBaseName[32];
get_weaponname(iWeaponId, szBaseName, charsmax(szBaseName));
client_cmd(pPlayer, szBaseName);
return PLUGIN_HANDLED;
}
public OnCanDrop(this) {
new CW:iHandler = GetHandlerByEntity(this);
if (iHandler == CW_INVALID_HANDLER) {
return HAM_IGNORED;
}
if (GetHamReturnStatus() >= HAM_OVERRIDE) {
return GetHamReturnStatus();
}
SetHamReturnInteger(
ExecuteBindedFunction(CWB_CanDrop, this) == PLUGIN_CONTINUE ? 1 : 0
);
return HAM_OVERRIDE;
}
public OnMessage_WeaponList(iMsgId, iMsgDest, pPlayer) {
new iWeaponId = get_msg_arg_int(8);
if (g_weaponListDefaults[iWeaponId][WL_WeaponId] == iWeaponId) {
return PLUGIN_CONTINUE; // already initialized
}
get_msg_arg_string(1, g_weaponListDefaults[iWeaponId][WL_WeaponName], 31);
g_weaponListDefaults[iWeaponId][WL_PrimaryAmmoType] = get_msg_arg_int(2);
g_weaponListDefaults[iWeaponId][WL_PrimaryAmmoMaxAmount] = get_msg_arg_int(3);
g_weaponListDefaults[iWeaponId][WL_SecondaryAmmoType] = get_msg_arg_int(4);
g_weaponListDefaults[iWeaponId][WL_SecondaryAmmoMaxAmount] = get_msg_arg_int(5);
g_weaponListDefaults[iWeaponId][WL_SlotId] = get_msg_arg_int(6);
g_weaponListDefaults[iWeaponId][WL_NumberInSlot] = get_msg_arg_int(7);
g_weaponListDefaults[iWeaponId][WL_WeaponId] = iWeaponId;
g_weaponListDefaults[iWeaponId][WL_Flags] = get_msg_arg_int(9);
return PLUGIN_CONTINUE;
}
// ANCHOR: Weapon Entity Methods
CompleteReload(this) {
new CW:iHandler = GetHandlerByEntity(this);
new CW_Flags:iFlags = GetData(iHandler, CW_Data_Flags);
if (~iFlags & CWF_CustomReload) {
new pPlayer = GetPlayer(this);
new iMaxClip = GetData(iHandler, CW_Data_ClipSize);
new iClip = get_member(this, m_Weapon_iClip);
new iPrimaryAmmoIndex = get_member(this, m_Weapon_iPrimaryAmmoType);
new iBpAmmo = get_member(pPlayer, m_rgAmmo, iPrimaryAmmoIndex);
new iSize = min(iMaxClip - iClip, iBpAmmo);
set_member(this, m_Weapon_iClip, iClip + iSize);
set_member(pPlayer, m_rgAmmo, iBpAmmo - iSize, iPrimaryAmmoIndex);
}
set_member(this, m_Weapon_fInReload, 0);
ExecuteBindedFunction(CWB_DefaultReloadEnd, this);
}
ItemPostFrame(this) {
new CW:iHandler = GetHandlerByEntity(this);
new pPlayer = GetPlayer(this);
new flInReload = get_member(this, m_Weapon_fInReload);
new iMaxClip = GetData(iHandler, CW_Data_ClipSize);
new iWeaponFlags = GetData(iHandler, CW_Data_WeaponFlags);
new Float:flNextAttack = get_member(pPlayer, m_flNextAttack);
new button = pev(pPlayer, pev_button);
new iPrimaryAmmoIndex = get_member(this, m_Weapon_iPrimaryAmmoType);
new iSecondaryAmmoIndex = 0;
new Float:flNextPrimaryAttack = get_member(this, m_Weapon_flNextPrimaryAttack);
new Float:flNextSecondaryAttack = get_member(this, m_Weapon_flNextSecondaryAttack);
new iPrimaryAmmoAmount = get_member(pPlayer, m_rgAmmo, iPrimaryAmmoIndex);
new iSecondaryAmmoAmount = get_member(pPlayer, m_rgAmmo, iSecondaryAmmoIndex);
new Float:flReloadEndTime = get_member(this, m_Weapon_flNextReload);
if (flReloadEndTime && flReloadEndTime < get_gametime()) {
set_member(this, m_Weapon_flNextReload, 0.0);
ExecuteBindedFunction(CWB_Pump, this);
}
if (flInReload && flNextAttack <= 0.0) {
CompleteReload(this);
}
if ((button & IN_ATTACK2) && flNextSecondaryAttack <= 0) {
if (iSecondaryAmmoIndex > 0 && !iSecondaryAmmoAmount) {
set_member(this, m_Weapon_fFireOnEmpty, 1);
}
SecondaryAttack(this);
} else if ((button & IN_ATTACK) && flNextPrimaryAttack <= 0) {
if ((!get_member(this, m_Weapon_iClip) && iPrimaryAmmoIndex > 0) || (iMaxClip == -1 && !iPrimaryAmmoAmount)) {
set_member(this, m_Weapon_fFireOnEmpty, 1);
}
PrimaryAttack(this);
} else if ((button & IN_RELOAD) && iMaxClip != WEAPON_NOCLIP && !flInReload) {
Reload(this);
} else if (!(button & (IN_ATTACK|IN_ATTACK2))) {
set_member(this, m_Weapon_fFireOnEmpty, 0);
if (!IsUseable(this) && flNextPrimaryAttack < 0.0) {
// if (!(iWeaponFlags & ITEM_FLAG_NOAUTOSWITCHEMPTY) && g_pGameRules->GetNextBestWeapon(m_pPlayer, this)) {
// set_member(this, m_Weapon_flNextPrimaryAttack, 0.3);
// return;
// }
} else {
if (!get_member(this, m_Weapon_iClip) && !(iWeaponFlags & ITEM_FLAG_NOAUTORELOAD) && flNextPrimaryAttack < 0.0) {
Reload(this);
return;
}
}
set_member(this, m_Weapon_iShotsFired, 0);
WeaponIdle(this);
return;
}
if (ShouldWeaponIdle(this)) {
WeaponIdle(this);
}
}
SecondaryAttack(this) {
if (get_member_game(m_bFreezePeriod)) {
return;
}
ExecuteHamB(Ham_Weapon_SecondaryAttack, this);
if (g_bSupercede) {
return;
}
if (ExecuteBindedFunction(CWB_SecondaryAttack, this) > PLUGIN_CONTINUE) {
return;
}
}
PrimaryAttack(this) {
if (get_member_game(m_bFreezePeriod)) {
return;
}
ExecuteHamB(Ham_Weapon_PrimaryAttack, this);
if (g_bSupercede) {
return;
}
if (ExecuteBindedFunction(CWB_PrimaryAttack, this) > PLUGIN_CONTINUE) {
return;
}
}
Reload(this) {
ExecuteHamB(Ham_Weapon_Reload, this);
if (g_bSupercede) {
return;
}
if (ExecuteBindedFunction(CWB_Reload, this) > PLUGIN_CONTINUE) {
return;
}
}
WeaponIdle(this) {
if (get_member(this, m_Weapon_flTimeWeaponIdle) > 0.0) {
return;
}
ExecuteHamB(Ham_Weapon_WeaponIdle, this);
if (g_bSupercede) {
return;
}
if (ExecuteBindedFunction(CWB_Idle, this) > PLUGIN_CONTINUE) {
return;
}
}
WeaponHolster(this) {
new pPlayer = GetPlayer(this);
SetWeaponPrediction(pPlayer, true);
set_member(this, m_Weapon_fInReload, 0);
set_member(this, m_Weapon_fInSpecialReload, 0);
set_member(this, m_Weapon_flNextReload, 0.0);
if (ExecuteBindedFunction(CWB_Holster, this) > PLUGIN_CONTINUE) {
return;
}
}
WeaponDeploy(this) {
if (ExecuteBindedFunction(CWB_Deploy, this) > PLUGIN_CONTINUE) {
return;
}
new pPlayer = GetPlayer(this);
if (g_bKnifeHolstered[pPlayer]) {
g_flNextPredictionUpdate[pPlayer] = get_gametime() + 1.0;
} else if (get_member(this, m_iId) == CSW_KNIFE) {
SetWeaponPrediction(pPlayer, false);
}
// SetThink(this, "DisablePrediction");
// set_pev(this, pev_nextthink, get_gametime() + 0.1);
}
bool:ShouldWeaponIdle(this) {
#pragma unused this
return false;
}
bool:IsUseable(this) {
new CW:iHandler = GetHandlerByEntity(this);
new pPlayer = GetPlayer(this);
new iPrimaryAmmoIndex = get_member(this, m_Weapon_iPrimaryAmmoType);
new iMaxAmmo1 = GetData(iHandler, CW_Data_PrimaryAmmoMaxAmount);
new iClip = get_member(this, m_Weapon_iClip);
new iBpAmmo = get_member(pPlayer, m_rgAmmo, iPrimaryAmmoIndex);
if (iClip <= 0) {