forked from zzzznn5000/bTimes-csgo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbTimes-timer.sp
More file actions
3823 lines (3218 loc) · 120 KB
/
bTimes-timer.sp
File metadata and controls
3823 lines (3218 loc) · 120 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#pragma semicolon 1
#include <bTimes-core>
public Plugin:myinfo =
{
name = "[bTimes] Timer",
author = "blacky",
description = "The timer portion of the bTimes plugin",
version = VERSION,
url = "http://steamcommunity.com/id/blaackyy/"
}
#include <sourcemod>
#include <bTimes-zones>
#include <bTimes-timer>
#include <bTimes-ranks>
#include <bTimes-random>
#include <sdktools>
#include <sdkhooks>
#include <smlib/entities>
#include <cstrike>
#include <clientprefs>
#undef REQUIRE_PLUGIN
#include <bTimes-ghost>
// database
new Handle:g_DB;
// Current map info
new String:g_sMapName[64],
Handle:g_MapList;
// Player timer info
new Float:g_fCurrentTime[MAXPLAYERS + 1],
bool:g_bTiming[MAXPLAYERS + 1];
new g_StyleConfig[32][StyleConfig];
new g_TotalStyles;
new g_Type[MAXPLAYERS + 1];
new g_Style[MAXPLAYERS + 1][MAX_TYPES];
new bool:g_bTimeIsLoaded[MAXPLAYERS + 1],
Float:g_fTime[MAXPLAYERS + 1][MAX_TYPES][MAX_STYLES],
String:g_sTime[MAXPLAYERS + 1][MAX_TYPES][MAX_STYLES][64];
new g_Strafes[MAXPLAYERS + 1],
g_Jumps[MAXPLAYERS + 1],
g_SWStrafes[MAXPLAYERS + 1][2],
Float:g_HSWCounter[MAXPLAYERS + 1],
Float:g_fSpawnTime[MAXPLAYERS + 1];
new Float:g_fNoClipSpeed[MAXPLAYERS + 1];
new g_Buttons[MAXPLAYERS + 1],
g_UnaffectedButtons[MAXPLAYERS + 1];
new bool:g_bPaused[MAXPLAYERS + 1],
Float:g_fPauseTime[MAXPLAYERS + 1],
Float:g_fPausePos[MAXPLAYERS + 1][3];
new Float:g_Fps[MAXPLAYERS + 1];
new String:g_msg_start[128],
String:g_msg_varcol[128],
String:g_msg_textcol[128];
// Warning
new Float:g_fWarningTime[MAXPLAYERS + 1];
// Sync measurement
new Float:g_fOldAngle[MAXPLAYERS + 1],
g_totalSync[MAXPLAYERS + 1],
g_goodSync[MAXPLAYERS + 1],
g_goodSyncVel[MAXPLAYERS + 1];
// Hint text
new Float:g_WorldRecord[MAX_TYPES][MAX_STYLES];
new String:g_sRecord[MAX_TYPES][MAX_STYLES][64];
// Cvars
new Handle:g_hTimerDisplay,
Handle:g_hHintSpeed,
Handle:g_hAllowYawspeed,
Handle:g_hAllowPause,
Handle:g_hChangeClanTag,
Handle:g_hTimerChangeClanTag,
Handle:g_hAllowNoClip,
Handle:g_hVelocityCap,
bool:g_bAllowVelocityCap,
Handle:g_hAllowAuto,
bool:g_bAllowAuto,
Handle:g_hJumpInStartZone,
bool:g_bJumpInStartZone,
Handle:g_hAutoStopsTimer,
bool:g_bAutoStopsTimer;
// All map times
new Handle:g_hTimes[MAX_TYPES][MAX_STYLES],
Handle:g_hTimesUsers[MAX_TYPES][MAX_STYLES],
bool:g_bTimesAreLoaded;
// Forwards
new Handle:g_fwdOnTimerFinished_Pre,
Handle:g_fwdOnTimerFinished_Post,
Handle:g_fwdOnTimerStart_Pre,
Handle:g_fwdOnTimerStart_Post,
Handle:g_fwdOnTimesDeleted,
Handle:g_fwdOnTimesUpdated,
Handle:g_fwdOnStylesLoaded,
Handle:g_fwdOnTimesLoaded,
Handle:g_fwdOnStyleChanged;
new Handle:g_ConVar_AirAccelerate,
Handle:g_ConVar_EnableBunnyhopping;
ConVar g_ConVar_Autobunnyhopping;
// Admin
new bool:g_bIsAdmin[MAXPLAYERS + 1];
bool JumpButtonsFix[65] = false;
int g_iStartCycle = 0;
char g_sStartColors[][] =
{
"00FF00", "00E000", "00D000", "00C000", "00B000", "00A000", "009000", "008000", "007000", "006000", "005000", "004000", "003000", "002000", "001000", "002000", "003000", "004000", "005000", "006000", "007000", "008000", "009000", "00A000", "00B000", "00C000", "00D000", "00E000", "00FF00"
};
int g_iBStartCycle = 0;
char g_sBStartColors[][] =
{
"00FFFF", "00FFFF", "00FFFF", "00FFFF", "00E5E5", "00CCCC", "00B2B2", "009999", "007F7F", "006666", "004C4C", "003333", "001919", "001111", "000707", "001111", "001919", "003333", "004C4C", "006666", "007F7F", "009999", "00B2B2", "00CCCC", "00E5E5", "00FFFF", "00FFFF", "00FFFF", "00FFFF"
};
int g_iNoTimerCycle = 0;
char g_sNoTimerColors[][] =
{
"FF0000", "E00000", "D00000", "C00000", "B00000", "A00000", "900000", "800000", "700000", "600000", "500000", "400000", "300000", "200000", "100000", "200000", "300000", "400000", "500000", "600000", "700000", "800000", "900000", "A00000", "B00000", "C00000", "D00000", "E00000", "FF0000"
};
int g_iPauseCycle = 0;
char g_sPauseColors[][] =
{
"CC6600", "C26100", "B85C00", "AD5700", "A35200", "994C00", "8F4700", "854200", "7A3D00", "703800", "663300", "5C2E00", "522900", "472400", "3D1F00", "331A00", "291400", "1F0F00", "140A00", "0A0500", "000000", "0A0500", "140A00", "1F0F00", "291400", "331A00", "3D1F00", "472400", "522900", "5C2E00", "663300", "703800", "7A3D00", "854200", "8F4700", "994C00", "A35200", "AD5700", "B85C00", "C26100", "CC6600"
};
public OnPluginStart()
{
// Connect to the database
DB_Connect();
// Server cvars
g_hHintSpeed = CreateConVar("timer_hintspeed", "0.1", "Changes the hint text update speed (bottom center text)", 0, true, 0.1);
g_hAllowYawspeed = CreateConVar("timer_allowyawspeed", "0", "Lets players use +left/+right commands without stopping their timer.", 0, true, 0.0, true, 1.0);
g_hAllowPause = CreateConVar("timer_allowpausing", "1", "Lets players use the !pause/!unpause commands.", 0, true, 0.0, true, 1.0);
g_hChangeClanTag = CreateConVar("timer_changeclantag", "1", "Means player clan tags will show their current timer time.", 0, true, 0.0, true, 1.0);
g_hAllowNoClip = CreateConVar("timer_noclip", "1", "Allows players to use the !p commands to noclip themselves.", 0, true, 0.0, true, 1.0);
g_hVelocityCap = CreateConVar("timer_velocitycap", "1", "Allows styles with a max velocity cap to cap player velocity.", 0, true, 0.0, true, 1.0);
g_hJumpInStartZone = CreateConVar("timer_allowjumpinstart", "1", "Allows players to jump in the start zone. (This is not exactly anti-prespeed)", 0, true, 0.0, true, 1.0);
g_hAllowAuto = CreateConVar("timer_allowauto", "1", "Allows players to use auto bunnyhop.", 0, true, 0.0, true, 1.0);
g_hAutoStopsTimer = CreateConVar("timer_autostopstimer", "0", "Players can't get times with autohop on.");
HookConVarChange(g_hHintSpeed, OnTimerHintSpeedChanged);
HookConVarChange(g_hChangeClanTag, OnChangeClanTagChanged);
HookConVarChange(g_hVelocityCap, OnVelocityCapChanged);
HookConVarChange(g_hAutoStopsTimer, OnAutoStopsTimerChanged);
HookConVarChange(g_hAllowAuto, OnAllowAutoChanged);
HookConVarChange(g_hJumpInStartZone, OnAllowJumpInStartZoneChanged);
AutoExecConfig(true, "timer", "timer");
// Event hooks
HookEvent("player_death", Event_PlayerDeath, EventHookMode_Pre);
HookEvent("player_team", Event_PlayerTeam, EventHookMode_Pre);
HookEvent("player_spawn", Event_PlayerSpawn, EventHookMode_Pre);
HookEvent("player_jump", Event_PlayerJump, EventHookMode_Pre);
HookEvent("player_jump", Event_PlayerJump_Post, EventHookMode_Post);
// Admin commands
RegAdminCmd("sm_delete", SM_Delete, ADMFLAG_CHEATS, "Deletes map times.");
RegAdminCmd("sm_spj", SM_SPJ, ADMFLAG_GENERIC, "Check the strafes per jump ratios for any player.");
RegAdminCmd("sm_enablestyle", SM_EnableStyle, ADMFLAG_RCON, "Enables a style for players to use. (Resets to default setting on map change)");
RegAdminCmd("sm_disablestyle", SM_DisableStyle, ADMFLAG_RCON, "Disables a style so players can no longer use it. (Resets to default setting on map change)");
// Player commands
RegConsoleCmdEx("sm_stop", SM_StopTimer, "Stops your timer.");
RegConsoleCmdEx("sm_style", SM_Style, "Change your style.");
RegConsoleCmdEx("sm_mode", SM_Style, "Change your style.");
RegConsoleCmdEx("sm_bstyle", SM_BStyle, "Change your bonus style.");
RegConsoleCmdEx("sm_bmode", SM_BStyle, "Change your bonus style.");
RegConsoleCmdEx("sm_practice", SM_Practice, "Puts you in noclip. Stops your timer.");
RegConsoleCmdEx("sm_p", SM_Practice, "Puts you in noclip. Stops your timer.");
RegConsoleCmdEx("sm_noclipme", SM_Practice, "Puts you in noclip. Stops your timer.");
RegConsoleCmdEx("sm_truevel", SM_TrueVelocity, "Toggles between 2D and 3D velocity velocity meters");
RegConsoleCmdEx("sm_velocity", SM_TrueVelocity, "Toggles between 2D and 3D velocity velocity meters");
RegConsoleCmdEx("sm_pause", SM_Pause, "Pauses your timer and freezes you.");
RegConsoleCmdEx("sm_unpause", SM_Unpause, "Unpauses your timer and unfreezes you.");
RegConsoleCmdEx("sm_resume", SM_Unpause, "Unpauses your timer and unfreezes you.");
RegConsoleCmdEx("sm_fps", SM_Fps, "Shows a list of every player's fps_max value.");
RegConsoleCmdEx("sm_auto", SM_Auto, "Toggles auto bunnyhop.");
RegConsoleCmdEx("sm_bhop", SM_Auto, "Toggles auto bunnyhop.");
RegAdminCmd("sm_reloadstyle", SM_ReloadStyle, ADMFLAG_ROOT, "Reload Style Config.");
// Makes FindTarget() work properly
LoadTranslations("common.phrases");
for(new Type; Type < MAX_TYPES; Type++)
{
for(new Style; Style < MAX_STYLES; Style++)
{
g_hTimes[Type][Style] = CreateArray(2);
g_hTimesUsers[Type][Style] = CreateArray(ByteCountToCells(MAX_NAME_LENGTH));
}
}
g_ConVar_AirAccelerate = FindConVar( "sv_airaccelerate" );
if ( g_ConVar_AirAccelerate == INVALID_HANDLE )
SetFailState( "Unable to find cvar handle for sv_airaccelerate!" );
new flags = GetConVarFlags( g_ConVar_AirAccelerate );
flags &= ~FCVAR_NOTIFY;
//flags &= ~FCVAR_REPLICATED;
SetConVarFlags( g_ConVar_AirAccelerate, flags );
g_ConVar_EnableBunnyhopping = FindConVar( "sv_enablebunnyhopping" );
if ( g_ConVar_EnableBunnyhopping == INVALID_HANDLE )
SetFailState( "Unable to find cvar handle for sv_enablebunnyhopping!" );
flags = GetConVarFlags( g_ConVar_EnableBunnyhopping );
flags &= ~FCVAR_NOTIFY;
flags &= ~FCVAR_REPLICATED;
SetConVarFlags( g_ConVar_EnableBunnyhopping, flags );
g_ConVar_Autobunnyhopping = FindConVar( "sv_autobunnyhopping" );
SetConVarFlags(g_ConVar_EnableBunnyhopping, FCVAR_NOTIFY);
CreateTimer(0.1, UpdateHUD_Timer, INVALID_HANDLE, TIMER_REPEAT);
}
public OnAllPluginsLoaded()
{
ReadStyleConfig();
}
public APLRes:AskPluginLoad2(Handle:myself, bool:late, String:error[], err_max)
{
// Natives
CreateNative("StartTimer", Native_StartTimer);
CreateNative("StopTimer", Native_StopTimer);
CreateNative("IsBeingTimed", Native_IsBeingTimed);
CreateNative("FinishTimer", Native_FinishTimer);
CreateNative("GetClientStyle", Native_GetClientStyle);
CreateNative("IsTimerPaused", Native_IsTimerPaused);
CreateNative("GetStyleName", Native_GetStyleName);
CreateNative("GetStyleAbbr", Native_GetStyleAbbr);
CreateNative("Style_IsEnabled", Native_Style_IsEnabled);
CreateNative("Style_IsTypeAllowed", Native_Style_IsTypeAllowed);
CreateNative("Style_IsFreestyleAllowed", Native_Style_IsFreestyleAllowed);
CreateNative("Style_GetTotal", Native_Style_GetTotal);
CreateNative("Style_CanUseReplay", Native_Style_CanUseReplay);
CreateNative("Style_CanReplaySave", Native_Style_CanReplaySave);
CreateNative("GetTypeStyleFromCommand", Native_GetTypeStyleFromCommand);
CreateNative("GetClientTimerType", Native_GetClientTimerType);
CreateNative("Style_GetConfig", Native_GetStyleConfig);
CreateNative("Timer_GetButtons", Native_GetButtons);
//CreateNative("Timer_OpenStatsMenu", Native_OpenStatsMenu);
// Forwards
g_fwdOnTimerStart_Pre = CreateGlobalForward("OnTimerStart_Pre", ET_Hook, Param_Cell, Param_Cell, Param_Cell);
g_fwdOnTimerStart_Post = CreateGlobalForward("OnTimerStart_Post", ET_Event, Param_Cell, Param_Cell, Param_Cell);
g_fwdOnTimerFinished_Pre = CreateGlobalForward("OnTimerFinished_Pre", ET_Hook, Param_Cell, Param_Cell, Param_Cell);
g_fwdOnTimerFinished_Post = CreateGlobalForward("OnTimerFinished_Post", ET_Event, Param_Cell, Param_Float, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell);
g_fwdOnTimesDeleted = CreateGlobalForward("OnTimesDeleted", ET_Event, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Any);
g_fwdOnTimesUpdated = CreateGlobalForward("OnTimesUpdated", ET_Event, Param_String, Param_Cell, Param_Cell, Param_Any);
g_fwdOnStylesLoaded = CreateGlobalForward("OnStylesLoaded", ET_Event);
g_fwdOnTimesLoaded = CreateGlobalForward("OnMapTimesLoaded", ET_Event);
g_fwdOnStyleChanged = CreateGlobalForward("OnStyleChanged", ET_Event, Param_Cell, Param_Cell, Param_Cell, Param_Cell);
return APLRes_Success;
}
public OnMapStart()
{
// Set the map id
GetCurrentMap(g_sMapName, sizeof(g_sMapName));
if(g_MapList != INVALID_HANDLE)
{
CloseHandle(g_MapList);
}
g_MapList = ReadMapList();
g_bTimesAreLoaded = false;
decl String:sTypeAbbr[32], String:sStyleAbbr[32];
for(new Type; Type < MAX_TYPES; Type++)
{
GetTypeAbbr(Type, sTypeAbbr, sizeof(sTypeAbbr), true);
for(new Style; Style < g_TotalStyles; Style++)
{
GetStyleAbbr(Style, sStyleAbbr, sizeof(sStyleAbbr), true);
FormatEx(g_sRecord[Type][Style], sizeof(g_sRecord[][]), "%sW%s: No Record", sTypeAbbr, sStyleAbbr);
}
}
}
public OnStylesLoaded()
{
RegConsoleCmdPerStyle("wr", SM_WorldRecord, "Show the world record info for {Type} timer on {Style} style.");
RegConsoleCmdPerStyle("time", SM_Time, "Show your time for {Type} timer on {Style} style.");
decl String:sType[32], String:sStyle[32], String:sTypeAbbr[32], String:sStyleAbbr[32], String:sCommand[64], String:sDescription[256];
for(new Type; Type < MAX_TYPES; Type++)
{
GetTypeName(Type, sType, sizeof(sType));
GetTypeAbbr(Type, sTypeAbbr, sizeof(sTypeAbbr), true);
for(new Style; Style < g_TotalStyles; Style++)
{
if(Style_IsEnabled(Style) && g_StyleConfig[Style][AllowType][Type])
{
GetStyleName(Style, sStyle, sizeof(sStyle));
GetStyleAbbr(Style, sStyleAbbr, sizeof(sStyleAbbr));
FormatEx(sCommand, sizeof(sCommand), "sm_%s%s", sTypeAbbr, sStyleAbbr);
FormatEx(sDescription, sizeof(sDescription), "Set your style to %s on the %s timer.", sStyle, sType);
if(Type == TIMER_MAIN)
RegConsoleCmdEx(sCommand, SM_SetStyle, sDescription);
else if(Type == TIMER_BONUS)
RegConsoleCmdEx(sCommand, SM_SetBonusStyle, sDescription);
}
}
}
}
public OnStyleChanged(client, oldStyle, newStyle, type)
{
new oldAA = g_StyleConfig[oldStyle][AirAcceleration];
new newAA = g_StyleConfig[newStyle][AirAcceleration];
if(oldAA != newAA)
{
CPrintToChat(client, "%s%sYour airacceleration has been set to %s%d%s.",
g_msg_start,
g_msg_textcol,
g_msg_varcol,
newAA,
g_msg_textcol);
}
}
public OnConfigsExecuted()
{
// Reset temporary enabled and disabled styles
for(new Style; Style < g_TotalStyles; Style++)
{
g_StyleConfig[Style][TempEnabled] = g_StyleConfig[Style][Enabled];
}
if(GetConVarInt(g_hChangeClanTag) == 0)
{
KillTimer(g_hTimerChangeClanTag);
}
else
{
g_hTimerChangeClanTag = CreateTimer(1.0, SetClanTag, _, TIMER_FLAG_NO_MAPCHANGE | TIMER_REPEAT);
}
g_hTimerDisplay = CreateTimer(GetConVarFloat(g_hHintSpeed), Timer_DrawHintText, _, TIMER_FLAG_NO_MAPCHANGE | TIMER_REPEAT);
g_bAllowVelocityCap = GetConVarBool(g_hVelocityCap);
g_bAllowAuto = GetConVarBool(g_hAllowAuto);
g_bAutoStopsTimer = GetConVarBool(g_hAutoStopsTimer);
g_bJumpInStartZone = GetConVarBool(g_hJumpInStartZone);
ExecMapConfig();
}
public bool:OnClientConnect(client)
{
for(new Type; Type < MAX_TYPES; Type++)
{
for(new Style; Style < MAX_STYLES; Style++)
{
g_fTime[client][Type][Style] = 0.0;
FormatEx(g_sTime[client][Type][Style], sizeof(g_sTime[][][]), "Best: Loading..");
}
}
// Set player times to null
g_bTimeIsLoaded[client] = false;
// Unpause timers
g_bPaused[client] = false;
// Reset noclip speed
g_fNoClipSpeed[client] = 1.0;
// Set style to first available style for each timer type
for(new Type; Type < MAX_TYPES; Type++)
{
for(new Style; Style < MAX_STYLES; Style++)
{
if(Style_IsEnabled(Style) && g_StyleConfig[Style][AllowType][Type])
{
g_Style[client][Type] = Style;
break;
}
}
}
g_bIsAdmin[client] = false;
g_fNoClipSpeed[client] = 1.0;
return true;
}
public OnClientPutInServer(client)
{
QueryClientConVar(client, "fps_max", OnFpsMaxRetrieved);
SDKHook(client, SDKHook_PreThink, Hook_PreThink);
}
public Hook_PreThink(client)
{
if(!IsFakeClient(client))
{
SetConVarInt(g_ConVar_AirAccelerate, g_StyleConfig[g_Style[client][g_Type[client]]][AirAcceleration]);
SetConVarBool(g_ConVar_EnableBunnyhopping, g_StyleConfig[g_Style[client][g_Type[client]]][EnableBunnyhopping]);
}
}
public OnFpsMaxRetrieved(QueryCookie:cookie, client, ConVarQueryResult:result, const String:cvarName[], const String:cvarValue[])
{
g_Fps[client] = StringToFloat(cvarValue);
if(g_Fps[client] > 1000)
g_Fps[client] = 1000.0;
}
public OnClientPostAdminCheck(client)
{
g_bIsAdmin[client] = GetAdminFlag(GetUserAdmin(client), Admin_Generic, Access_Effective);
}
public OnPlayerIDLoaded(client)
{
if(g_bTimesAreLoaded == true)
{
DB_LoadPlayerInfo(client);
}
}
public OnTimerChatChanged(MessageType, String:Message[])
{
if(MessageType == 0)
{
Format(g_msg_start, sizeof(g_msg_start), Message);
}
else if(MessageType == 1)
{
Format(g_msg_varcol, sizeof(g_msg_varcol), Message);
}
else if(MessageType == 2)
{
Format(g_msg_textcol, sizeof(g_msg_textcol), Message);
}
}
public OnZonesLoaded()
{
DB_LoadTimes(true);
}
public OnTimerHintSpeedChanged(Handle:convar, const String:oldValue[], const String:newValue[])
{
KillTimer(g_hTimerDisplay);
g_hTimerDisplay = CreateTimer(GetConVarFloat(convar), Timer_DrawHintText, _, TIMER_FLAG_NO_MAPCHANGE | TIMER_REPEAT);
}
public OnChangeClanTagChanged(Handle:convar, const String:oldValue[], const String:newValue[])
{
if(GetConVarInt(convar) == 0)
{
KillTimer(g_hTimerChangeClanTag);
}
else
{
g_hTimerChangeClanTag = CreateTimer(1.0, SetClanTag, _, TIMER_FLAG_NO_MAPCHANGE | TIMER_REPEAT);
}
}
public OnVelocityCapChanged(Handle:convar, const String:oldValue[], const String:newValue[])
{
g_bAllowVelocityCap = bool:StringToInt(newValue);
}
public OnAutoStopsTimerChanged(Handle:convar, const String:oldValue[], const String:newValue[])
{
if(StringToInt(newValue) == 1)
{
for(new client = 1; client <= MaxClients; client++)
{
if(IsClientInGame(client) && IsBeingTimed(client, TIMER_ANY) && (GetClientSettings(client) & AUTO_BHOP))
{
StopTimer(client);
}
}
}
}
public OnAllowJumpInStartZoneChanged(Handle:convar, const String:oldValue[], const String:newValue[])
{
g_bJumpInStartZone = bool:StringToInt(newValue);
}
public OnAllowAutoChanged(Handle:convar, const String:oldValue[], const String:newValue[])
{
g_bAllowAuto = bool:StringToInt(newValue);
}
public Action:Event_PlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
{
new client = GetClientOfUserId(GetEventInt(event, "userid"));
// Player timers should stop when they die
StopTimer(client);
}
public Action:Event_PlayerTeam(Handle:event, const String:name[], bool:dontBroadcast)
{
new client = GetClientOfUserId(GetEventInt(event, "userid"));
// Player timers should stop when they switch teams
StopTimer(client);
}
public Action:Event_PlayerSpawn(Handle:event, const String:name[], bool:dontBroadcast)
{
new client = GetClientOfUserId(GetEventInt(event, "userid"));
// Anti-time-cheat
g_fSpawnTime[client] = GetEngineTime();
// Player timers should stop when they spawn
StopTimer(client);
}
public Action:Event_PlayerJump(Handle:event, const String:name[], bool:dontBroadcast)
{
new client = GetClientOfUserId(GetEventInt(event, "userid"));
// Increase jump count for the hud hint text, it resets to 0 when StartTimer for the client is called
if(g_bTiming[client] == true)
{
g_Jumps[client]++;
}
new Style = g_Style[client][g_Type[client]];
if(g_StyleConfig[Style][EzHop] == true)
{
SetEntPropFloat(client, Prop_Send, "m_flStamina", 0.0);
}
else if(g_StyleConfig[Style][Freestyle] && g_StyleConfig[Style][Freestyle_EzHop])
{
if(Timer_InsideZone(client, FREESTYLE, 1 << Style) != -1)
{
SetEntPropFloat(client, Prop_Send, "m_flStamina", 0.0);
}
}
}
public Action:Event_PlayerJump_Post(Handle:event, const String:name[], bool:dontBroadcast)
{
// Check max velocity on player jump event rather than OnPlayerRunCmd, rewards better strafing
if(g_bAllowVelocityCap == true)
{
new client = GetClientOfUserId(GetEventInt(event, "userid"));
new Style = g_Style[client][g_Type[client]];
if(g_bAllowVelocityCap == true && g_StyleConfig[Style][MaxVel] != 0.0)
{
// Has to be on next game frame, TeleportEntity doesn't seem to work in event player_jump
CreateTimer(0.0, Timer_CheckVel, client);
}
}
}
public Action:Timer_CheckVel(Handle:timer, any:client)
{
new Style = g_Style[client][g_Type[client]];
new Float:fVel = GetClientVelocity(client, true, true, false);
if(fVel > g_StyleConfig[Style][MaxVel])
{
new Float:vVel[3];
Entity_GetAbsVelocity(client, vVel);
new Float:fTemp = vVel[2];
ScaleVector(vVel, g_StyleConfig[Style][MaxVel]/fVel);
vVel[2] = fTemp;
TeleportEntity(client, NULL_VECTOR, NULL_VECTOR, vVel);
}
}
public Action:UpdateHUD_Timer(Handle:timer)
{
g_iStartCycle++;
g_iBStartCycle++;
g_iNoTimerCycle++;
g_iPauseCycle++;
if(g_iStartCycle > (sizeof(g_sStartColors) - 1))
{
g_iStartCycle = 0;
}
if(g_iBStartCycle > (sizeof(g_sBStartColors) - 1))
{
g_iBStartCycle = 0;
}
if(g_iNoTimerCycle > (sizeof(g_sNoTimerColors) - 1))
{
g_iNoTimerCycle = 0;
}
if(g_iPauseCycle > (sizeof(g_sPauseColors) - 1))
{
g_iPauseCycle = 0;
}
return Plugin_Continue;
}
// Auto bhop
public Action:SM_Auto(client, args)
{
if(g_bAllowAuto == true)
{
if (args < 1)
{
SetClientSettings(client, GetClientSettings(client) ^ AUTO_BHOP);
if(g_bAutoStopsTimer && (GetClientSettings(client) & AUTO_BHOP))
{
StopTimer(client);
}
if(GetClientSettings(client) & AUTO_BHOP)
{
CPrintToChat(client, "%s%sAuto bhop %senabled",
g_msg_start,
g_msg_textcol,
g_msg_varcol);
}
else
{
CPrintToChat(client, "%s%sAuto bhop %sdisabled",
g_msg_start,
g_msg_textcol,
g_msg_varcol);
}
}
else if (args == 1)
{
decl String:TargetArg[128];
GetCmdArgString(TargetArg, sizeof(TargetArg));
new TargetID = FindTarget(client, TargetArg, true, false);
if(TargetID != -1)
{
decl String:TargetName[128];
GetClientName(TargetID, TargetName, sizeof(TargetName));
if(GetClientSettings(TargetID) & AUTO_BHOP)
{
CPrintToChat(client, "%s%sPlayer %s%s%s has auto bhop %senabled",
g_msg_start,
g_msg_textcol,
g_msg_varcol,
TargetName,
g_msg_textcol,
g_msg_varcol);
}
else
{
CPrintToChat(client, "%s%sPlayer %s%s%s has auto bhop %sdisabled",
g_msg_start,
g_msg_textcol,
g_msg_varcol,
TargetName,
g_msg_textcol,
g_msg_varcol);
}
}
}
}
return Plugin_Handled;
}
// Toggles between 2d vector and 3d vector velocity
public Action:SM_TrueVelocity(client, args)
{
SetClientSettings(client, GetClientSettings(client) ^ SHOW_2DVEL);
if(GetClientSettings(client) & SHOW_2DVEL)
{
CPrintToChat(client, "%s%sShowing %strue %svelocity",
g_msg_start,
g_msg_textcol,
g_msg_varcol,
g_msg_textcol);
}
else
{
CPrintToChat(client, "%s%sShowing %snormal %svelocity",
g_msg_start,
g_msg_textcol,
g_msg_varcol,
g_msg_textcol);
}
return Plugin_Handled;
}
public Action:SM_SPJ(client, args)
{
// Get target
decl String:sArg[255];
GetCmdArgString(sArg, sizeof(sArg));
// Write data to send to query callback
new Handle:pack = CreateDataPack();
WritePackCell(pack, GetClientUserId(client));
WritePackString(pack, sArg);
// Do query
decl String:query[512];
Format(query, sizeof(query), "SELECT User, SPJ, SteamID, MStrafes, MJumps FROM (SELECT t2.User, t2.SteamID, AVG(t1.Strafes/t1.Jumps) AS SPJ, SUM(t1.Strafes) AS MStrafes, SUM(t1.Jumps) AS MJumps FROM times AS t1, players AS t2 WHERE t1.PlayerID=t2.PlayerID AND t1.Style=0 GROUP BY t1.PlayerID ORDER BY AVG(t1.Strafes/t1.Jumps) DESC) AS x WHERE MStrafes > 100");
SQL_TQuery(g_DB, SPJ_Callback, query, pack);
return Plugin_Handled;
}
public SPJ_Callback(Handle:owner, Handle:hndl, String:error[], any:pack)
{
if(hndl != INVALID_HANDLE)
{
// Get data from command arg
decl String:sTarget[MAX_NAME_LENGTH];
ResetPack(pack);
new client = GetClientOfUserId(ReadPackCell(pack));
ReadPackString(pack, sTarget, sizeof(sTarget));
new len = strlen(sTarget);
decl String:item[255], String:info[255], String:sAuth[32], String:sName[MAX_NAME_LENGTH];
new Float:SPJ, Strafes, Jumps;
// Create menu
new Handle:menu = CreateMenu(Menu_ShowSPJ);
SetMenuTitle(menu, "Showing strafes per jump\nSelect an item for more info\n ");
new rows = SQL_GetRowCount(hndl);
for(new i=0; i<rows; i++)
{
SQL_FetchRow(hndl);
SQL_FetchString(hndl, 0, sName, sizeof(sName));
SPJ = SQL_FetchFloat(hndl, 1);
SQL_FetchString(hndl, 2, sAuth, sizeof(sAuth));
Strafes = SQL_FetchInt(hndl, 3);
Jumps = SQL_FetchInt(hndl, 4);
if(StrContains(sName, sTarget) != -1 || len == 0)
{
Format(item, sizeof(item), "%.1f - %s",
SPJ,
sName);
Format(info, sizeof(info), "%s <%s> SPJ: %.1f, Strafes: %d, Jumps: %d",
sName,
sAuth,
SPJ,
Strafes,
Jumps);
AddMenuItem(menu, info, item);
}
}
DisplayMenu(menu, client, MENU_TIME_FOREVER);
}
else
{
LogError(error);
}
CloseHandle(pack);
}
public Menu_ShowSPJ(Handle:menu, MenuAction:action, param1, param2)
{
if(action == MenuAction_Select)
{
decl String:info[255];
GetMenuItem(menu, param2, info, sizeof(info));
PrintToChat(param1, info);
}
else if(action == MenuAction_End)
{
CloseHandle(menu);
}
}
// Admin command for deleting times
public Action:SM_Delete(client, args)
{
if(args == 0)
{
if(GetCmdReplySource() == SM_REPLY_TO_CHAT)
PrintToConsole(client, "[SM] Usage:\nsm_delete record - Deletes a specific record.\nsm_delete record1 record2 - Deletes all times from record1 to record2.");
}
else if(args == 1)
{
decl String:input[128];
GetCmdArgString(input, sizeof(input));
new value = StringToInt(input);
if(value != 0)
{
AdminCmd_DeleteRecord(client, value, value);
}
}
else if(args == 2)
{
decl String:sValue0[128], String:sValue1[128];
GetCmdArg(1, sValue0, sizeof(sValue0));
GetCmdArg(2, sValue1, sizeof(sValue1));
AdminCmd_DeleteRecord(client, StringToInt(sValue0), StringToInt(sValue1));
}
return Plugin_Handled;
}
AdminCmd_DeleteRecord(client, value1, value2)
{
new Handle:menu = CreateMenu(AdminMenu_DeleteRecord);
if(value1 == value2)
SetMenuTitle(menu, "Delete record %d", value1);
else
SetMenuTitle(menu, "Delete records %d to %d", value1, value2);
decl String:sDisplay[64], String:sInfo[32], String:sStyle[32], String:sType[32];
for(new Type; Type < MAX_TYPES; Type++)
{
GetTypeName(Type, sType, sizeof(sType));
for(new Style; Style < g_TotalStyles; Style++)
{
if(Style_IsEnabled(Style) && g_StyleConfig[Style][AllowType][Type])
{
Format(sInfo, sizeof(sInfo), "%d;%d;%d;%d", value1, value2, Type, Style);
GetStyleName(Style, sStyle, sizeof(sStyle));
FormatEx(sDisplay, sizeof(sDisplay), "%s (%s)", sStyle, sType);
AddMenuItem(menu, sInfo, sDisplay);
}
}
}
SetMenuExitButton(menu, true);
DisplayMenu(menu, client, MENU_TIME_FOREVER);
}
public AdminMenu_DeleteRecord(Handle:menu, MenuAction:action, param1, param2)
{
if (action == MenuAction_Select)
{
decl String:info[32], String:sTypeStyle[4][8];
GetMenuItem(menu, param2, info, sizeof(info));
if(StrContains(info, ";") != -1)
{
ExplodeString(info, ";", sTypeStyle, 4, 8);
new RecordOne = StringToInt(sTypeStyle[0]);
new RecordTwo = StringToInt(sTypeStyle[1]);
new Type = StringToInt(sTypeStyle[2]);
new Style = StringToInt(sTypeStyle[3]);
DB_DeleteRecord(param1, Type, Style, RecordOne, RecordTwo);
//DB_UpdateRanks(g_sMapName, Type, Style);
}
}
else if (action == MenuAction_End)
CloseHandle(menu);
}
public Action:SM_StopTimer(client, args)
{
StopTimer(client);
return Plugin_Handled;
}
public Action:SM_WorldRecord(client, args)
{
new Type, Style;
if(GetTypeStyleFromCommand("wr", Type, Style))
{
if(!IsSpamming(client))
{
SetIsSpamming(client, 1.0);
if(args == 0)
{
DB_DisplayRecords(client, g_sMapName, Type, Style);
}
else if(args == 1)
{
decl String:arg[64];
GetCmdArgString(arg, sizeof(arg));
if(FindStringInArray(g_MapList, arg) != -1)
{
DB_DisplayRecords(client, arg, Type, Style);
}
else
{
CPrintToChat(client, "%s%sNo map found named %s%s",
g_msg_start,
g_msg_textcol,
g_msg_varcol,
arg);
}
}
}
}
return Plugin_Handled;
}
public Action:SM_Time(client, args)
{
new Type, Style;
if(GetTypeStyleFromCommand("time", Type, Style))
{
if(!IsSpamming(client))
{
SetIsSpamming(client, 1.0);
if(args == 0)
{
DB_ShowTime(client, client, g_sMapName, Type, Style);
}
else if(args == 1)
{
decl String:arg[250];
GetCmdArgString(arg, sizeof(arg));
if(arg[0] == '@')
{
ReplaceString(arg, 250, "@", "");
DB_ShowTimeAtRank(client, g_sMapName, StringToInt(arg), Type, Style);
}
else
{