forked from zzzznn5000/bTimes-csgo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbTimes-ranks.sp
More file actions
2621 lines (2201 loc) · 65.6 KB
/
bTimes-ranks.sp
File metadata and controls
2621 lines (2201 loc) · 65.6 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 dynamic 131072
#pragma semicolon 1
#include <bTimes-core>
public Plugin:myinfo =
{
name = "[bTimes] - Ranks",
author = "blacky",
description = "Controls server rankings",
version = VERSION,
url = "http://steamcommunity.com/id/blaackyy/"
}
#include <sourcemod>
#include <sdkhooks>
#include <bTimes-ranks>
#include <bTimes-timer>
#include <bTimes-random>
#include <bTimes-zones>
#undef REQUIRE_PLUGIN
#include <scp>
#define CC_HASCC 1<<0
#define CC_MSGCOL 1<<1
#define CC_NAME 1<<2
new Handle:g_DB;
new Handle:g_MapList;
new Handle:g_hMapsDone[MAX_TYPES][MAX_STYLES],
Handle:g_hMapsDoneHndlRef[MAX_TYPES][MAX_STYLES],
Handle:g_hRecordListID[MAX_TYPES][MAX_STYLES],
Handle:g_hRecordListCount[MAX_TYPES][MAX_STYLES],
g_RecordCount[MAXPLAYERS + 1],
g_iMVPs_offset,
bool:g_bStatsLoaded;
new Handle:g_hRanksPlayerID[MAX_TYPES][MAX_STYLES],
Handle:g_hRanksPoints[MAX_TYPES][MAX_STYLES],
Handle:g_hRanksNames[MAX_TYPES][MAX_STYLES],
g_Rank[MAXPLAYERS + 1][MAX_TYPES][MAX_STYLES],
g_Points[MAXPLAYERS + 1][MAX_TYPES][MAX_STYLES];
new String:g_msg_start[128],
String:g_msg_varcol[128],
String:g_msg_textcol[128];
// Chat ranks
new Handle:g_hChatRanksRanges,
Handle:g_hChatRanksNames;
// Custom chat
new Handle:g_hCustomSteams,
Handle:g_hCustomNames,
Handle:g_hCustomMessages,
Handle:g_hCustomUse,
g_ClientUseCustom[MAXPLAYERS + 1];
new bool:g_bNewMessage;
// Settings
new Handle:g_hUseCustomChat,
Handle:g_hUseChatRanks,
Handle:g_hAllChat;
// Points recalculation
new g_RecalcTotal,
g_RecalcProgress;
public OnPluginStart()
{
decl String:sGame[64];
GetGameFolderName(sGame, sizeof(sGame));
// Connect to the database
DB_Connect();
// Cvars
g_hUseCustomChat = CreateConVar("timer_enablecc", "1", "Allows specific players in sourcemod/configs/timer/custom.cfg to use custom chat.", 0, true, 0.0, true, 1.0);
g_hUseChatRanks = CreateConVar("timer_chatranks", "1", "Allows players to use chat ranks specified in sourcemod/configs/timer/ranks.cfg", 0, true, 0.0, true, 1.0);
g_hAllChat = CreateConVar("timer_allchat", "0", "Enable's allchat", 0, true, 0.0, true, 1.0);
AutoExecConfig(true, "ranks", "timer");
// Commands
RegConsoleCmdEx("sm_ccname", SM_ColoredName, "Change colored name.");
RegConsoleCmdEx("sm_ccmsg", SM_ColoredMsg, "Change the color of your messages.");
RegConsoleCmdEx("sm_cchelp", SM_Colorhelp, "For help on creating a custom name tag with colors and a color message.");
RegConsoleCmdEx("sm_rankings", SM_Rankings, "Shows the chat ranking tags and the ranks required to get them.");
RegConsoleCmdEx("sm_ranks", SM_Rankings, "Shows the chat ranking tags and the ranks required to get them.");
RegConsoleCmdEx("sm_chatranks", SM_Rankings, "Shows the chat ranking tags and the ranks required to get them.");
// Admin commands
RegAdminCmd("sm_enablecc", SM_EnableCC, ADMFLAG_ROOT, "Enable custom chat for a specified SteamID.");
RegAdminCmd("sm_disablecc", SM_DisableCC, ADMFLAG_ROOT, "Disable custom chat for a specified SteamID.");
RegAdminCmd("sm_cclist", SM_CCList, ADMFLAG_CHEATS, "Shows a list of players with custom chat privileges.");
RegAdminCmd("sm_recalcpts", SM_RecalcPts, ADMFLAG_CHEATS, "Recalculates all the points in the database.");
// Admin
RegAdminCmd("sm_reloadranks", SM_ReloadRanks, ADMFLAG_CHEATS, "Reloads chat ranks.");
// Chat ranks
g_hChatRanksRanges = CreateArray(2);
g_hChatRanksNames = CreateArray(ByteCountToCells(256));
LoadChatRanks();
// Custom chat ranks
g_hCustomSteams = CreateArray(ByteCountToCells(32));
g_hCustomNames = CreateArray(ByteCountToCells(128));
g_hCustomMessages = CreateArray(ByteCountToCells(256));
g_hCustomUse = CreateArray();
// Makes FindTarget() work properly
LoadTranslations("common.phrases");
// Command listeners
AddCommandListener(Command_Say, "say");
g_iMVPs_offset = FindSendPropInfo("CCSPlayerResource", "m_iMVPs");
}
public OnEntityCreated(entity, const String:classname[])
{
if(StrContains(classname, "_player_manager") != -1)
{
SDKHook(entity, SDKHook_ThinkPost, PlayerManager_OnThinkPost);
}
}
public APLRes:AskPluginLoad2(Handle:myself, bool:late, String:error[], err_max)
{
CreateNative("DB_UpdateRanks", Native_UpdateRanks);
CreateNative("Timer_EnableCustomChat", Native_EnableCustomChat);
CreateNative("Timer_DisableCustomChat", Native_DisableCustomChat);
CreateNative("Timer_SteamIDHasCustomChat", Native_SteamIDHasCustomChat);
CreateNative("Timer_OpenStatsMenu", Native_OpenStatsMenu);
return APLRes_Success;
}
public OnMapStart()
{
if(g_MapList != INVALID_HANDLE)
CloseHandle(g_MapList);
g_MapList = ReadMapList();
CreateTimer(1.0, UpdateDeaths, _, TIMER_REPEAT | TIMER_FLAG_NO_MAPCHANGE);
}
public OnClientAuthorized(client, const String:auth[])
{
new idx = FindStringInArray(g_hCustomSteams, auth);
if(idx != -1)
{
g_ClientUseCustom[client] = GetArrayCell(g_hCustomUse, idx);
}
}
public bool:OnClientConnect(client)
{
g_ClientUseCustom[client] = 0;
for(new Type; Type < MAX_TYPES; Type++)
{
for(new Style; Style < MAX_STYLES; Style++)
{
g_Rank[client][Type][Style] = 0;
g_Points[client][Type][Style] = 0;
g_RecordCount[client] = 0;
}
}
return true;
}
public OnPlayerIDLoaded(client)
{
SetClientRank(client);
SetRecordCount(client);
}
public OnMapTimesLoaded()
{
DB_LoadStats();
}
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 OnStylesLoaded()
{
RegConsoleCmdPerStyle("rank", SM_Rank, "Show your rank for {Type} timer on {Style} style.");
RegConsoleCmdPerStyle("mapsleft", SM_Mapsleft, "Show maps left for {Type} timer on {Style} style.");
RegConsoleCmdPerStyle("mapsdone", SM_Mapsdone, "Show maps done for {Type} timer on {Style} style.");
RegConsoleCmdPerStyle("top", SM_Top, "Show list of top players for {Type} timer on {Style} style.");
RegConsoleCmdPerStyle("topwr", SM_TopWorldRecord, "Show who has the most records for {Type} timer on {Style} style.");
RegConsoleCmdPerStyle("stats", SM_Stats, "Shows a player's stats for {Type} timer on {Style} style.");
for(new Type; Type < MAX_TYPES; Type++)
{
for(new Style; Style < MAX_STYLES; Style++)
{
if(Style_IsEnabled(Style) && Style_IsTypeAllowed(Style, Type))
{
g_hRanksPlayerID[Type][Style] = CreateArray();
g_hRanksPoints[Type][Style] = CreateArray();
g_hRanksNames[Type][Style] = CreateArray(ByteCountToCells(MAX_NAME_LENGTH));
g_hRecordListID[Type][Style] = CreateArray();
g_hRecordListCount[Type][Style] = CreateArray();
g_hMapsDone[Type][Style] = CreateArray();
g_hMapsDoneHndlRef[Type][Style] = CreateArray();
}
}
}
}
public Action:Command_Say(client, const String:command[], argc)
{
if(GetConVarBool(g_hAllChat))
{
g_bNewMessage = true;
}
}
public Action:OnChatMessage(&author, Handle:recipients, String:name[], String:message[])
{
GetChatName(author, name, MAXLENGTH_NAME);
GetChatMessage(author, message, MAXLENGTH_MESSAGE);
if(g_bNewMessage == true)
{
if(GetMessageFlags() & CHATFLAGS_ALL && !IsPlayerAlive(author))
{
for(new client = 1; client <= MaxClients; client++)
{
if(IsClientConnected(client) && IsClientInGame(client) && IsPlayerAlive(client))
{
PushArrayCell(recipients, client);
}
}
}
g_bNewMessage = false;
}
return Plugin_Changed;
}
FormatTag(client, String:buffer[], maxlength)
{
char RandomColor[][] =
{
"\x01", "\x02", "\x03", "\x04", "\x05", "\x06", "\x07", "\x08", "\x09", "\x10", "\x0B", "\x0C", "\x0E", "\x0F"
};
while(StrContains(buffer, "{rand}", true) != -1)
{
ReplaceString(buffer, maxlength, "{rand}", RandomColor[GetRandomInt(0, sizeof(RandomColor) - 1)]);
}
ReplaceString(buffer, maxlength, "{team}", "\x03", true);
ReplaceString(buffer, maxlength, "{white}", "\x01", true);
ReplaceString(buffer, maxlength, "{red}", "\x02", true);
ReplaceString(buffer, maxlength, "{green}", "\x04", true);
ReplaceString(buffer, maxlength, "{lightreen}", "\x05", true);
ReplaceString(buffer, maxlength, "{limegreen}", "\x06", true);
ReplaceString(buffer, maxlength, "{lightred}", "\x07", true);
ReplaceString(buffer, maxlength, "{gray}", "\x08", true);
ReplaceString(buffer, maxlength, "{grey}", "\x08", true);
ReplaceString(buffer, maxlength, "{lightyellow}", "\x09", true);
ReplaceString(buffer, maxlength, "{gold}", "\x10", true);
ReplaceString(buffer, maxlength, "{skyblue}", "\x0B", true);
ReplaceString(buffer, maxlength, "{blue}", "\x0C", true);
ReplaceString(buffer, maxlength, "{pink}", "\x0E", true);
ReplaceString(buffer, maxlength, "{lighterred}", "\x0F", true);
if(0 < client <= MaxClients)
{
decl String:sName[MAX_NAME_LENGTH];
GetClientName(client, sName, sizeof(sName));
ReplaceString(buffer, maxlength, "{name}", sName, true);
}
}
GetChatName(client, String:buffer[], maxlength)
{
if((g_ClientUseCustom[client] & CC_HASCC) && (g_ClientUseCustom[client] & CC_NAME) && GetConVarBool(g_hUseCustomChat))
{
decl String:sAuth[32];
GetClientAuthId(client, AuthId_Engine, sAuth, sizeof(sAuth));
new idx = FindStringInArray(g_hCustomSteams, sAuth);
if(idx != -1)
{
GetArrayString(g_hCustomNames, idx, buffer, maxlength);
FormatTag(client, buffer, maxlength);
}
}
else if(GetConVarBool(g_hUseChatRanks))
{
new iSize = GetArraySize(g_hChatRanksRanges);
for(new i=0; i<iSize; i++)
{
if(GetArrayCell(g_hChatRanksRanges, i, 0) <= g_Rank[client][TIMER_MAIN][0] <= GetArrayCell(g_hChatRanksRanges, i, 1))
{
GetArrayString(g_hChatRanksNames, i, buffer, maxlength);
FormatTag(client, buffer, maxlength);
return;
}
}
}
}
GetChatMessage(client, String:message[], maxlength)
{
if((g_ClientUseCustom[client] & CC_HASCC) && (g_ClientUseCustom[client] & CC_MSGCOL) && GetConVarBool(g_hUseCustomChat))
{
decl String:sAuth[32];
GetClientAuthId(client, AuthId_Engine, sAuth, sizeof(sAuth));
new idx = FindStringInArray(g_hCustomSteams, sAuth);
if(idx != -1)
{
decl String:buffer[MAXLENGTH_MESSAGE];
GetArrayString(g_hCustomMessages, idx, buffer, MAXLENGTH_MESSAGE);
FormatTag(client, buffer, maxlength);
Format(message, maxlength, "%s%s", buffer, message);
}
}
}
public Action:SM_RecalcPts(client, args)
{
new Handle:menu = CreateMenu(Menu_RecalcPts);
SetMenuTitle(menu, "Recalculating the points takes a while.\nAre you sure you want to do this?");
AddMenuItem(menu, "y", "Yes");
AddMenuItem(menu, "n", "No");
DisplayMenu(menu, client, MENU_TIME_FOREVER);
return Plugin_Handled;
}
public Menu_RecalcPts(Handle:menu, MenuAction:action, param1, param2)
{
if (action == MenuAction_Select)
{
decl String:info[16];
GetMenuItem(menu, param2, info, sizeof(info));
if(info[0] == 'y')
{
RecalcPoints(param1);
}
}
else if (action == MenuAction_End)
CloseHandle(menu);
}
RecalcPoints(client)
{
CPrintToChatAll("%s%sRecalculating the ranks, see console for progress.",
g_msg_start,
g_msg_textcol);
decl String:query[128];
FormatEx(query, sizeof(query), "SELECT MapName, MapID FROM maps");
SQL_TQuery(g_DB, RecalcPoints_Callback, query, client);
}
public RecalcPoints_Callback(Handle:owner, Handle:hndl, String:error[], any:data)
{
if(hndl != INVALID_HANDLE)
{
new rows = SQL_GetRowCount(hndl);
decl String:sMapName[64], String:query[128];
g_RecalcTotal = rows * 4;
g_RecalcProgress = 0;
for(new i = 0; i < rows; i++)
{
SQL_FetchRow(hndl);
SQL_FetchString(hndl, 0, sMapName, sizeof(sMapName));
if(FindStringInArray(g_MapList, sMapName) != -1)
{
new TotalStyles = Style_GetTotal();
for(new Type = 0; Type < MAX_TYPES; Type++)
{
for(new Style = 0; Style < TotalStyles; Style++)
{
if(Style_IsEnabled(Style) && Style_IsTypeAllowed(Style, Type))
{
UpdateRanks(sMapName, Type, Style, true);
}
}
}
}
else
{
FormatEx(query, sizeof(query), "UPDATE times SET Points = 0 WHERE MapID = %d",
SQL_FetchInt(hndl, 1));
new Handle:pack = CreateDataPack();
WritePackString(pack, sMapName);
SQL_TQuery(g_DB, RecalcPoints_Callback2, query, pack);
}
}
}
else
{
LogError(error);
}
}
public RecalcPoints_Callback2(Handle:owner, Handle:hndl, String:error[], any:data)
{
if(hndl != INVALID_HANDLE)
{
ResetPack(data);
decl String:sMapName[64];
ReadPackString(data, sMapName, sizeof(sMapName));
g_RecalcProgress += 4;
for(new client = 1; client <= MaxClients; client++)
{
if(IsClientInGame(client))
{
if(!IsFakeClient(client))
{
PrintToConsole(client, "[%.1f%%] %s's points deleted.",
float(g_RecalcProgress)/float(g_RecalcTotal) * 100.0,
sMapName);
}
}
}
}
else
{
LogError(error);
}
CloseHandle(data);
}
public Action:SM_Rank(client, args)
{
new Type, Style;
if(GetTypeStyleFromCommand("rank", Type, Style))
{
if(!IsSpamming(client))
{
SetIsSpamming(client, 1.0);
if(args == 0)
{
DB_ShowRank(client, client, Type, Style);
}
else
{
decl String:targetName[128];
GetCmdArgString(targetName, sizeof(targetName));
new target = FindTarget(client, targetName, true, false);
if(target != -1)
DB_ShowRank(client, target, Type, Style);
}
}
}
return Plugin_Handled;
}
public Action:SM_Top(client, args)
{
new Type, Style;
if(GetTypeStyleFromCommand("top", Type, Style))
{
if(!IsSpamming(client))
{
SetIsSpamming(client, 1.0);
DB_ShowTopAllSpec(client, Type, Style);
}
}
return Plugin_Handled;
}
public Action:SM_Mapsleft(client, args)
{
new Type, Style;
if(GetTypeStyleFromCommand("mapsleft", Type, Style))
{
if(!IsSpamming(client))
{
SetIsSpamming(client, 1.0);
if(args == 0)
{
DB_ShowMapsleft(client, client, Type, Style);
}
else
{
decl String:targetName[128];
GetCmdArgString(targetName, sizeof(targetName));
new target = FindTarget(client, targetName, true, false);
if(target != -1)
DB_ShowMapsleft(client, target, Type, Style);
}
}
}
return Plugin_Handled;
}
public Action:SM_Mapsdone(client, args)
{
new Type, Style;
if(GetTypeStyleFromCommand("mapsdone", Type, Style))
{
if(!IsSpamming(client))
{
SetIsSpamming(client, 1.0);
new PlayerID;
if(args == 0)
{
PlayerID = GetPlayerID(client);
if(PlayerID != 0)
{
DB_ShowMapsdone(client, PlayerID, Type, Style);
}
else
{
CPrintToChat(client, "%s%sYou have not been authorized by the timer yet.",
g_msg_start,
g_msg_textcol);
}
}
else
{
decl String:targetName[128];
GetCmdArgString(targetName, sizeof(targetName));
new target = FindTarget(client, targetName, true, false);
if(target != -1)
{
PlayerID = GetPlayerID(target);
if(PlayerID != 0)
{
DB_ShowMapsdone(client, PlayerID, Type, Style);
}
else
{
CPrintToChat(client, "%s%s%N%s has not been authorized by the timer yet.",
g_msg_start,
g_msg_varcol,
target,
g_msg_textcol);
}
}
}
}
}
return Plugin_Handled;
}
public Action:SM_Stats(client, args)
{
new Type, Style;
if(GetTypeStyleFromCommand("stats", Type, Style))
{
if(!IsSpamming(client))
{
SetIsSpamming(client, 1.0);
new PlayerID;
if(args == 0)
{
PlayerID = GetPlayerID(client);
if(PlayerID != 0)
{
OpenStatsMenu(client, PlayerID, Type, Style);
}
else
{
CPrintToChat(client, "%s%sYou have not been authorized by the timer yet.",
g_msg_start,
g_msg_textcol);
}
}
else
{
decl String:targetName[128];
GetCmdArgString(targetName, sizeof(targetName));
new target = FindTarget(client, targetName, true, false);
if(target != -1)
{
PlayerID = GetPlayerID(target);
if(PlayerID != 0)
{
OpenStatsMenu(client, PlayerID, Type, Style);
}
else
{
CPrintToChat(client, "%s%s%N%s has not been authorized by the timer yet.",
g_msg_start,
g_msg_varcol,
target,
g_msg_textcol);
}
}
}
}
}
return Plugin_Handled;
}
OpenStatsMenu(client, PlayerID, Type, Style)
{
new Rank = FindValueInArray(g_hRanksPlayerID[Type][Style], PlayerID);
if(Rank != -1)
{
Rank++;
new Handle:menu = CreateMenu(Menu_Stats);
decl String:sName[MAX_NAME_LENGTH], String:sAuth[32], String:sType[32], String:sStyle[32];
GetNameFromPlayerID(PlayerID, sName, sizeof(sName));
GetSteamIDFromPlayerID(PlayerID, sAuth, sizeof(sAuth));
GetTypeName(Type, sType, sizeof(sType));
GetStyleName(Style, sStyle, sizeof(sStyle));
SetMenuTitle(menu, "Stats for %s (%s)\n--------------------------------\n", sName, sAuth);
// Get Record count
new RecordCount;
new idx = FindValueInArray(g_hRecordListID[Type][Style], PlayerID);
if(idx != -1)
{
RecordCount = GetArrayCell(g_hRecordListCount[Type][Style], idx);
}
// Get maps done
new Handle:hCell = GetArrayCell(g_hMapsDone[Type][Style], PlayerID);
new MapsDone;
if(hCell != INVALID_HANDLE)
MapsDone = GetArraySize(hCell);
new TotalMaps;
if(Type == TIMER_MAIN)
TotalMaps = GetTotalZonesAllMaps(MAIN_START);
else
TotalMaps = GetTotalZonesAllMaps(BONUS_START);
new Float:fCompletion = float(MapsDone) / float(TotalMaps) * 100.0;
// Get rank info
new TotalRanks = GetArraySize(g_hRanksPlayerID[Type][Style]);
new Float:fPoints = GetArrayCell(g_hRanksPoints[Type][Style], Rank - 1);
decl String:sDisplay[256];
FormatEx(sDisplay, sizeof(sDisplay), "%s [%s]\nWorld Records: %d\n \nMaps done: %d / %d (%.1f%%)\n \nRank: %d / %d (%d Pts.)\n--------------------------------",
sType,
sStyle,
RecordCount,
MapsDone,
TotalMaps,
fCompletion,
Rank,
TotalRanks,
RoundToFloor(fPoints));
decl String:sInfo[32];
FormatEx(sInfo, sizeof(sInfo), "%d;%d;%d", PlayerID, Type, Style);
AddMenuItem(menu, sInfo, sDisplay);
for(new lType; lType < MAX_TYPES; lType++)
{
GetTypeName(lType, sType, sizeof(sType));
for(new lStyle; lStyle < MAX_STYLES; lStyle++)
{
if(lType == Type && lStyle == Style)
continue;
if(Style_IsEnabled(lStyle) && Style_IsTypeAllowed(lStyle, lType))
{
GetStyleName(lStyle, sStyle, sizeof(sStyle));
FormatEx(sInfo, sizeof(sInfo), "%d;%d;%d", PlayerID, lType, lStyle);
FormatEx(sDisplay, sizeof(sDisplay), "%s [%s]", sType, sStyle);
AddMenuItem(menu, sInfo, sDisplay);
}
}
}
DisplayMenu(menu, client, MENU_TIME_FOREVER);
}
else
{
if(g_bStatsLoaded == false)
{
CPrintToChat(client, "%s%sThe stats have not been loaded yet.",
g_msg_start,
g_msg_textcol);
}
else
{
decl String:sType[32], String:sStyle[32];
GetTypeName(Type, sType, sizeof(sType));
GetStyleName(Style, sStyle, sizeof(sStyle));
decl String:slType[32], String:slStyle[32];
for(new lType; lType < MAX_TYPES; lType++)
{
GetTypeName(lType, slType, sizeof(slType));
for(new lStyle; lStyle < MAX_STYLES; lStyle++)
{
if(Style_IsEnabled(lStyle) && Style_IsTypeAllowed(lStyle, lType))
{
GetStyleName(lStyle, slStyle, sizeof(slStyle));
if((Rank = FindValueInArray(g_hRanksPlayerID[lType][lStyle], PlayerID)) != -1)
{
CPrintToChat(client, "%s%sCouldn't find stats for [%s%s%s] - [%s%s%s], showing stats for [%s%s%s] - [%s%s%s] instead.",
g_msg_start,
g_msg_textcol,
g_msg_varcol,
sType,
g_msg_textcol,
g_msg_varcol,
sStyle,
g_msg_textcol,
g_msg_varcol,
slType,
g_msg_textcol,
g_msg_varcol,
slStyle,
g_msg_textcol);
OpenStatsMenu(client, PlayerID, lType, lStyle);
return;
}
}
}
}
CPrintToChat(client, "%s%sThe player you specified is unranked.",
g_msg_start,
g_msg_textcol);
}
}
}
public Menu_Stats(Handle:menu, MenuAction:action, param1, param2)
{
if (action == MenuAction_Select)
{
decl String:info[32];
GetMenuItem(menu, param2, info, sizeof(info));
decl String:sInfoExploded[3][16];
ExplodeString(info, ";", sInfoExploded, sizeof(sInfoExploded), sizeof(sInfoExploded[]));
OpenStatsMenu(param1, StringToInt(sInfoExploded[0]), StringToInt(sInfoExploded[1]), StringToInt(sInfoExploded[2]));
}
else if (action == MenuAction_End)
CloseHandle(menu);
}
public Native_OpenStatsMenu(Handle:plugin, numParams)
{
OpenStatsMenu(GetNativeCell(1), GetNativeCell(2), GetNativeCell(3), GetNativeCell(4));
}
public Action:SM_TopWorldRecord(client, args)
{
new Type, Style;
if(GetTypeStyleFromCommand("topwr", Type, Style))
{
decl String:sType[32];
GetTypeName(Type, sType, sizeof(sType));
decl String:sStyle[32];
GetStyleName(Style, sStyle, sizeof(sStyle));
new iSize = GetArraySize(g_hRecordListID[Type][Style]);
if(iSize > 0)
{
new Handle:menu = CreateMenu(Menu_RecordCount);
SetMenuTitle(menu, "World Record Count [%s] - [%s]", sType, sStyle);
new PlayerID, RecordCount, String:sInfo[32], String:sDisplay[64], String:sName[MAX_NAME_LENGTH];
for(new idx; idx < iSize; idx++)
{
PlayerID = GetArrayCell(g_hRecordListID[Type][Style], idx);
RecordCount = GetArrayCell(g_hRecordListCount[Type][Style], idx);
FormatEx(sInfo, sizeof(sInfo), "%d;%d;%d", PlayerID, Type, Style);
GetNameFromPlayerID(PlayerID, sName, sizeof(sName));
FormatEx(sDisplay, sizeof(sDisplay), "#%d: %s (%d)", idx + 1, sName, RecordCount);
AddMenuItem(menu, sInfo, sDisplay);
}
DisplayMenu(menu, client, MENU_TIME_FOREVER);
}
else
{
CPrintToChat(client, "%s%s[%s%s%s] - [%s%s%s] There are no world records on any map.",
g_msg_start,
g_msg_textcol,
g_msg_varcol,
sType,
g_msg_textcol,
g_msg_varcol,
sStyle,
g_msg_textcol);
}
}
return Plugin_Handled;
}
public Menu_RecordCount(Handle:menu, MenuAction:action, param1, param2)
{
if (action == MenuAction_Select)
{
decl String:sInfo[32];
GetMenuItem(menu, param2, sInfo, sizeof(sInfo));
decl String:sInfoExploded[3][16];
ExplodeString(sInfo, ";", sInfoExploded, sizeof(sInfoExploded), sizeof(sInfoExploded[]));
OpenStatsMenu(param1, StringToInt(sInfoExploded[0]), StringToInt(sInfoExploded[1]), StringToInt(sInfoExploded[2]));
}
else if (action == MenuAction_End)
CloseHandle(menu);
}
public Action:SM_ColoredName(client, args)
{
if(!IsSpamming(client))
{
SetIsSpamming(client, 1.0);
if(g_ClientUseCustom[client] & CC_HASCC)
{
decl String:query[512], String:sAuth[32];
GetClientAuthId(client, AuthId_Engine, sAuth, sizeof(sAuth));
if(args == 0)
{
// Get new ccname setting
g_ClientUseCustom[client] ^= CC_NAME;
// Acknowledge change to client
if(g_ClientUseCustom[client] & CC_NAME)
{
CPrintToChat(client, "%s%sColored name enabled.",
g_msg_start,
g_msg_textcol);
}
else
{
CPrintToChat(client, "%s%sColored name disabled.",
g_msg_start,
g_msg_textcol);
}
// Set the new ccname setting
new idx = FindStringInArray(g_hCustomSteams, sAuth);
if(idx != -1)
SetArrayCell(g_hCustomUse, idx, g_ClientUseCustom[client]);
// Format the query
FormatEx(query, sizeof(query), "UPDATE players SET ccuse=%d WHERE SteamID='%s'",
g_ClientUseCustom[client],
sAuth);
}
else
{
// Get new ccname
decl String:sArg[250];
GetCmdArgString(sArg, sizeof(sArg));
decl String:sEscapeArg[(strlen(sArg)*2)+1];
// Escape the ccname for SQL insertion
SQL_LockDatabase(g_DB);
SQL_EscapeString(g_DB, sArg, sEscapeArg, (strlen(sArg)*2)+1);
SQL_UnlockDatabase(g_DB);
// Modify player's ccname
new idx = FindStringInArray(g_hCustomSteams, sAuth);
if(idx != -1)
SetArrayString(g_hCustomNames, idx, sEscapeArg);
// Prepare query
FormatEx(query, sizeof(query), "UPDATE players SET ccname='%s' WHERE SteamID='%s'",
sEscapeArg,
sAuth);
CPrintToChat(client, "%s%sColored name set to %s%s",
g_msg_start,
g_msg_textcol,
g_msg_varcol,
sArg);
}
// Execute query
SQL_TQuery(g_DB, ColoredName_Callback, query);
}
}
return Plugin_Handled;
}
public ColoredName_Callback(Handle:owner, Handle:hndl, String:error[], any:data)
{
if(hndl == INVALID_HANDLE)
{
LogError(error);
}
}
public Action:SM_ColoredMsg(client, args)
{
if(!IsSpamming(client))
{
SetIsSpamming(client, 1.0);
if(g_ClientUseCustom[client] & CC_HASCC)
{
decl String:query[512], String:sAuth[32];
GetClientAuthId(client, AuthId_Engine, sAuth, sizeof(sAuth));
if(args == 0)
{
g_ClientUseCustom[client] ^= CC_MSGCOL;
new idx = FindStringInArray(g_hCustomSteams, sAuth);
if(idx != -1)
SetArrayCell(g_hCustomUse, idx, g_ClientUseCustom[client]);
FormatEx(query, sizeof(query), "UPDATE players SET ccuse=%d WHERE SteamID='%s'",
g_ClientUseCustom[client],
sAuth);