This repository has been archived by the owner on Jul 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathinsurgency.sp
1783 lines (1660 loc) · 61.1 KB
/
insurgency.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
#define PLUGIN_DESCRIPTION "Provides functions to support Insurgency. Includes logging, round statistics, weapon names, player class names, and more."
#define PLUGIN_NAME "[INS] Insurgency Support Library"
#define PLUGIN_VERSION "1.4.3"
#define PLUGIN_WORKING "1"
#define PLUGIN_LOG_PREFIX "INSLIB"
#define PLUGIN_AUTHOR "Jared Ballou (jballou)"
#define PLUGIN_URL "http://jballou.com/insurgency"
public Plugin:myinfo = {
name = PLUGIN_NAME,
author = PLUGIN_AUTHOR,
description = PLUGIN_DESCRIPTION,
version = PLUGIN_VERSION,
url = PLUGIN_URL
};
#include <sourcemod>
#include <regex>
#include <sdktools>
#include <insurgencydy>
#include <loghelper>
#undef REQUIRE_PLUGIN
#include <updater>
#pragma unused cvarVersion
#define INS
new Handle:cvarVersion = INVALID_HANDLE; // version cvar
new Handle:cvarEnabled = INVALID_HANDLE; // are we enabled?
//new Handle:cvarCheckpointCounterattackCapture = INVALID_HANDLE;
//new Handle:cvarCheckpointCapturePlayerRatio = INVALID_HANDLE;
new Handle:cvarInfiniteAmmo = INVALID_HANDLE; // Infinite ammo (still needs reloads)
new Handle:cvarInfiniteMagazine = INVALID_HANDLE; // Infinite magazine (never need to reload)
new Handle:cvarDisableSliding = INVALID_HANDLE; // Disable Sliding
new Handle:cvarLogLevel = INVALID_HANDLE; // Log level
new Handle:cvarClassStripWords = INVALID_HANDLE;
new Handle:g_weap_array = INVALID_HANDLE;
new Handle:hGameConf = INVALID_HANDLE;
new g_iObjResEntity, String:g_iObjResEntityNetClass[32];
new g_iGameRulesProxy, String:g_iGameRulesProxyNetClass[32]
new g_iPlayerManagerEntity, String:g_iPlayerManagerEntityNetClass[32];
new String:g_classes[Teams][MAX_SQUADS][SQUAD_SIZE][MAX_CLASS_LEN];
new g_weapon_stats[MAXPLAYERS+1][MAX_DEFINABLE_WEAPONS][WeaponStatFields];
new g_round_stats[MAXPLAYERS+1][RoundStatFields];
new g_client_last_weapon[MAXPLAYERS+1] = {-1, ...};
new String:g_client_last_weaponstring[MAXPLAYERS+1][64];
new String:g_client_hurt_weaponstring[MAXPLAYERS+1][64];
new String:g_client_last_classstring[MAXPLAYERS+1][64];
#define KILL_REGEX_PATTERN "^\"(.+(?:<[^>]*>))\" killed \"(.+(?:<[^>]*>))\" with \"([^\"]*)\" at (.*)"
#define SUICIDE_REGEX_PATTERN "^\"(.+(?:<[^>]*>))\" committed suicide with \"([^\"]*)\""
new Handle:kill_regex = INVALID_HANDLE;
new Handle:suicide_regex = INVALID_HANDLE;
#define MAX_STRIP_LEN 32
#define MAX_STRIP_COUNT 16
//new String:ServerName[100];// Stores the server name.
//new String:Version[100]; // Stores the update version number
//new String:IP_Port[100]; // Stores the IP address & port number
//new String:SteamID[100]; // Stores the steam server ID
//new String:Account[100]; // Stores the account logged into the server.
//new String:Map[100];// Stores the current map name
//new String:Players[100]; // Stores the total number of players & bots active
//new String:Edicts[100]; // Stores total number of edicts used
//============================================================================================================
public APLRes:Plugin_Setup_natives() {
CreateNative("Ins_GetWeaponGetMaxClip1", Native_Weapon_GetMaxClip1);
CreateNative("Ins_GetMaxClip1", Native_Weapon_GetMaxClip1);
CreateNative("Ins_GetDefaultClip1", Native_Weapon_GetDefaultClip1);
CreateNative("Ins_DecrementAmmo", Native_Weapon_DecrementAmmo);
CreateNative("Ins_AddMags", Native_Player_AddMags);
CreateNative("Ins_GetWeaponName", Native_Weapon_GetWeaponName);
CreateNative("Ins_GetWeaponId", Native_Weapon_GetWeaponId);
CreateNative("Ins_ObjectiveResource_GetProp", Native_ObjectiveResource_GetProp);
CreateNative("Ins_ObjectiveResource_GetPropFloat", Native_ObjectiveResource_GetPropFloat);
CreateNative("Ins_ObjectiveResource_GetPropEnt", Native_ObjectiveResource_GetPropEnt);
CreateNative("Ins_ObjectiveResource_GetPropBool", Native_ObjectiveResource_GetPropBool);
CreateNative("Ins_ObjectiveResource_GetPropVector", Native_ObjectiveResource_GetPropVector);
CreateNative("Ins_ObjectiveResource_GetPropString", Native_ObjectiveResource_GetPropString);
CreateNative("Ins_InCounterAttack", Native_InCounterAttack);
CreateNative("Ins_Log", Native_Log);
CreateNative("Ins_GetPlayerScore", Native_GetPlayerScore);
CreateNative("Ins_GetPlayerClass", Native_GetPlayerClass);
return APLRes_Success;
}
/*
"flag_pickup"
{
"priority" "short"
"userid" "short"
}
"flag_drop"
{
"priority" "short"
"userid" "short"
}
"flag_captured"
{
"priority" "short"
"cp" "short"
"userid" "short"
}
"flag_returned"
{
"priority" "short"
"userid" "short"
}
"flag_reset"
{
"priority" "short"
"team" "short"
}
"object_destroyed"
{
"team" "byte"
"attacker" "byte"
"cp" "short"
"index" "short"
"type" "byte"
"weapon" "string"
"weaponid" "short"
"assister" "byte"
"attackerteam" "byte"
}
"radio_requested"
{
"requesting_player" "short"
"team" "short"
}
"artillery_requested"
{
"requesting_player" "short"
"radio_player" "short"
"team" "short"
"type" "string"
"lethal" "bool"
"target_x" "float"
"target_y" "float"
"target_z" "float"
}
"artillery_failed"
{
"requesting_player" "short"
"radio_player" "short"
"team" "short"
"type" "string"
"lethal" "bool"
"reason" "string"
}
"artillery_called"
{
"requesting_player" "short"
"radio_player" "short"
"team" "short"
"type" "string"
"lethal" "bool"
"target_x" "float"
"target_y" "float"
"target_z" "float"
}
"flag_pickup"
"flag_drop"
"flag_captured"
"flag_returned"
"flag_reset"
"object_destroyed"
"radio_requested"
"artillery_requested"
"artillery_failed"
"artillery_called"
*/
public Plugin_Setup_cvar() {
cvarVersion = CreateConVar("sm_insurgency_version", PLUGIN_VERSION, PLUGIN_DESCRIPTION, FCVAR_NOTIFY | FCVAR_DONTRECORD);
cvarEnabled = CreateConVar("sm_insurgency_enabled", PLUGIN_WORKING, "sets whether log fixing is enabled", FCVAR_NOTIFY);
//cvarCheckpointCapturePlayerRatio = CreateConVar("sm_insurgency_checkpoint_capture_player_ratio", "0.5", "Fraction of living players required to capture in Checkpoint", FCVAR_NOTIFY);
//cvarCheckpointCounterattackCapture = CreateConVar("sm_insurgency_checkpoint_counterattack_capture", "0", "Enable counterattack by bots to capture points in Checkpoint", FCVAR_NOTIFY);
cvarInfiniteAmmo = CreateConVar("sm_insurgency_infinite_ammo", "0", "Infinite ammo, still uses magazines and needs to reload", FCVAR_NOTIFY);
cvarInfiniteMagazine = CreateConVar("sm_insurgency_infinite_magazine", "0", "Infinite magazine, will never need reloading.", FCVAR_NOTIFY);
cvarDisableSliding = CreateConVar("sm_insurgency_disable_sliding", "0", "0: do nothing, 1: disable for everyone, 2: disable for Security, 3: disable for Insurgents", FCVAR_NOTIFY);
cvarLogLevel = CreateConVar("sm_insurgency_log_level", "error", "Logging level, values can be: all, trace, debug, info, warn, error", FCVAR_NOTIFY);
cvarClassStripWords = CreateConVar("sm_insurgency_class_strip_words", "template training coop security insurgent survival", "Strings to strip out of player class (squad slot) names", FCVAR_NOTIFY, true, 0.0, true, 1.0);
HookConVarChange(cvarLogLevel,OnCvarLogLevelChange);
}
public Plugin_Setup_stats() {
kill_regex = CompileRegex(KILL_REGEX_PATTERN);
suicide_regex = CompileRegex(SUICIDE_REGEX_PATTERN);
//Begin HookEvents
hook_wstats();
}
public Plugin_Setup_events() {
// Hook events
HookEvent("player_hurt", Event_PlayerHurt);
HookEvent("weapon_fire", Event_WeaponFire);
HookEvent("weapon_firemode", Event_WeaponFireMode);
HookEvent("weapon_reload", Event_WeaponReload);
HookEvent("weapon_deploy", Event_WeaponDeploy);
HookEvent("player_death", Event_PlayerDeathPre, EventHookMode_Pre);
HookEvent("player_death", Event_PlayerDeath);
HookEvent("player_pick_squad", Event_PlayerPickSquad);
HookEvent("player_suppressed", Event_PlayerSuppressed);
HookEvent("player_avenged_teammate", Event_PlayerAvengedTeammate);
HookEvent("player_disconnect", Event_PlayerDisconnect, EventHookMode_Pre);
HookEvent("grenade_thrown", Event_GrenadeThrown);
HookEvent("grenade_detonate", Event_GrenadeDetonate);
HookEvent("game_end", Event_GameEnd);
HookEvent("game_end", Event_GameEndPre, EventHookMode_Pre);
HookEvent("game_newmap", Event_GameNewMap);
HookEvent("game_start", Event_GameStart);
HookEvent("round_start", Event_RoundStart);
HookEvent("round_begin", Event_RoundBegin);
HookEvent("round_end", Event_RoundEnd);
HookEvent("round_end", Event_RoundEndPre, EventHookMode_Pre);
HookEvent("round_level_advanced", Event_RoundLevelAdvanced);
HookEvent("missile_launched", Event_MissileLaunched);
HookEvent("missile_detonate", Event_MissileDetonate);
HookEvent("object_destroyed", Event_ObjectDestroyed);
HookEvent("controlpoint_captured", Event_ControlPointCaptured);
HookEvent("controlpoint_captured", Event_ControlPointCapturedPre, EventHookMode_Pre);
HookEvent("controlpoint_neutralized", Event_ControlPointNeutralized);
HookEvent("controlpoint_starttouch", Event_ControlPointStartTouchPre, EventHookMode_Pre);
HookEvent("controlpoint_starttouch", Event_ControlPointStartTouch);
HookEvent("controlpoint_endtouch", Event_ControlPointEndTouch);
HookEvent("enter_spawnzone", Event_EnterSpawnZone);
HookEvent("exit_spawnzone", Event_ExitSpawnZone);
}
public APLRes:AskPluginLoad2(Handle:myself, bool:late, String:error[], err_max) {
RegPluginLibrary("insurgency");
return Plugin_Setup_natives();
}
public OnPluginStart() {
InsLog(DEFAULT,"Starting");
Plugin_Setup_cvar();
Plugin_Setup_events();
Plugin_Setup_stats();
hGameConf = LoadGameConfigFile("insurgency.games");
//Begin Engine LogHooks
AddGameLogHook(LogEvent);
// LoadTranslations("insurgency.phrases");
//UpdateAllDataSources();
//HookUpdater();
}
public OnCvarLogLevelChange(Handle:cvar, const String:oldVal[], const String:newVal[])
{
// If nothing has changed, exit
if (strcmp(oldVal,newVal,false) == 0)
return;
for (new i=0; i<sizeof(g_sLogLevel); i++)
{
if (strcmp(newVal,g_sLogLevel[i],false) == 0)
{
g_iLogLevel = LOG_LEVEL:i;
InsLog(DEBUG,"New log level is %s (%d), g_iLogLevel %d, old was %s",newVal,i,g_iLogLevel,oldVal);
}
}
}
public OnPluginEnd()
{
WstatsDumpAll();
g_weap_array = INVALID_HANDLE;
g_iGameRulesProxy = -1;
g_iObjResEntity = -1;
g_iPlayerManagerEntity = -1;
}
public OnMapStart()
{
UpdateAllDataSources();
}
public UpdateAllDataSources()
{
InsLog(DEBUG,"Starting UpdateAllDataSources");
GetEntity_ObjectiveResource(1);
GetEntity_GameRulesProxy(1);
GetEntity_PlayerManager(1);
GetWeaponData();
GetTeams(false);
GetStatus();
//CreateTimer(4.5, GetStatus);
}
public GetStatus()
//Action:GetStatus(Handle:Timer)
{
InsLog(DEBUG,"Starting GetStatus");
// Grab status output.
// 600 characters is enough,
// decl String:Output[600];
// ServerCommandEx(Output, 600, "version");
// Grab the first 8 lines out only
// decl String:Derp[8][100];
// ExplodeString(Output, "\n", Derp, 8, 100);
// ServerName = Derp[0]; // Server name
// Version = Derp[1]; // Version number
// InsLog(DEBUG,"Derp %s Version %s",Derp,Version);
// IP_Port = Derp[2]; // Port & IP
// SteamID = Derp[3]; // Server steam ID
// Account = Derp[4]; // Steam account logged in
// Map = Derp[5]; // Map name
// Players = Derp[6]; // Players & bots
// Edicts = Derp[7]; // Edict count
//new Handle:fileHandle=OpenFile(path,"r"); // Opens addons/sourcemod/blank.txt to read from (and only reading)
//while(!IsEndOfFile(fileHandle)&&ReadFileLine(fileHandle,line,sizeof(line)))
//{
// InsLog(DEBUG,"line %s",line);
//}
//CloseHandle(fileHandle);
}
// public OnLibraryAdded(const String:name[]) {
// HookUpdater();
// }
OnPlayerDisconnect(client)
{
if(client > 0 && IsClientInGame(client))
{
dump_player_stats(client);
reset_player_stats(client);
reset_round_stats(client);
}
}
//=====================================================================================================
hook_wstats()
{
HookEvent("player_first_spawn", Event_PlayerSpawn);
HookEvent("player_spawn", Event_PlayerSpawn);
HookEvent("player_disconnect", Event_PlayerDisconnect, EventHookMode_Pre);
}
// Update array tracking the class of each player
public UpdateClassName(team,squad,squad_slot,String:raw_class_template[]) {
decl String:class_template[MAX_CLASS_LEN];
FormatPlayerClassName(class_template,sizeof(class_template),raw_class_template);
if(!StrEqual(g_classes[team][squad][squad_slot],class_template))
{
InsLog(DEBUG,"team: %d squad: %d squad_slot: %d class_template: %s",team,squad,squad_slot,class_template);
Format(g_classes[team][squad][squad_slot],MAX_CLASS_LEN,"%s",class_template);
}
}
GetEntity_ObjectiveResource(always=0) {
if (((g_iObjResEntity < 1) || !IsValidEntity(g_iObjResEntity)) || (always))
{
g_iObjResEntity = FindEntityByClassname(0,"ins_objective_resource");
GetEntityNetClass(g_iObjResEntity, g_iObjResEntityNetClass, sizeof(g_iObjResEntityNetClass));
InsLog(DEBUG,"g_iObjResEntityNetClass %s",g_iObjResEntityNetClass);
}
if (g_iObjResEntity)
return g_iObjResEntity;
InsLog(WARN,"GetEntity_ObjectiveResource failed!");
return -1;
}
/*
CINSRulesProxy (type DT_INSRulesProxy)
Table: baseclass (offset 0) (type DT_GameRulesProxy)
Table: ins_gamerules_data (offset 0) (type DT_INSRules)
Member: m_iWinningTeam (offset 908) (type integer) (bits 5) ()
Member: m_flRoundStartTime (offset 916) (type float) (bits 0) (NoScale)
Member: m_flGameStartTime (offset 920) (type float) (bits 0) (NoScale)
Member: m_flLastPauseTime (offset 924) (type float) (bits 0) (NoScale)
Member: m_bTimerPaused (offset 928) (type integer) (bits 1) (Unsigned)
Member: m_flRoundLength (offset 932) (type float) (bits 0) (NoScale)
Member: m_flRoundMaxTime (offset 936) (type float) (bits 0) (NoScale)
Member: m_iGameState (offset 904) (type integer) (bits 8) (Unsigned)
Member: m_iRoundPlayedCount (offset 940) (type integer) (bits 32) ()
Table: m_flNextReinforcementWave (offset 948) (type m_flNextReinforcementWave)
Member: 000 (offset 0) (type float) (bits 0) (NoScale)
Member: 001 (offset 4) (type float) (bits 0) (NoScale)
Table: m_flLastReinforcementWave (offset 956) (type m_flLastReinforcementWave)
Member: 000 (offset 0) (type float) (bits 0) (NoScale)
Member: 001 (offset 4) (type float) (bits 0) (NoScale)
Member: m_nMaxLives (offset 964) (type integer) (bits 32) ()
Member: m_nAttackingTeam (offset 968) (type integer) (bits 32) ()
Member: m_iLevel (offset 972) (type integer) (bits 32) ()
Member: m_iTheaterTeamOne (offset 976) (type integer) (bits 8) ()
Member: m_iTheaterTeamTwo (offset 980) (type integer) (bits 8) ()
Member: m_bCounterAttack (offset 912) (type integer) (bits 1) (Unsigned)
*/
//GetConVarString(FindConVar("mp_gamemode"), sGameMode, sizeof(sGameMode));
GetEntity_GameRulesProxy(always=0) {
if (((g_iGameRulesProxy < 1) || !IsValidEntity(g_iGameRulesProxy)) || (always)) {
g_iGameRulesProxy = FindEntityByClassname(-1,"ins_rulesproxy");
GetEntityNetClass(g_iGameRulesProxy, g_iGameRulesProxyNetClass, sizeof(g_iGameRulesProxyNetClass));
InsLog(DEBUG,"g_iGameRulesProxyNetClass %s",g_iGameRulesProxyNetClass);
}
if (g_iGameRulesProxy)
return g_iGameRulesProxy;
InsLog(WARN,"GetEntity_GameRulesProxy failed!");
return -1;
}
GetEntity_PlayerManager(always=0) {
if (((g_iPlayerManagerEntity < 1) || !IsValidEntity(g_iPlayerManagerEntity)) || (always))
{
g_iPlayerManagerEntity = FindEntityByClassname(-1,"ins_player_manager");
GetEntityNetClass(g_iPlayerManagerEntity, g_iPlayerManagerEntityNetClass, sizeof(g_iPlayerManagerEntityNetClass));
InsLog(DEBUG,"g_iPlayerManagerEntityNetClass %s",g_iPlayerManagerEntityNetClass);
}
if (g_iPlayerManagerEntity)
return g_iPlayerManagerEntity;
InsLog(WARN,"GetEntity_PlayerManager failed!");
return -1;
}
// Get data for each weapon type in game. Tracks classname and id
// TODO: Get print name localization
public GetWeaponData() {
if (g_weap_array == INVALID_HANDLE) {
g_weap_array = CreateArray(MAX_DEFINABLE_WEAPONS);
for (new i;i<MAX_DEFINABLE_WEAPONS;i++) {
PushArrayString(g_weap_array, "");
}
InsLog(DEBUG,"starting LoadValues");
new String:name[32];
for(new i=0;i<= GetMaxEntities() ;i++) {
if(!IsValidEntity(i))
continue;
if(GetEdictClassname(i, name, sizeof(name))) {
if (StrContains(name,"weapon_") == 0) {
GetWeaponId(i);
}
}
}
}
}
reset_round_stats(client) {
for (new i = 1; i < sizeof(g_round_stats[]); i++)
{
g_round_stats[client][i] = 0;
}
if (IsValidClient(client))
{
InsLog(DEBUG,"Running reset_round_stats for %N",client);
g_round_stats[client][STAT_SCORE] = Ins_GetPlayerScore(client);
}
else
{
g_round_stats[client][STAT_SCORE] = 0;
}
}
reset_round_stats_all()
{
for (new i = 1; i < MaxClients; i++)
{
reset_round_stats(i);
}
}
// Get weapon id of a given weapon entity
GetWeaponId(i) {
if (i < 0) {
return -1;
}
new m_hWeaponDefinitionHandle = GetEntProp(i, Prop_Send, "m_hWeaponDefinitionHandle");
new String:name[32];
GetEdictClassname(i, name, sizeof(name));
decl String:strBuf[32];
GetArrayString(g_weap_array, m_hWeaponDefinitionHandle, strBuf, sizeof(strBuf));
if(!StrEqual(name, strBuf)) {
SetArrayString(g_weap_array, m_hWeaponDefinitionHandle, name);
InsLog(DEBUG,"Weapon %s not in trie, added as index %d", name,m_hWeaponDefinitionHandle);
}
return m_hWeaponDefinitionHandle;
}
dump_player_stats(client)
{
if (IsClientInGame(client) && IsClientConnected(client))
{
decl String: player_authid[64];
if (!GetClientAuthId(client, AuthId_Steam2, player_authid, sizeof(player_authid)))
{
strcopy(player_authid, sizeof(player_authid), "UNKNOWN");
}
new player_team_index = GetClientTeam(client);
new player_userid = GetClientUserId(client);
new is_logged;
//for (new i = 0; (i < MAX_LOG_WEAPONS); i++)
//DYNAMIC POPULATE
//for (new i = 0; i < GetArraySize(g_weap_array); i++)
for (new i = 0; i < MAX_DEFINABLE_WEAPONS; i++)
{
decl String:strBuf[32];
Ins_GetWeaponName(i, strBuf, sizeof(strBuf));
if (g_weapon_stats[client][i][LOG_HIT_HITS] > 0)
{
LogToGame("\"%N<%d><%s><%s>\" triggered \"weaponstats\" (weapon \"%s\") (shots \"%d\") (hits \"%d\") (kills \"%d\") (headshots \"%d\") (tks \"%d\") (damage \"%d\") (deaths \"%d\")",
client,
player_userid,
player_authid,
g_team_list[player_team_index],
strBuf, //g_weapon_list[i],
g_weapon_stats[client][i][LOG_HIT_SHOTS],
g_weapon_stats[client][i][LOG_HIT_HITS],
g_weapon_stats[client][i][LOG_HIT_KILLS],
g_weapon_stats[client][i][LOG_HIT_HEADSHOTS],
g_weapon_stats[client][i][LOG_HIT_TEAMKILLS],
g_weapon_stats[client][i][LOG_HIT_DAMAGE],
g_weapon_stats[client][i][LOG_HIT_DEATHS]);
LogToGame("\"%N<%d><%s><%s>\" triggered \"weaponstats2\" (weapon \"%s\") (head \"%d\") (chest \"%d\") (stomach \"%d\") (leftarm \"%d\") (rightarm \"%d\") (leftleg \"%d\") (rightleg \"%d\")",
client,
player_userid,
player_authid,
g_team_list[player_team_index],
strBuf, //g_weapon_list[i],
g_weapon_stats[client][i][LOG_HIT_HEAD],
g_weapon_stats[client][i][LOG_HIT_CHEST],
g_weapon_stats[client][i][LOG_HIT_STOMACH],
g_weapon_stats[client][i][LOG_HIT_LEFTARM],
g_weapon_stats[client][i][LOG_HIT_RIGHTARM],
g_weapon_stats[client][i][LOG_HIT_LEFTLEG],
g_weapon_stats[client][i][LOG_HIT_RIGHTLEG]);
is_logged++;
}
}
if (is_logged > 0)
{
reset_player_stats(client);
}
}
}
reset_player_stats(client)
{
//for (new i = 0; (i < MAX_LOG_WEAPONS); i++)
//DYNAMIC POPULATE
//for( new i = 0; i < GetArraySize(g_weap_array); i++)
for( new i = 0; i < MAX_DEFINABLE_WEAPONS; i++)
{
g_weapon_stats[client][i][LOG_HIT_SHOTS] = 0;
g_weapon_stats[client][i][LOG_HIT_HITS] = 0;
g_weapon_stats[client][i][LOG_HIT_KILLS] = 0;
g_weapon_stats[client][i][LOG_HIT_HEADSHOTS] = 0;
g_weapon_stats[client][i][LOG_HIT_TEAMKILLS] = 0;
g_weapon_stats[client][i][LOG_HIT_DAMAGE] = 0;
g_weapon_stats[client][i][LOG_HIT_DEATHS] = 0;
g_weapon_stats[client][i][LOG_HIT_GENERIC] = 0;
g_weapon_stats[client][i][LOG_HIT_HEAD] = 0;
g_weapon_stats[client][i][LOG_HIT_CHEST] = 0;
g_weapon_stats[client][i][LOG_HIT_STOMACH] = 0;
g_weapon_stats[client][i][LOG_HIT_LEFTARM] = 0;
g_weapon_stats[client][i][LOG_HIT_RIGHTARM] = 0;
g_weapon_stats[client][i][LOG_HIT_LEFTLEG] = 0;
g_weapon_stats[client][i][LOG_HIT_RIGHTLEG] = 0;
}
}
WstatsDumpAll()
{
for (new i = 1; i <= MaxClients; i++)
{
dump_player_stats(i);
}
}
//=====================================================================================================
GetPlayerScore(client)
{
GetEntity_PlayerManager();
new retval = -1;
if ((IsValidClient(client)) && (g_iPlayerManagerEntity > 0))
{
retval = GetEntData(g_iPlayerManagerEntity, FindSendPropInfo(g_iPlayerManagerEntityNetClass, "m_iPlayerScore") + (4 * client));
InsLog(DEBUG,"Client %N m_iPlayerScore %d",client,retval);
}
return retval;
}
public Native_Log(Handle:plugin, numParams)
{
new LOG_LEVEL:level = GetNativeCell(1);
decl String:buffer[1024];
FormatNativeString(0, 2, 3, sizeof(buffer), _,buffer);
InsLog(level,buffer);
return 0;
}
public Native_GetPlayerScore(Handle:plugin, numParams)
{
new client = GetNativeCell(1);
return GetPlayerScore(client);
}
public Native_GetPlayerClass(Handle:plugin, numParams)
{
new client = GetNativeCell(1);
if (IsValidClient(client))
{
new maxlen = GetNativeCell(3);
SetNativeString(2, g_client_last_classstring[client], maxlen+1);
}
return;
}
bool:InCounterAttack() {
//GetEntity_GameRulesProxy();
new bool:retval;
// if (retval)
// PrintToServer("PRE:InCounterAttack: TRUE");
// else
// PrintToServer("PRE:InCounterAttack: FALSE");
// if (g_iGameRulesProxy > 0) {
// retval = bool:GetEntData(g_iGameRulesProxy, FindSendPropInfo(g_iGameRulesProxyNetClass, "m_bCounterAttack"));
// }
//result = bool:GetEntData(g_iLogicEntity, FindSendPropInfo(g_iLogicEntityNetClass, "m_bCounterAttack"));
retval = bool:GameRules_GetProp("m_bCounterAttack");
// if (retval)
// PrintToServer("POST:InCounterAttack: TRUE");
// else
// PrintToServer("POST:InCounterAttack: FALSE");
return retval;
}
public Native_InCounterAttack(Handle:plugin, numParams)
{
return InCounterAttack();
}
public Native_Weapon_GetWeaponId(Handle:plugin, numParams)
{
new len;
GetNativeStringLength(1, len);
if (len <= 0)
{
return false;
}
new String:weapon_name[len+1];
decl String:strBuf[32];
GetNativeString(1, weapon_name, len+1);
GetWeaponData();
new iEntity = FindEntityByClassname(-1,weapon_name);
if (iEntity)
{
return GetWeaponId(iEntity);
}
else
{
for(new i = 0; i < MAX_DEFINABLE_WEAPONS; i++)
{
GetArrayString(g_weap_array, i, strBuf, sizeof(strBuf));
if(StrEqual(weapon_name, strBuf)) return i;
}
}
return -1;
}
public Native_Weapon_GetWeaponName(Handle:plugin, numParams)
{
new weaponid = GetNativeCell(1);
decl String:strBuf[32];
GetWeaponData();
GetArrayString(g_weap_array, weaponid, strBuf, sizeof(strBuf));
new maxlen = GetNativeCell(3);
SetNativeString(2, strBuf, maxlen+1);
}
Weapon_GetMaxClip1(weapon) {
StartPrepSDKCall(SDKCall_Entity);
if(!PrepSDKCall_SetFromConf(hGameConf, SDKConf_Virtual, "GetMaxClip1")) {
SetFailState("PrepSDKCall_SetFromConf GetMaxClip1 failed");
}
PrepSDKCall_SetReturnInfo(SDKType_PlainOldData, SDKPass_ByValue);
new Handle:hCall = EndPrepSDKCall();
new value = SDKCall(hCall, weapon);
CloseHandle(hCall);
return value;
}
Weapon_GetDefaultClip1(weapon) {
StartPrepSDKCall(SDKCall_Entity);
if(!PrepSDKCall_SetFromConf(hGameConf, SDKConf_Virtual, "GetDefaultClip1")) {
SetFailState("PrepSDKCall_SetFromConf GetDefaultClip1 failed");
}
PrepSDKCall_SetReturnInfo(SDKType_PlainOldData, SDKPass_ByValue);
new Handle:hCall = EndPrepSDKCall();
new value = SDKCall(hCall, weapon);
CloseHandle(hCall);
return value;
}
Weapon_DecrementAmmo(weapon, value) {
StartPrepSDKCall(SDKCall_Entity);
if(!PrepSDKCall_SetFromConf(hGameConf, SDKConf_Virtual, "CINSWeapon::DecrementAmmo")) {
SetFailState("PrepSDKCall_SetFromConf CINSWeapon::DecrementAmmo failed");
}
PrepSDKCall_AddParameter(SDKType_PlainOldData, SDKPass_Plain);
//PrepSDKCall_SetReturnInfo(SDKType_PlainOldData, SDKPass_ByValue);
new Handle:hCall = EndPrepSDKCall();
SDKCall(hCall, weapon, value);
CloseHandle(hCall);
}
Weapon_Player_AddMags(client, ammo) {
StartPrepSDKCall(SDKCall_Player);
if(!PrepSDKCall_SetFromConf(hGameConf, SDKConf_Signature, "AddMags")) {
SetFailState("PrepSDKCall_SetFromConf CINSWeapon::DecrementAmmo failed");
}
PrepSDKCall_AddParameter(SDKType_PlainOldData, SDKPass_Plain);
//PrepSDKCall_SetReturnInfo(SDKType_PlainOldData, SDKPass_ByValue);
new Handle:hCall = EndPrepSDKCall();
SDKCall(hCall, client, ammo);
CloseHandle(hCall);
}
public Native_Weapon_GetMaxClip1(Handle:plugin, numParams) {
new weapon = GetNativeCell(1);
return Weapon_GetMaxClip1(weapon);
}
public Native_Weapon_GetDefaultClip1(Handle:plugin, numParams) {
new weapon = GetNativeCell(1);
return Weapon_GetDefaultClip1(weapon);
}
public Native_Weapon_DecrementAmmo(Handle:plugin, numParams) {
new weapon = GetNativeCell(1);
new ammo = GetNativeCell(2);
Weapon_DecrementAmmo(weapon, ammo);
}
public Native_Player_AddMags(Handle:plugin, numParams) {
new client = GetNativeCell(1);
new ammo = GetNativeCell(2);
Weapon_Player_AddMags(client, ammo);
}
public Native_ObjectiveResource_GetProp(Handle:plugin, numParams)
{
new len;
GetNativeStringLength(1, len);
if (len <= 0)
{
return false;
}
new String:prop[len+1],retval=-1;
GetNativeString(1, prop, len+1);
new size = GetNativeCell(2);
new element = GetNativeCell(3);
GetEntity_ObjectiveResource();
if (g_iObjResEntity > 0)
{
retval = GetEntData(g_iObjResEntity, FindSendPropInfo(g_iObjResEntityNetClass, prop) + (size * element));
}
return retval;
}
public Native_ObjectiveResource_GetPropFloat(Handle:plugin, numParams)
{
new len;
GetNativeStringLength(1, len);
if (len <= 0)
{
return false;
}
new String:prop[len+1],Float:retval=-1.0;
GetNativeString(1, prop, len+1);
new size = GetNativeCell(2);
new element = GetNativeCell(3);
GetEntity_ObjectiveResource();
if (g_iObjResEntity > 0)
{
retval = Float:GetEntData(g_iObjResEntity, FindSendPropInfo(g_iObjResEntityNetClass, prop) + (size * element));
}
return _:retval;
}
public Native_ObjectiveResource_GetPropEnt(Handle:plugin, numParams)
{
new len;
GetNativeStringLength(1, len);
if (len <= 0)
{
return false;
}
new String:prop[len+1],retval=-1;
GetNativeString(1, prop, len+1);
new element = GetNativeCell(2);
GetEntity_ObjectiveResource();
if (g_iObjResEntity > 0)
{
retval = GetEntData(g_iObjResEntity, FindSendPropInfo(g_iObjResEntityNetClass, prop) + (4 * element));
}
return retval;
}
public Native_ObjectiveResource_GetPropBool(Handle:plugin, numParams)
{
new len;
GetNativeStringLength(1, len);
if (len <= 0)
{
return false;
}
new String:prop[len+1],retval=-1;
GetNativeString(1, prop, len+1);
new element = GetNativeCell(2);
GetEntity_ObjectiveResource();
if (g_iObjResEntity > 0)
{
retval = bool:GetEntData(g_iObjResEntity, FindSendPropInfo(g_iObjResEntityNetClass, prop) + (element));
}
return _:retval;
}
public Native_ObjectiveResource_GetPropVector(Handle:plugin, numParams) {
new len;
GetNativeStringLength(1, len);
if (len <= 0) {
return false;
}
new String:prop[len+1];
new size = 12; // Size of data slice - 3x4-byte floats
GetNativeString(1, prop, len+1);
new element = GetNativeCell(3);
GetEntity_ObjectiveResource();
new Float:result[3];
if (g_iObjResEntity > 0) {
GetEntDataVector(g_iObjResEntity, FindSendPropInfo(g_iObjResEntityNetClass, prop) + (size * element), result);
SetNativeArray(2, result, 3);
}
return 1;
}
public Native_ObjectiveResource_GetPropString(Handle:plugin, numParams)
{
new len;
GetNativeStringLength(1, len);
if (len <= 0)
{
return false;
}
new String:prop[len+1],retval=-1;
GetNativeString(1, prop, len+1);
/*
new maxlen = GetNativeCell(3);
GetEntity_ObjectiveResource();
if (g_iObjResEntity > 0)
{
//SetNativeString(2, buffer, maxlen+1);
//GetEntData(g_iObjResEntity, FindSendPropInfo(g_iObjResEntityNetClass, prop) + (size * element));
}
*/
return retval;
}
public CheckInfiniteAmmo(client)
{
if (GetConVarBool(cvarInfiniteAmmo))
{
new weapon = GetEntPropEnt(client, Prop_Data, "m_hActiveWeapon");
new m_iPrimaryAmmoType = GetEntProp(weapon, Prop_Send, "m_iPrimaryAmmoType");
new m_iClip1 = GetEntProp(weapon, Prop_Send, "m_iClip1"); // weapon clip amount bullets
new m_iAmmo_prim = GetEntProp(client, Prop_Send, "m_iAmmo", _, m_iPrimaryAmmoType); // Player ammunition for this weapon ammo type
new m_iPrimaryAmmoCount = -1;//GetEntProp(weapon, Prop_Send, "m_iPrimaryAmmoCount");
InsLog(DEBUG,"weapon %d m_iPrimaryAmmoType %d m_iClip1 %d m_iAmmo_prim %d m_iPrimaryAmmoCount %d",weapon,m_iPrimaryAmmoType,m_iClip1,m_iAmmo_prim,m_iPrimaryAmmoCount);
SetEntProp(client, Prop_Send, "m_iAmmo", 99, _, m_iPrimaryAmmoType); // Set player ammunition of this weapon primary ammo type
//new ammo = GetEntProp(ActiveWeapon, Prop_Send, "m_iClip1", 1);
}
if (GetConVarBool(cvarInfiniteMagazine))
{
new ActiveWeapon = GetEntPropEnt(client, Prop_Data, "m_hActiveWeapon");
new maxammo = Ins_GetMaxClip1(ActiveWeapon);
SetEntProp(ActiveWeapon, Prop_Send, "m_iClip1", maxammo);
}
}
//=====================================================================================================
// Disable sliding
public Action:OnPlayerRunCmd(client, &buttons, &impulse, Float:vel[3], Float:angles[3], &weapon)
{
if ((GetConVarInt(cvarDisableSliding) == 1) || (GetClientTeam(client) == GetConVarInt(cvarDisableSliding)))
{
if (buttons & IN_ATTACK || buttons & IN_ATTACK2)
{
if (GetEntProp(client, Prop_Send, "m_bWasSliding") == 1)
return Plugin_Handled;
}
}
return Plugin_Continue;
}
public Action:Event_ControlPointCapturedPre(Handle:event, const String:name[], bool:dontBroadcast)
{
if (!GetConVarBool(cvarEnabled))
{
return Plugin_Continue;
}
//"priority" "short"
//"cp" "byte"
//"cappers" "string"
//"cpname" "string"
//"team" "byte"
/*
decl String:cappers[256];
//new priority = GetEventInt(event, "priority");
GetEventString(event, "cappers", cappers, sizeof(cappers));
new team = GetEventInt(event, "team");
new capperlen = GetCharBytes(cappers);
if ((InCounterAttack()) && (team == 3) && (!GetConVarBool(cvarCheckpointCounterattackCapture)))
{
InsLog(DEBUG,"Event_ControlPointCaptured: Want to block CounterAttack Capture!");
//return Plugin_Stop;
}
new Float:ratio = (Float:capperlen / Float:Team_CountAlivePlayers(team));
new Float:goalratio = GetConVarFloat(cvarCheckpointCapturePlayerRatio);
//InsLog(DEBUG,"Event_ControlPointCaptured ratio %0.2f (%d of %d) goalratio %0.2f",ratio,capperlen,Team_CountAlivePlayers(team),goalratio);
if (ratio < goalratio)
{
InsLog(DEBUG,"Event_ControlPointCaptured Blocking due to insufficient friendly players!");
//return Plugin_Stop;
}
*/
return Plugin_Continue;
}
public Action:Event_ControlPointCaptured(Handle:event, const String:name[], bool:dontBroadcast)
{
if (!GetConVarBool(cvarEnabled))
{
return Plugin_Continue;
}
//"priority" "short"
//"cp" "byte"
//"cappers" "string"
//"cpname" "string"
//"team" "byte"
decl String:cappers[256],String:cpname[64];
//new priority = GetEventInt(event, "priority");
new cp = GetEventInt(event, "cp");
GetEventString(event, "cappers", cappers, sizeof(cappers));
GetEventString(event, "cpname", cpname, sizeof(cpname));
new team = GetEventInt(event, "team");
new capperlen = GetCharBytes(cappers);
InsLog(DEBUG,"Event_ControlPointCaptured cp %d capperlen %d cpname %s team %d", cp,capperlen,cpname,team);
//"cp" "byte" - for naming, currently not needed
for (new i = 0; i < strlen(cappers); i++)
{
new client = cappers[i];
//InsLog(DEBUG,"Event_ControlPointCaptured parsing capper id %d client %d",i,client);
if(client > 0 && client <= MaxClients && IsClientInGame(client))
{
decl String:player_authid[64];
if (!GetClientAuthId(client, AuthId_Steam2, player_authid, sizeof(player_authid)))
{
strcopy(player_authid, sizeof(player_authid), "UNKNOWN");
}
new player_userid = GetClientUserId(client);
new player_team_index = GetClientTeam(client);
g_round_stats[client][STAT_CAPTURES]++;
LogToGame("\"%N<%d><%s><%s>\" triggered \"ins_cp_captured\"", client, player_userid, player_authid, g_team_list[player_team_index]);
}
}
return Plugin_Continue;
}
public Action:Event_ControlPointNeutralized(Handle:event, const String:name[], bool:dontBroadcast)
{
if (!GetConVarBool(cvarEnabled))
{
return Plugin_Continue;
}
//"priority" "short"
//"cp" "byte"
//"cappers" "string"
//"cpname" "string"
//"team" "byte"
decl String:cappers[256],String:cpname[64];
//new priority = GetEventInt(event, "priority");
//new cp = GetEventInt(event, "cp");
GetEventString(event, "cappers", cappers, sizeof(cappers));
GetEventString(event, "cpname", cpname, sizeof(cpname));