-
Notifications
You must be signed in to change notification settings - Fork 1
/
cwm_main.sp
1777 lines (1496 loc) · 56.7 KB
/
cwm_main.sp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#pragma semicolon 1
#include <sourcemod>
#include <sdktools>
#include <sdkhooks>
#include <smlib>
#include <emitsoundany>
#include <colors_csgo>
#include <dhooks>
#include <eItems>
#include <SteamWorks>
#include <custom_weapon_mod.inc>
#if USE_VSCRIPT == 1
#include <vscriptfun>
#endif
#pragma newdecls required
int g_iStackCount = 0;
int g_iStack[MAX_CWEAPONS][WSI_Max], g_iEntityData[MAX_ENTITIES][WSI_Max];
int g_aStack[MAX_CWEAPONS][WAA_Max][MAX_ANIMATION][3];
float g_fStack[MAX_CWEAPONS][WSF_Max], g_fEntityData[MAX_ENTITIES][WSF_Max];
Handle g_hStack[MAX_CWEAPONS][WSH_Max], g_hReloading[MAX_ENTITIES];
char g_sStack[MAX_CWEAPONS][WSS_Max][PLATFORM_MAX_PATH];
int g_cBlood[MAX_BLOOD], g_cScorch, g_cBullet[MAX_BULLET], g_cBeam;
int g_iClientZoom[65][4];
DataPack g_hProjectile[MAX_ENTITIES];
Handle g_hCSPlayer_GetPlayerMaxSpeed = INVALID_HANDLE;
bool g_bHasCustomWeapon[65], g_bInAttack3[65];
StringMap g_hNamedIdentified;
char g_szMuzzle[][PLATFORM_MAX_PATH] = {
"weapon_muzzle_flash_assaultrifle",
"weapon_muzzle_flash_autoshotgun",
"weapon_muzzle_flash_awp",
"weapon_muzzle_flash_huntingrifle",
"weapon_muzzle_flash_para",
"weapon_muzzle_flash_pistol",
"weapon_muzzle_flash_shotgun",
"weapon_muzzle_flash_smg",
"weapon_muzzle_flash_taser"
};
char g_szBullet[][PLATFORM_MAX_PATH] = {
"weapon_shell_casing_50cal",
"weapon_shell_casing_9mm",
"weapon_shell_casing_candycorn",
"weapon_shell_casing_rifle",
"weapon_shell_casing_shotgun"
};
char g_szTracer[][PLATFORM_MAX_PATH] = {
"weapon_tracers_50cal",
"weapon_tracers_assrifle",
"weapon_tracers_mach",
"weapon_tracers_original",
"weapon_tracers_pistol",
"weapon_tracers_rifle",
"weapon_tracers_shot",
"weapon_tracers_smg",
"weapon_tracers_taser"
};
#define ANIM_SEQ 0
#define ANIM_FRAME 1
#define ANIM_FPS 2
#define ZOOM_DOING 0
#define ZOOM_DIRECTION 1
#define ZOOM_DESIRED 2
#define ZOOM_SPEED 3
#define DEG2RAD(%1) (%1*3.14159265/180.0)
#define CAN_ATTACK(%1) (!g_hReloading[%1] && g_fEntityData[%1][WSF_NextAttack] <= time)
// -----------------------------------------------------------------------------------------------------------------
//
// PLUGIN START
//
public void OnPluginStart() {
bool win = GameConfGetOffset(LoadGameConfigFile("core.games/common.games"), "GetDataDescMap") == 11 ? true : false;
int offset = GameConfGetOffset(LoadGameConfigFile("sdktools.games/engine.csgo"), "CommitSuicide") + (win?MAXSPEED_DIFF_WIN:MAXSPEED_DIFF_LINUX);
g_hCSPlayer_GetPlayerMaxSpeed = DHookCreate(offset, HookType_Entity, ReturnType_Float, ThisPointer_CBaseEntity, CCSPlayer_GetPlayerMaxSpeed);
for (int i = 1; i < MaxClients; i++)
if (IsClientInGame(i))
OnClientPostAdminCheck(i);
for (int i = 1; i < MAX_ENTITIES; i++)
g_iEntityData[i][WSI_Identifier] = -1;
RegAdminCmd("sm_cwm", Cmd_Spawn, ADMFLAG_ROOT);
// RegConsoleCmd("sm_cwm", Cmd_Spawn);
AddCommandListener(Cmd_LAW_Press, "+lookatweapon");
AddCommandListener(Cmd_LAW_Release, "-lookatweapon");
LoadTranslations("common.phrases");
g_hNamedIdentified = new StringMap();
}
public void OnMapStart() {
char tmp[PLATFORM_MAX_PATH];
for (int i = 0; i < MAX_BLOOD; i++) {
Format(tmp, sizeof(tmp), "decals/blood%d.vtf", i + 1); // vtf ?
g_cBlood[i] = PrecacheDecal(tmp);
}
for (int i = 0; i < MAX_BULLET; i++) {
Format(tmp, sizeof(tmp), "decals/brick/brick%d.vmt", i + 1);
g_cBullet[i] = PrecacheDecal(tmp);
}
for (int i = 0; i < sizeof(g_szBullet); i++)
PrecacheParticleSystem(g_szBullet[i]);
for (int i = 0; i < sizeof(g_szMuzzle); i++)
PrecacheParticleSystem(g_szMuzzle[i]);
for (int i = 0; i < sizeof(g_szTracer); i++)
PrecacheParticleSystem(g_szTracer[i]);
PrecacheEffect("Impact");
PrecacheEffect("ParticleEffect");
g_cScorch = PrecacheDecal("decals/scorch1.vtf");
g_cBeam = PrecacheModel("materials/sprites/laserbeam.vmt");
if( g_cBeam ) { } // This is mostly for debug propuse. So we might need to remove this warning.
PrecacheSound("weapons/clipempty_rifle.wav");
PrecacheSound("weapons/sg556/sg556_draw.wav");
for (int i = 0; i < g_iStackCount; i++) {
g_iStack[i][WSI_VModel] = PrecacheModel(g_sStack[i][WSS_VModel]);
g_iStack[i][WSI_WModel] = PrecacheModel(g_sStack[i][WSS_WModel]);
Format(tmp, sizeof(tmp), "materials/panorama/images/icons/equipment/%s.svg", g_sStack[i][WSS_Name]);
if( FileExists(tmp) )
AddFileToDownloadsTable(tmp);
}
}
public APLRes AskPluginLoad2(Handle hPlugin, bool isAfterMapLoaded, char[] error, int err_max) {
RegPluginLibrary("CustomWeaponMod");
CreateNative("CWM_Create", Native_CWM_Create);
CreateNative("CWM_SetInt", Native_CWM_SetInt);
CreateNative("CWM_GetInt", Native_CWM_GetInt);
CreateNative("CWM_SetEntityInt", Native_CWM_SetEntityInt);
CreateNative("CWM_GetEntityInt", Native_CWM_GetEntityInt);
CreateNative("CWM_SetFloat", Native_CWM_SetFloat);
CreateNative("CWM_GetFloat", Native_CWM_GetFloat);
CreateNative("CWM_SetEntityFloat", Native_CWM_SetEntityFloat);
CreateNative("CWM_GetEntityFloat", Native_CWM_GetEntityFloat);
CreateNative("CWM_RegHook", Native_CWM_RegHook);
CreateNative("CWM_AddAnimation", Native_CWM_AddAnimation);
CreateNative("CWM_RunAnimation", Native_CWM_RunAnimation);
CreateNative("CWM_RunAnimationSound", Native_CWM_RunAnimationSound);
CreateNative("CWM_Spawn", Native_CWM_Spawn);
CreateNative("CWM_ShootProjectile", Native_CWM_ShootProjectile);
CreateNative("CWM_ShootDamage", Native_CWM_ShootDamage);
CreateNative("CWM_ShootHull", Native_CWM_ShootHull);
CreateNative("CWM_ShootRay", Native_CWM_ShootRay);
CreateNative("CWM_ShootExplode", Native_CWM_ShootExplode);
CreateNative("CWM_GetId", Native_CWM_GetId);
CreateNative("CWM_RefreshHUD", Native_CWM_RefreshHUD);
CreateNative("CWM_IsCustom", Native_CWM_IsCustom);
CreateNative("CWM_GetName", Native_CWM_GetName);
CreateNative("CWM_ZoomIn", Native_CWM_ZoomIn);
CreateNative("CWM_ZoomOut", Native_CWM_ZoomOut);
CreateNative("CWM_ShellOut", Native_CWM_ShellOut);
CreateNative("CWM_LookupAttachment", Native_CWM_LookupAttachment);
ServerCommand("sm_cwm_reload");
}
// -----------------------------------------------------------------------------------------------------------------
//
// Admin commands
//
public Action Cmd_Spawn(int client, int args) {
char tmp[64], tmp2[64], tmp3[MAX_TARGET_LENGTH];
float pos[3], ang[3];
GetCmdArg(1, tmp, sizeof(tmp));
GetCmdArg(2, tmp2, sizeof(tmp2));
if (args <= 0) {
menu_Open(client);
return Plugin_Handled;
}
int id;
if (g_hNamedIdentified.GetValue(tmp, id)) {
if( args >= 2 ) {
if (StrContains(tmp2, "#") == 0 ) {
ReplaceString(tmp2, sizeof(tmp2), "#", "");
int target = GetClientOfUserId(StringToInt(tmp2));
if( IsValidClient(target) )
CWM_Spawn(id, target, pos, ang);
}
else if( IsValidClient(StringToInt(tmp2)) ) {
CWM_Spawn(id, StringToInt(tmp2), pos, ang);
}
else {
int target_list[MAXPLAYERS], target_count; bool tn_is_ml;
if ( (target_count = ProcessTargetString(tmp2, client, target_list, MAXPLAYERS,
COMMAND_FILTER_ALIVE|COMMAND_FILTER_NO_IMMUNITY, tmp3, sizeof(tmp3), tn_is_ml)) <= 0) {
ReplyToTargetError(client, target_count);
return Plugin_Handled;
}
for (int i = 0; i < target_count; i++)
CWM_Spawn(id, target_list[i], pos, ang);
}
}
else if (client > 0) {
GetClientAimedLocation(client, pos, ang);
ang[0] = ang[2] = 0.0;
ang[1] += 180.0;
CWM_Spawn(id, 0, pos, ang);
}
}
return Plugin_Handled;
}
void menu_Open(int client, int start = 0) {
Menu menu = CreateMenu(menu_Spawn);
menu.SetTitle("Que voulez-vous spawn?");
for (int i = 0; i < g_iStackCount; i++) {
menu.AddItem(g_sStack[i][WSS_Name], g_sStack[i][WSS_Fullname]);
}
menu.DisplayAt(client, start, MENU_TIME_FOREVER);
}
public int menu_Spawn(Handle handler, MenuAction action, int client, int param) {
if (action == MenuAction_Select) {
char item[32];
GetMenuItem(handler, param, item, sizeof(item));
ClientCommand(client, "sm_cwm %s #%d", item, GetClientUserId(client));
menu_Open(client, GetMenuSelectionPosition());
}
else if (action == MenuAction_End) {
CloseHandle(handler);
}
}
// -----------------------------------------------------------------------------------------------------------------
//
// Native
//
public int Native_CWM_GetId(Handle plugin, int numParams) {
static char tmp[PLATFORM_MAX_PATH];
GetNativeString(1, tmp, sizeof(tmp));
int id;
if (g_hNamedIdentified.GetValue(tmp, id))
return id;
return -1;
}
public int Native_CWM_Create(Handle plugin, int numParams) {
static char tmp[PLATFORM_MAX_PATH];
GetNativeString(2, tmp, sizeof(tmp));
int id;
if( !g_hNamedIdentified.GetValue(tmp, id) )
id = g_iStackCount++;
else {
PrintToServer("[CWM] Warning: same weapon already exist. Overriding.");
for (int i = 0; i < sizeof(g_aStack[]); i++)
g_aStack[id][i][0][0] = 0;
}
GetNativeString(1, g_sStack[id][WSS_Fullname], PLATFORM_MAX_PATH);
GetNativeString(2, g_sStack[id][WSS_Name], PLATFORM_MAX_PATH);
GetNativeString(3, g_sStack[id][WSS_ReplaceWeapon], PLATFORM_MAX_PATH);
GetNativeString(4, g_sStack[id][WSS_VModel], PLATFORM_MAX_PATH);
GetNativeString(5, g_sStack[id][WSS_WModel], PLATFORM_MAX_PATH);
g_iStack[id][WSI_VModel] = PrecacheModel(g_sStack[id][WSS_VModel]);
g_iStack[id][WSI_WModel] = PrecacheModel(g_sStack[id][WSS_WModel]);
Format(tmp, sizeof(tmp), "materials/panorama/images/icons/equipment/%s.svg", g_sStack[id][WSS_Name]);
if( FileExists(tmp) )
AddFileToDownloadsTable(tmp);
g_iStack[id][WSI_AttackBulletType] = g_iStack[id][WSI_Attack2BulletType] = g_iStack[id][WSI_Attack3BulletType] = view_as<int>(WSB_Primary);
view_as<Handle>(g_hStack[id][WSH_Draw]) = CreateForward(ET_Hook, Param_Cell, Param_Cell);
view_as<Handle>(g_hStack[id][WSH_Attack]) = CreateForward(ET_Hook, Param_Cell, Param_Cell);
view_as<Handle>(g_hStack[id][WSH_AttackPost]) = CreateForward(ET_Hook, Param_Cell, Param_Cell);
view_as<Handle>(g_hStack[id][WSH_Attack2]) = CreateForward(ET_Hook, Param_Cell, Param_Cell);
view_as<Handle>(g_hStack[id][WSH_Attack3]) = CreateForward(ET_Hook, Param_Cell, Param_Cell);
view_as<Handle>(g_hStack[id][WSH_Reload]) = CreateForward(ET_Hook, Param_Cell, Param_Cell);
view_as<Handle>(g_hStack[id][WSH_Idle]) = CreateForward(ET_Hook, Param_Cell, Param_Cell);
view_as<Handle>(g_hStack[id][WSH_Empty]) = CreateForward(ET_Hook, Param_Cell, Param_Cell);
g_hNamedIdentified.SetValue(g_sStack[id][WSS_Name], id);
return id++;
}
public int Native_CWM_RunAnimationSound(Handle plugin, int numParams) {
char tmp[PLATFORM_MAX_PATH];
int entity = GetNativeCell(1);
int id = g_iEntityData[entity][WSI_Identifier];
int client = g_iEntityData[entity][WSI_Owner];
if (id == -1)
return;
int anim = GetNativeCell(2);
GetNativeString(3, tmp, sizeof(tmp));
int frame = GetNativeCell(4);
float timer = (frame / float(g_aStack[id][anim][1][ANIM_FRAME])) * g_fEntityData[entity][WSF_AnimationSpeed];
Handle dp;
CreateDataTimer(timer, Timer_CWM_RunAnimationSound, dp, TIMER_DATA_HNDL_CLOSE);
WritePackCell(dp, entity);
WritePackCell(dp, client);
WritePackCell(dp, g_iEntityData[entity][WSI_Animation]);
WritePackString(dp, tmp);
}
public Action Timer_CWM_RunAnimationSound(Handle timer, Handle dp) {
char tmp[PLATFORM_MAX_PATH];
ResetPack(dp);
int entity = ReadPackCell(dp);
int client = ReadPackCell(dp);
int anim = ReadPackCell(dp);
if( g_iEntityData[entity][WSI_Owner] != client )
return Plugin_Stop;
if( anim != g_iEntityData[entity][WSI_Animation] ) // TODO: Save WSI_AnimationType
return Plugin_Stop;
ReadPackString(dp, tmp, sizeof(tmp));
EmitSoundToAllAny(tmp, client, SNDCHAN_WEAPON);
return Plugin_Stop;
}
public int Native_CWM_RunAnimation(Handle plugin, int numParams) {
int entity = GetNativeCell(1);
int id = g_iEntityData[entity][WSI_Identifier];
int client = g_iEntityData[entity][WSI_Owner];
if (id == -1)
return;
int anim = GetNativeCell(2);
float time = GetNativeCell(3);
int rnd = GetNativeCell(4);
if( rnd < 0 ) {
if( g_aStack[id][anim][0][0] > 1 ) {
rnd = Math_GetRandomInt(1, g_aStack[id][anim][0][0]);
if( g_aStack[id][anim][rnd][ANIM_SEQ] == g_iEntityData[entity][WSI_Animation] )
rnd = 1 + (rnd % g_aStack[id][anim][0][0]);
}
else
rnd = 1;
}
float factor;
float duration = g_aStack[id][anim][rnd][ANIM_FRAME] / float(g_aStack[id][anim][rnd][ANIM_FPS]);
if( time <= 0.0 ) {
time = duration;
factor = 1.0;
}
else {
factor = duration / time;
}
g_iEntityData[entity][WSI_Animation] = g_aStack[id][anim][rnd][ANIM_SEQ];
g_fEntityData[entity][WSF_NextIdle] = GetGameTime() + time;
g_fEntityData[entity][WSF_AnimationSpeed] = time;
CWM_Animation(client, entity, factor);
}
public int Native_CWM_AddAnimation(Handle plugin, int numParams) {
int id = GetNativeCell(1);
int data = GetNativeCell(2);
int cpt = g_aStack[id][data][0][ANIM_SEQ] + 1;
g_aStack[id][data][cpt][ANIM_SEQ] = GetNativeCell(3);
g_aStack[id][data][cpt][ANIM_FRAME] = GetNativeCell(4);
g_aStack[id][data][cpt][ANIM_FPS] = GetNativeCell(5);
g_aStack[id][data][0][0] = cpt;
}
public int Native_CWM_SetInt(Handle plugin, int numParams) {
g_iStack[GetNativeCell(1)][GetNativeCell(2)] = GetNativeCell(3);
return 1;
}
public int Native_CWM_SetEntityInt(Handle plugin, int numParams) {
g_iEntityData[GetNativeCell(1)][GetNativeCell(2)] = GetNativeCell(3);
return 1;
}
public int Native_CWM_GetEntityInt(Handle plugin, int numParams) {
return g_iEntityData[GetNativeCell(1)][GetNativeCell(2)];
}
public int Native_CWM_GetInt(Handle plugin, int numParams) {
return g_iStack[GetNativeCell(1)][GetNativeCell(2)];
}
public int Native_CWM_SetFloat(Handle plugin, int numParams) {
g_fStack[GetNativeCell(1)][GetNativeCell(2)] = GetNativeCell(3);
return 1;
}
public int Native_CWM_SetEntityFloat(Handle plugin, int numParams) {
g_fEntityData[GetNativeCell(1)][GetNativeCell(2)] = GetNativeCell(3);
return 1;
}
public int Native_CWM_GetEntityFloat(Handle plugin, int numParams) {
return view_as<int>(g_fEntityData[GetNativeCell(1)][GetNativeCell(2)]);
}
public int Native_CWM_GetFloat(Handle plugin, int numParams) {
return view_as<int>(g_fStack[GetNativeCell(1)][GetNativeCell(2)]);
}
public int Native_CWM_RegHook(Handle plugin, int numParams) {
AddToForward(g_hStack[GetNativeCell(1)][GetNativeCell(2)], plugin, GetNativeFunction(3));
}
public int Native_CWM_Spawn(Handle plugin, int numParams) {
float pos[3], ang[3];
int id = GetNativeCell(1);
int target = GetNativeCell(2);
GetNativeArray(3, pos, sizeof(pos));
GetNativeArray(4, ang, sizeof(ang));
#if CSGO_FIX_SPAWN == 1
int sClient[65], sCount;
for (int i = 1; i <= MaxClients; i++) {
if( !IsValidClient(i) )
continue;
sClient[sCount++] = i;
}
int player = sClient[GetRandomInt(0, sCount - 1)];
int wepid1 = GivePlayerItem(player, g_sStack[id][WSS_ReplaceWeapon]);
int entity = GivePlayerItem(player, g_sStack[id][WSS_ReplaceWeapon]);
RemovePlayerItem(player, entity);
RemovePlayerItem(player, wepid1);
RemoveEdict(wepid1);
#else
int entity = CreateEntityByName(g_sStack[id][WSS_ReplaceWeapon]);
DispatchKeyValue(entity, "classname", g_sStack[id][WSS_ReplaceWeapon]);
DispatchKeyValue(entity, "CanBePickedUp", "1");
DispatchSpawn(entity);
#endif
#if CSGO_RENAME_WEAPON == 1
SetEntDataString(entity, FindSendPropInfo("CBaseAttributableItem", "m_szCustomName"), g_sStack[id][WSS_Fullname], 128);
#endif
#if CSGO_FIX_STARTRAK == 1
SetEntData(entity, FindSendPropInfo("CBaseAttributableItem", "m_iItemIDLow"), -1);
SetEntData(entity, FindSendPropInfo("CBaseAttributableItem", "m_nFallbackPaintKit"), GetRandomInt(1, 2048));
SetEntData(entity, FindSendPropInfo("CBaseAttributableItem", "m_nFallbackStatTrak"), -1);
SetEntProp(entity, Prop_Send, "m_iItemDefinitionIndex", eItems_GetWeaponDefIndexByClassName(g_sStack[id][WSS_ReplaceWeapon]));
#endif
SetEntityModel(entity, g_sStack[id][WSS_WModel]);
TeleportEntity(entity, pos, ang, NULL_VECTOR);
g_fEntityData[entity][WSF_LastReload] = GetGameTime();
g_fEntityData[entity][WSF_NextAttack] = GetGameTime();
g_iEntityData[entity][WSI_ShotFired] = 0;
g_iEntityData[entity][WSI_Identifier] = id;
g_iEntityData[entity][WSI_AttackDamage] = g_iStack[id][WSI_AttackDamage];
g_iEntityData[entity][WSI_Bullet] = g_iStack[id][WSI_MaxBullet];
g_iEntityData[entity][WSI_Ammunition] = g_iStack[id][WSI_MaxAmmunition];
g_iEntityData[entity][WSI_MaxBullet] = g_iStack[id][WSI_MaxBullet];
g_iEntityData[entity][WSI_MaxAmmunition] = g_iStack[id][WSI_MaxAmmunition];
g_iEntityData[entity][WSI_Bullet2] = g_iStack[id][WSI_MaxBullet2];
g_iEntityData[entity][WSI_Ammunition2] = g_iStack[id][WSI_MaxAmmunition2];
g_iEntityData[entity][WSI_MaxBullet2] = g_iStack[id][WSI_MaxBullet];
g_iEntityData[entity][WSI_MaxAmmunition2] = g_iStack[id][WSI_MaxAmmunition];
g_iEntityData[entity][WSI_AttackType] = g_iStack[id][WSI_AttackType];
g_iEntityData[entity][WSI_Attack2Type] = g_iStack[id][WSI_Attack2Type];
g_iEntityData[entity][WSI_Attack3Type] = g_iStack[id][WSI_Attack3Type];
g_iEntityData[entity][WSI_Slot] = g_iStack[id][WSI_Slot];
g_fEntityData[entity][WSF_Speed] = g_fStack[id][WSF_Speed];
g_hReloading[entity] = INVALID_HANDLE;
if (IsValidClient(target)) {
Client_EquipWeapon(target, entity, true);
QueryClientConVar(target, "viewmodel_offset_x", view_as<ConVarQueryFinished>(ClientConVar), target);
QueryClientConVar(target, "viewmodel_offset_y", view_as<ConVarQueryFinished>(ClientConVar), target);
QueryClientConVar(target, "viewmodel_offset_z", view_as<ConVarQueryFinished>(ClientConVar), target);
}
if (Weapon_GetOwner(entity) > 0)
OnClientWeaponSwitch(Weapon_GetOwner(entity), entity);
#if SLOT_REDIRECT == 1
CreateTimer(2.0, CWM_Spawn_Post, entity);
#endif
}
public Action CWM_Spawn_Post(Handle timer, any entity) {
int id = g_iEntityData[entity][WSI_Identifier];
char tmp[PLATFORM_MAX_PATH];
switch(g_iStack[id][WSI_Slot]) {
case CS_SLOT_PRIMARY: {
strcopy(tmp, sizeof(tmp), "weapon_negev");
}
case CS_SLOT_SECONDARY: {
strcopy(tmp, sizeof(tmp), "weapon_deagle");
}
case CS_SLOT_KNIFE: {
strcopy(tmp, sizeof(tmp), "weapon_knife");
}
case CS_SLOT_GRENADE: {
strcopy(tmp, sizeof(tmp), "weapon_hegrenade");
}
case CS_SLOT_C4: {
strcopy(tmp, sizeof(tmp), "weapon_c4");
}
}
if( id >= 0 )
SetEntProp(entity, Prop_Send, "m_iItemDefinitionIndex", eItems_GetWeaponDefIndexByClassName(tmp));
}
public int Native_CWM_ShootHull(Handle plugin, int numParams) {
float src[3], ang[3], hit[3], dst[3], min[3], max[3];
int client = GetNativeCell(1);
int wpnid = GetNativeCell(2);
float size = GetNativeCell(3);
GetNativeArray(4, hit, sizeof(hit));
int id = g_iEntityData[wpnid][WSI_Identifier];
GetClientEyePosition(client, src);
GetClientEyeAngles(client, ang);
ang[0] += GetRandomFloat(-g_fStack[id][WSF_Spread], g_fStack[id][WSF_Spread]);
ang[1] += GetRandomFloat(-g_fStack[id][WSF_Spread], g_fStack[id][WSF_Spread]);
GetAngleVectors(ang, dst, NULL_VECTOR, NULL_VECTOR);
ScaleVector(dst, 10000.0);
AddVectors(src, dst, dst);
for (int i = 0; i < 3; i++) {
min[i] = -size;
max[i] = size;
}
int target;
Handle trace = TR_TraceHullFilterEx(src, dst, min, max, MASK_SHOT, TraceEntityFilterSelf, client);
if (TR_DidHit(trace)) {
TR_GetEndPosition(hit, trace);
target = TR_GetEntityIndex(trace);
if (GetVectorDistance(src, hit) < g_fStack[id][WSF_AttackRange]) {
if (IsBreakable(target)) {
Entity_Hurt(target, g_iEntityData[wpnid][WSI_AttackDamage], client, DMG_CRUSH|DMG_SLASH, g_sStack[id][WSS_Name]);
if (IsValidClient(target)) {
TE_SetupBloodSprite(hit, view_as<float>( { 0.0, 0.0, 0.0 } ), { 255, 0, 0, 255 }, 16, 0, 0);
TE_SendToAll();
Entity_GetGroundOrigin(target, dst);
TE_SetupWorldDecal(dst, g_cBlood[GetRandomInt(0, MAX_BLOOD - 1)]);
TE_SendToAll();
}
}
else
target = 0;
}
else
target = -1;
}
delete trace;
if (target >= 0)
SetNativeArray(4, hit, sizeof(hit));
return target;
}
public int Native_CWM_ShootRay(Handle plugin, int numParams) {
static float src[3], ang[3], hit[3], dst[3], nor[3];
int client = GetNativeCell(1);
int wpnid = GetNativeCell(2);
GetNativeArray(3, hit, sizeof(hit));
int id = g_iEntityData[wpnid][WSI_Identifier];
GetClientEyePosition(client, src);
GetClientEyeAngles(client, ang);
GetEntPropVector(client, Prop_Send, "m_aimPunchAngleVel", nor);
float penality = GetEntPropFloat(wpnid, Prop_Send, "m_fAccuracyPenalty") * 8.0;
ang[0] += GetRandomFloat(-g_fStack[id][WSF_Spread], g_fStack[id][WSF_Spread]) * penality + (nor[0]/10.0)*2.0;
ang[1] += GetRandomFloat(-g_fStack[id][WSF_Spread], g_fStack[id][WSF_Spread]) * penality + (nor[1]/10.0)*2.0;
int target;
Handle trace = TR_TraceRayFilterEx(src, ang, MASK_SHOT, RayType_Infinite, TraceEntityFilterSelf, client);
if (TR_DidHit(trace)) {
TR_GetEndPosition(hit, trace);
TR_GetPlaneNormal(trace, nor);
target = TR_GetEntityIndex(trace);
int hitbox = TR_GetHitGroup(trace);
if (GetVectorDistance(src, hit) < g_fStack[id][WSF_AttackRange]) {
TE_Start("Entity Decal");
TE_WriteNum("m_nEntity", target > 0 ? target : 0);
TE_WriteVector("m_vecOrigin", hit);
TE_WriteVector("m_vecStart", src);
TE_WriteNum("m_nIndex", g_cBullet[GetRandomInt(0, MAX_BULLET - 1)]);
TE_SendToAll();
if( IsMoveable(target) ) {
float physcale = 8.0; // TODO: Use cvar: phys_pushscale
SubtractVectors(hit, src, nor);
NormalizeVector(nor, nor);
ScaleVector(nor, float(g_iEntityData[wpnid][WSI_AttackDamage]) * physcale);
TeleportEntity(target, NULL_VECTOR, NULL_VECTOR, nor);
}
if (IsBreakable(target)) {
Entity_Hurt(target, g_iEntityData[wpnid][WSI_AttackDamage], client, DMG_CRUSH, g_sStack[id][WSS_Name]);
if (IsValidClient(target)) {
TE_SetupBloodSprite(hit, nor, { 255, 0, 0, 255 }, 16, 0, 0);
TE_SendToAll();
Entity_GetGroundOrigin(target, dst);
TE_SetupWorldDecal(dst, g_cBlood[GetRandomInt(0, MAX_BLOOD - 1)]);
TE_SendToAll();
}
else {
TE_SetupBloodSprite(hit, nor, { 0, 0, 0, 255 }, 16, 0, 0);
TE_SendToAll();
}
}
else {
TE_Start("EffectDispatch");
TE_WriteFloatArray("m_vOrigin.x", hit, 3);
TE_WriteFloatArray("m_vStart.x", src, 3);
TE_WriteNum("m_nHitBox", hitbox);
TE_WriteNum("m_nSurfaceProp", 0);
TE_WriteNum("m_nDamageType", DMG_CRUSH);
TE_WriteNum("entindex", target);
TE_WriteNum("m_iEffectName", GetEffectIndex("Impact"));
TE_SendToAll();
target = 0;
}
}
else
target = -1;
}
delete trace;
if (target >= 0)
SetNativeArray(3, hit, sizeof(hit));
return target;
}
public int Native_CWM_ShootDamage(Handle plugin, int numParams) {
static float hit[3];
int client = GetNativeCell(1);
int wpnid = GetNativeCell(2);
int target = GetNativeCell(3);
GetNativeArray(4, hit, sizeof(hit));
int id = g_iEntityData[wpnid][WSI_Identifier];
if (IsBreakable(target)) {
Entity_Hurt(target, g_iEntityData[wpnid][WSI_AttackDamage], client, DMG_CRUSH, g_sStack[id][WSS_Name]);
if (IsValidClient(target)) {
TE_SetupBloodSprite(hit, view_as<float>( { 0.0, 0.0, 0.0 } ), { 255, 0, 0, 255 }, 16, 0, 0);
TE_SendToAll();
Entity_GetGroundOrigin(target, hit);
TE_SetupWorldDecal(hit, g_cBlood[GetRandomInt(0, MAX_BLOOD - 1)]);
TE_SendToAll();
}
}
return target;
}
public int Native_CWM_ShootExplode(Handle plugin, int numParams) {
int client = GetNativeCell(1);
int wpnid = GetNativeCell(2);
int entity = GetNativeCell(3);
float radius = view_as<float>(GetNativeCell(4));
int id = g_iEntityData[wpnid][WSI_Identifier];
float falloff = float(g_iEntityData[wpnid][WSI_AttackDamage]) / radius;
float src[3], dst[3], distance, min[3], max[3], hit[3], fraction;
Handle tr;
Entity_GetAbsOrigin(entity, src);
TE_Start("World Decal");
TE_WriteVector("m_vecOrigin", src);
TE_WriteNum("m_nIndex", g_cScorch);
TE_SendToAll();
int MTRACE = 8;
for (int i = 1; i <= MAX_ENTITIES; i++) {
if (!IsValidEdict(i) || !IsValidEntity(i))
continue;
if (!IsBreakable(i))
continue;
if (IsValidClient(i) && !IsPlayerAlive(i))
continue;
Entity_GetAbsOrigin(i, dst);
distance = view_as<float>(Math_Min(1.0, GetVectorDistance(src, dst)));
if (distance > radius)
continue;
Entity_GetMinSize(i, min);
Entity_GetMaxSize(i, max);
fraction = 0.0;
for (int j = 0; j < MTRACE; j++) {
for (int k = 0; k <= 2; k++)
hit[k] = dst[k] + GetRandomFloat(min[k], max[k]);
tr = TR_TraceRayFilterEx(src, hit, MASK_SHOT, RayType_EndPoint, TraceEntityFilterSelf, entity);
if (TR_DidHit(tr)) {
fraction += TR_GetFraction(tr);
if (TR_GetEntityIndex(tr) == i) {
TE_SetupBloodSprite(hit, view_as<float>( { 0.0, 0.0, 0.0 } ), { 255, 0, 0, 255 }, 16, 0, 0);
TE_SendToAll();
}
}
else {
fraction += 1.0;
TE_SetupBloodSprite(hit, view_as<float>( { 0.0, 0.0, 0.0 } ), { 255, 0, 0, 255 }, 16, 0, 0);
TE_SendToAll();
}
delete tr;
}
float damage = (fraction / float(MTRACE)) * (radius - distance) * falloff;
if (damage > 0.0) {
Entity_Hurt(i, RoundToCeil(damage), client, DMG_BLAST, g_sStack[id][WSS_Name]);
}
}
return 1;
}
public int Native_CWM_ShootProjectile(Handle plugin, int numParams) {
char name[32], model[PLATFORM_MAX_PATH];
int client = GetNativeCell(1);
int entity = GetNativeCell(2);
GetNativeString(3, model, sizeof(model));
GetNativeString(4, name, sizeof(name));
float spreadAngle = view_as<float>(GetNativeCell(5));
float speed = view_as<float>(GetNativeCell(6));
Function callback = GetNativeFunction(7);
int ent = CreateEntityByName("hegrenade_projectile");
DispatchKeyValue(ent, "classname", name);
DispatchSpawn(ent);
SetEntPropEnt(ent, Prop_Send, "m_hOwnerEntity", client);
SetEntPropFloat(ent, Prop_Send, "m_flElasticity", 0.4);
SetEntityMoveType(ent, MOVETYPE_FLYGRAVITY);
Entity_SetSolidType(ent, SOLID_VPHYSICS);
Entity_SetSolidFlags(ent, FSOLID_TRIGGER);
Entity_SetCollisionGroup(ent, COLLISION_GROUP_PLAYER);
if (!StrEqual(model, NULL_MODEL)) {
if (!IsModelPrecached(model))
PrecacheModel(model);
SetEntityModel(ent, model);
}
else
SetEntityRenderMode(ent, RENDER_NONE);
float vecOrigin[3], vecAngles[3], vecDir[3], vecPush[3];
GetClientEyePosition(g_iEntityData[entity][WSI_Owner], vecOrigin);
GetClientEyeAngles(g_iEntityData[entity][WSI_Owner], vecAngles);
vecAngles[0] += GetRandomFloat(-spreadAngle, spreadAngle);
vecAngles[1] += GetRandomFloat(-spreadAngle, spreadAngle);
GetAngleVectors(vecAngles, vecPush, NULL_VECTOR, NULL_VECTOR);
GetAngleVectors(vecAngles, vecDir, NULL_VECTOR, NULL_VECTOR);
ScaleVector(vecPush, RANGE_MELEE - 16.0);
ScaleVector(vecDir, speed);
float delta[3] = { 32.0, -4.0, -12.0 };
Math_RotateVector(delta, vecAngles, delta);
vecOrigin[0] += delta[0];
vecOrigin[1] += delta[1];
vecOrigin[2] += delta[2];
if (g_hProjectile[ent])
delete g_hProjectile[ent];
g_hProjectile[ent] = new DataPack();
g_hProjectile[ent].WriteCell(client);
g_hProjectile[ent].WriteCell(entity);
g_hProjectile[ent].WriteCell(plugin);
g_hProjectile[ent].WriteFunction(callback);
TeleportEntity(ent, vecOrigin, vecAngles, vecDir);
SDKHook(ent, SDKHook_StartTouch, CWM_ProjectileTouch);
return ent;
}
public int Native_CWM_RefreshHUD(Handle plugin, int numParams) {
CWM_Refresh(GetNativeCell(1), GetNativeCell(2));
}
public int Native_CWM_IsCustom(Handle plugin, int numParams) {
int entity = GetNativeCell(1);
return view_as<int>(g_iEntityData[entity][WSI_Identifier] >= 0);
}
public int Native_CWM_GetName(Handle plugin, int numParams) {
int id = GetNativeCell(1);
SetNativeString(2, g_sStack[id][WSS_Name], sizeof(g_sStack[][]));
}
public int Native_CWM_ZoomIn(Handle plugin, int numParams) {
int client = GetNativeCell(1);
g_iClientZoom[client][ZOOM_DIRECTION] = -1;
g_iClientZoom[client][ZOOM_DOING] = GetNativeCell(2);
g_iClientZoom[client][ZOOM_DESIRED] = GetNativeCell(3);
g_iClientZoom[client][ZOOM_SPEED] = GetNativeCell(4);
int hud = GetEntProp(client, Prop_Send, "m_iHideHUD");
SetEntProp(client, Prop_Send, "m_iHideHUD", hud|HIDEHUD_CROSSHAIR);
}
public int Native_CWM_ZoomOut(Handle plugin, int numParams) {
int client = GetNativeCell(1);
g_iClientZoom[client][ZOOM_DIRECTION] = 1;
g_iClientZoom[client][ZOOM_DOING] = GetNativeCell(2);
g_iClientZoom[client][ZOOM_DESIRED] = GetNativeCell(3);
g_iClientZoom[client][ZOOM_SPEED] = GetNativeCell(4);
int hud = GetEntProp(client, Prop_Send, "m_iHideHUD");
SetEntProp(client, Prop_Send, "m_iHideHUD", hud&~HIDEHUD_CROSSHAIR);
}
public int Native_CWM_ShellOut(Handle plugin, int numParams) {
static float hit[3];
int client = GetNativeCell(1);
int wpnid = GetNativeCell(2);
int muzzle = GetNativeCell(3);
int bullet = GetNativeCell(4);
int tracer = GetNativeCell(5);
GetNativeArray(6, hit, sizeof(hit));
bool right = view_as<bool>(GetNativeCell(7));
bool left = view_as<bool>(GetNativeCell(8));
int idx;
int view = GetEntPropEnt(client, Prop_Send, "m_hViewModel");
int world = GetEntPropEnt(wpnid, Prop_Send, "m_hWeaponWorldModel");
if( view <= 0 || world <= 0 )
return 0;
int pCount = 0, pPlayers[65];
for (int i = 1; i < MaxClients; i++)
if( IsValidClient(i) && i != client )
pPlayers[pCount++] = i;
int tracerId = CreateEntityByName("info_particle_system");
DispatchKeyValue(tracerId, "OnUser1", "!self,KillHierarchy,,0.01,-1");
DispatchSpawn(tracerId);
TeleportEntity(tracerId, hit, NULL_VECTOR, NULL_VECTOR);
AcceptEntityInput(tracerId, "FireUser1");
if( right ) {
if( muzzle > 0 ) {
idx = CWM_LookupAttachment(view, "rw_muzzle");
if( idx > 0 ) {
TE_SetupEffect(g_szMuzzle[muzzle - 1], view, idx);
TE_SendToClient(client);
}
idx = CWM_LookupAttachment(world, "muzzle_flash");
if( idx > 0 ) {
TE_SetupEffect(g_szMuzzle[muzzle - 1], world, idx);
TE_Send(pPlayers, pCount);
}
}
if( bullet > 0 ) {
idx = CWM_LookupAttachment(view, "rw_bullet");
if( idx > 0 ) {
TE_SetupEffect(g_szBullet[bullet - 1], view, idx);
TE_SendToClient(client);
}
idx = CWM_LookupAttachment(world, "shell_eject");
if( idx > 0 ) {
TE_SetupEffect(g_szBullet[bullet - 1], world, idx);
TE_Send(pPlayers, pCount);
}
}
if( tracer > 0 && tracerId > 0 ) {
idx = CWM_LookupAttachment(view, "rw_muzzle");
if( idx > 0 ) {
TE_SetupEffect(g_szTracer[tracer - 1], view, idx);
TE_WriteNum("m_nOtherEntIndex", tracerId);
TE_SendToClient(client);
}
idx = CWM_LookupAttachment(world, "muzzle_flash");
if( idx > 0 ) {
TE_SetupEffect(g_szTracer[tracer - 1], world, idx);
TE_WriteNum("m_nOtherEntIndex", tracerId);
TE_Send(pPlayers, pCount);
}
}
}
if( left ) {
if( muzzle > 0 ) {
idx = CWM_LookupAttachment(view, "lw_muzzle");
if( idx > 0 ) {
TE_SetupEffect(g_szMuzzle[muzzle - 1], view, idx);
TE_SendToClient(client);
}
idx = CWM_LookupAttachment(world, "muzzle_flash2");
if( idx > 0 ) {
TE_SetupEffect(g_szMuzzle[muzzle - 1], world, idx);
TE_Send(pPlayers, pCount);
}
}
if( bullet > 0 ) {
idx = CWM_LookupAttachment(view, "lw_bullet");
if( idx > 0 ) {
TE_SetupEffect(g_szBullet[bullet - 1], view, idx);
TE_SendToClient(client);
}
idx = CWM_LookupAttachment(world, "shell_eject2");
if( idx > 0 ) {
TE_SetupEffect(g_szBullet[bullet - 1], world, idx);
TE_Send(pPlayers, pCount);
}
}
if( tracer > 0 && tracerId > 0 ) {
idx = CWM_LookupAttachment(view, "rl_muzzle");
if( idx > 0 ) {
TE_SetupEffect(g_szTracer[tracer - 1], view, idx);
TE_WriteNum("m_nOtherEntIndex", tracerId);
TE_SendToClient(client);
}
idx = CWM_LookupAttachment(world, "muzzle_flash2");
if( idx > 0 ) {
TE_SetupEffect(g_szTracer[tracer - 1], world, idx);
TE_WriteNum("m_nOtherEntIndex", tracerId);
TE_Send(pPlayers, pCount);
}
}
}
return 1;
}
public int Native_CWM_LookupAttachment(Handle plugin, int numParams) {
static char tmp[PLATFORM_MAX_PATH], model[PLATFORM_MAX_PATH], key[PLATFORM_MAX_PATH * 2+1];
static StringMap cache;
if( !cache )
cache = new StringMap();
int value = -1;
int ent = GetNativeCell(1);
GetNativeString(2, tmp, sizeof(tmp));
Entity_GetModel(ent, model, sizeof(model));
Format(key, sizeof(key), "%s###%s", model, tmp);
if( cache.GetValue(key, value) )
return value;
#if USE_VSCRIPT == 1
VSF_CBaseAnimating mdl = VSF_CBaseAnimating.FromEntIndex(ent);