This repository has been archived by the owner on Aug 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Modular_LS.sp
1392 lines (1019 loc) · 34.9 KB
/
Modular_LS.sp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#pragma semicolon 1
#define PLUGIN_AUTHOR "Fishy"
#define PLUGIN_VERSION "2.0.0"
#include <sourcemod>
#include <sdktools>
#include <morecolors>
#include <SteamWorks>
#undef REQUIRE_PLUGIN
#include <EventLogs>
#undef REQUIRE_EXTENSIONS
#include <steamtools>
#pragma newdecls required
#define BaseXP 10.0
#define MaxBonusHour 2
#define MaxPL 5
#define MaxPLL 50
#define Bar_Fill "█"
#define Bar_Empty "░"
#define DoubleXPSymbol "ϟ"
#define Sound_LVL "ls/lvl.wav"
#define Sound_Prestige "ls/prestige.wav"
#define Sound_Alarm "ambient_mp3/alarms/doomsday_lift_alarm.mp3"
#define Sound_LVL_Absolute "sound/ls/lvl.wav"
#define Sound_Prestige_Absolute "sound/ls/prestige.wav"
#define Sound_Alarm_Absolute "sound/ambient_mp3/alarms/doomsday_lift_alarm.mp3"
#define MemberGroupID32 28307369
#define TesterGroupID32 29292279
enum LSPL
{
LSPL_0,
LSPL_1,
LSPL_2,
LSPL_3,
LSPL_4,
LSPL_5,
LSPL_Count
}
enum LSRL
{
LSRL_Admin,
LSRL_Tester,
LSRL_Donor,
LSRL_Member,
LSRL_Normal,
LSRL_Count
}
enum LSPL_Multiplier
{
LSPL_Multiplier_0 = 1.175,
LSPL_Multiplier_1 = 1.185,
LSPL_Multiplier_2 = 1.195,
LSPL_Multiplier_3 = 1.20,
LSPL_Multiplier_4 = 1.22,
LSPL_Multiplier_Invalid
}
char LSPL_Titles[LSPL_Count][] = {
"F",
"D",
"C",
"B",
"A",
"S"
};
char LSRL_Titles[LSRL_Count][] = {
"Chief",
"Tester",
"Spark",
"Member",
""
};
// Prestige is 0 indexed
int g_iPrestigeColors[MaxPL + 1][3] = {
{ 211, 218, 229 },
{ 50, 10, 141 },
{ 184, 134, 11 },
{ 14, 237, 199 },
{ 158, 20, 20 },
{ 211, 44, 230 },
};
int g_iPrestigeDefaultColor[3] = { 211, 211, 211 };
//<!-- Main -->
Database hDB;
bool Verbose;
Handle Progression_Hud;
Handle LevelForward;
Handle PrestigeForward;
Handle LoadedForward;
bool DoubleXP;
enum struct Player {
bool bIsLoaded;
bool bInMemberGroup;
bool bInTesterGroup;
int iXPGained;
int iXP;
int iPrestige;
int iLevel;
int iXPAtLevel;
int iXPToNextLevel;
char sProgressBar[64];
int iColors[3];
void UpdateColors() {
if (this.iPrestige > MaxPL) {
this.iColors[0] = g_iPrestigeDefaultColor[0];
this.iColors[1] = g_iPrestigeDefaultColor[1];
this.iColors[2] = g_iPrestigeDefaultColor[2];
return;
}
this.iColors[0] = g_iPrestigeColors[this.iPrestige][0];
this.iColors[1] = g_iPrestigeColors[this.iPrestige][1];
this.iColors[2] = g_iPrestigeColors[this.iPrestige][2];
}
// Incase we don't want foreign plugins to modify it
void CloneColors(iColors[3]) {
this.UpdateColors();
iColors[0] = this.iColors[0];
iColors[1] = this.iColors[1];
iColors[2] = this.iColors[2];
}
}
Player g_pPlayers[MAXPLAYERS + 1];
#define LOOP_CLIENTS(%1) for (int %1=0; %1 <= MaxClients; %1++)
public Plugin myinfo =
{
name = "Modular LS",
author = PLUGIN_AUTHOR,
description = "Modular Leveling System",
version = PLUGIN_VERSION,
url = "https://keybase.io/rumblefrog"
};
public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
{
Database.Connect(OnDatabaseConnected, "modular_ls");
RegPluginLibrary("Modular_LS");
CreateNative("MLS_GetUserLevel", Native_GetUserLevel);
CreateNative("MLS_GetUserPrestige", Native_GetUserPrestige);
CreateNative("MLS_GetUserRank", Native_GetUserRank);
CreateNative("MLS_GetPrestigeColorRGB", Native_GetPrestigeColorRGB);
CreateNative("MLS_GetPrestigeColorHex", Native_GetPrestigeColorHex);
CreateNative("MLS_GetPrestigeTitle", Native_GetPrestigeTitle);
CreateNative("MLS_GetRankTitle", Native_GetRankTitle);
CreateNative("MLS_AddXP", Native_AddXP);
CreateNative("MLS_PrintToClient", Native_PrintToClient);
CreateNative("MLS_IsLoaded", Native_IsLoaded);
return APLRes_Success;
}
public void OnDatabaseConnected(Database db, const char[] error, any data)
{
hDB = db;
char TableCreateSQL[] = "CREATE TABLE IF NOT EXISTS `Modular_LS` ( `id` INT NOT NULL AUTO_INCREMENT , `steamid` VARCHAR(32) NOT NULL , `name` VARCHAR(32) NOT NULL , `xp` BIGINT NOT NULL DEFAULT '0' , `prestige` TINYINT NOT NULL DEFAULT '0' , `creation_date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP , PRIMARY KEY (`id`), INDEX (`prestige`), UNIQUE (`steamid`)) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_general_ci";
// Note that utf8mb4 is only available for sm10+
// https://github.com/alliedmodders/sourcemod/commit/4637cf9221ca3329a6e71b4317839a77e11d88ee
hDB.SetCharset("utf8mb4");
hDB.Query(OnTableCreate, TableCreateSQL, _, DBPrio_High);
}
public void OnTableCreate(Database db, DBResultSet results, const char[] error, any pData)
{
if (results == null)
{
EL_LogPlugin(LOG_FATAL, "Unable to create MLS table: %s", error);
SetFailState("Unable to create table: %s", error);
}
}
public void OnPluginStart()
{
RegConsoleCmd("sm_prestige", CmdPrestige, "Prestige!");
RegConsoleCmd("sm_top10", CmdTop10, "Displays Top 10");
RegConsoleCmd("sm_rank", CmdRank, "Displays Current Rank");
RegConsoleCmd("sm_session", CmdSession, "Displays Session Data");
RegAdminCmd("sm_mls_dump", CmdDump, 0, "Dump user data");
RegAdminCmd("sm_mls_debug", CmdToggleDebug, ADMFLAG_CHEATS, "Toggle Console Debugging");
//RegAdminCmd("sm_mls_addxp", CmdAddXP, 0, "DEBUG: Add XP"); //TODO: REMOVE FOR RELEASE
RegAdminCmd("sm_mls_setprestige", CmdSetPrestige, ADMFLAG_ROOT, "DEBUG: Set Prestige Level");
RegAdminCmd("sm_mls_doublexp", CmdDoubleXP, ADMFLAG_ROOT, "Toggle Double XP Session");
RegAdminCmd("mls_core_donor_permission", CmdVoid, ADMFLAG_RESERVATION);
RegAdminCmd("mls_core_admin_permission", CmdVoid, ADMFLAG_GENERIC);
Progression_Hud = CreateHudSynchronizer();
LevelForward = CreateGlobalForward("MLS_OnClientLeveledUp", ET_Ignore, Param_Cell, Param_Cell, Param_Cell);
PrestigeForward = CreateGlobalForward("MLS_OnClientPrestige", ET_Ignore, Param_Cell, Param_Cell, Param_Cell);
LoadedForward = CreateGlobalForward("MLS_OnClientDataLoaded", ET_Ignore, Param_Cell);
HookEvent("player_connect", EventConnect, EventHookMode_Pre);
HookEvent("player_disconnect", EventDisconnect, EventHookMode_Pre);
}
public void OnMapStart()
{
CreateTimer(0.5, Timer_Progression_Hud, _, TIMER_REPEAT);
PrecacheSound(Sound_LVL, true);
PrecacheSound(Sound_Prestige, true);
PrecacheSound(Sound_Alarm, true); //No need to download, already in TF2 assets
AddFileToDownloadsTable(Sound_LVL_Absolute);
AddFileToDownloadsTable(Sound_Prestige_Absolute);
}
public void OnMapEnd()
{
DoubleXP = false;
}
public Action Timer_Progression_Hud(Handle hTimer)
{
LOOP_CLIENTS(iClient)
{
if (IsValidClient(iClient))
{
g_pPlayers[iClient].UpdateColors();
SetHudTextParams(0.05, 0.10, 0.6, 0, g_pPlayers[iClient].iColors[0], g_pPlayers[iClient].iColors[1], g_pPlayers[iClient].iColors[2], 0);
if (g_pPlayers[iClient].iPrestige != MaxPL)
{
if (g_pPlayers[iClient].iLevel == -1 || g_pPlayers[iClient].iXPAtLevel == -1 || g_pPlayers[iClient].iXPToNextLevel == -1)
ShowSyncHudText(iClient, Progression_Hud, "N/A");
else
{
GenerateProgressBar(g_pPlayers[iClient].iXPAtLevel, g_pPlayers[iClient].iXPToNextLevel, g_pPlayers[iClient].sProgressBar, sizeof Player::sProgressBar);
ShowSyncHudText(iClient, Progression_Hud, "[Lvl] %i: %s %i/%i %s", g_pPlayers[iClient].iLevel, g_pPlayers[iClient].sProgressBar, g_pPlayers[iClient].iXPAtLevel, g_pPlayers[iClient].iXPToNextLevel, (DoubleXP ? DoubleXPSymbol : ""));
}
} else
ShowSyncHudText(iClient, Progression_Hud, "Reached Max Prestige: %i XP", g_pPlayers[iClient].iXP);
}
}
}
public Action CmdVoid(int iClient, int args)
{
return Plugin_Handled;
}
public Action CmdTop10(int iClient, int args)
{
ShowTop10(iClient);
return Plugin_Handled;
}
public Action CmdRank(int iClient, int args)
{
ShowRank(iClient);
return Plugin_Handled;
}
public Action CmdSession(int iClient, int args)
{
ShowSession(iClient);
return Plugin_Handled;
}
public Action CmdDoubleXP(int iClient, int args)
{
if (DoubleXP)
{
CReplyToCommand(iClient, "{lightseagreen}[MaxDB] {grey}Disabled Double XP Session");
CPrintToChatAll("{lightseagreen}[MaxDB] {deeppink}DoubleXP Event was ended by {chartreuse}%N{deeppink}.", iClient);
}
else
{
CReplyToCommand(iClient, "{lightseagreen}[MaxDB] {grey}Enabled Double XP Session");
CPrintToChatAll("{lightseagreen}[MaxDB] {deeppink}DoubleXP Event was started by {chartreuse}%N{deeppink}.", iClient);
EmitSoundToAll(Sound_Alarm);
EmitSoundToAll(Sound_Alarm);
}
DoubleXP = !DoubleXP;
return Plugin_Handled;
}
public void OnClientSayCommand_Post(int iClient, const char[] command, const char[] sArgs)
{
if (strcmp(command, "say") == 0 || strcmp(command, "say_team") == 0)
{
if (strcmp(sArgs, "top10") == 0)
ShowTop10(iClient);
if (strcmp(sArgs, "rank") == 0)
ShowRank(iClient);
if (strcmp(sArgs, "session") == 0)
ShowSession(iClient);
}
}
public Action CmdToggleDebug(int iClient, int args)
{
if (!Verbose)
CReplyToCommand(iClient, "{lightseagreen}[MaxDB] {grey}Enabled verbose logging");
else
CReplyToCommand(iClient, "{lightseagreen}[MaxDB] {grey}Disabled verbose logging");
Verbose = !Verbose;
return Plugin_Handled;
}
public Action CmdAddXP(int iClient, int args)
{
if (args < 1)
{
CReplyToCommand(iClient, "{lightseagreen}[MaxDB] {grey}Missing XP");
return Plugin_Handled;
}
if (!CanGainXP(iClient))
{
CReplyToCommand(iClient, "{lightseagreen}[MaxDB] {grey}Cannot gain XP");
return Plugin_Handled;
}
char buffer[16];
GetCmdArg(1, buffer, sizeof buffer);
int input = StringToInt(buffer);
int EXP = GetXPValue(iClient, input);
AddXPToUser(iClient, EXP);
CReplyToCommand(iClient, "{lightseagreen}[MaxDB] {grey}Requested %i XP to be added", EXP);
return Plugin_Handled;
}
public Action CmdSetPrestige(int iClient, int args)
{
if (args < 1)
{
CReplyToCommand(iClient, "{lightseagreen}[MaxDB] {grey}Missing Prestige");
return Plugin_Handled;
}
char buffer[16];
GetCmdArg(1, buffer, sizeof buffer);
int prestigel = StringToInt(buffer);
g_pPlayers[iClient].iPrestige = prestigel;
return Plugin_Handled;
}
public Action CmdDump(int iClient, int args)
{
PrintToConsole(iClient, "Base: %f", BaseXP);
PrintToConsole(iClient, "XP: %i", g_pPlayers[iClient].iXP);
PrintToConsole(iClient, "Prestige: %i", g_pPlayers[iClient].iPrestige);
PrintToConsole(iClient, "Prestige Multiplier: %f", view_as<float>(GetMultiplierByPrestige(iClient)));
PrintToConsole(iClient, "Level: %i", g_pPlayers[iClient].iLevel);
PrintToConsole(iClient, "XPAtLevel: %i", g_pPlayers[iClient].iXPAtLevel);
PrintToConsole(iClient, "XPToNextLevel: %i", g_pPlayers[iClient].iXPToNextLevel);
PrintToConsole(iClient, "<-------------------------->");
PrintToConsole(iClient, "TEST1: %f", g_pPlayers[iClient].iXP / BaseXP);
PrintToConsole(iClient, "TEST2: %i", g_pPlayers[iClient].bInMemberGroup);
PrintToConsole(iClient, "TEST3: %i", g_pPlayers[iClient].bInTesterGroup);
return Plugin_Handled;
}
public Action CmdPrestige(int iClient, int args)
{
if (g_pPlayers[iClient].iXP == -1 || g_pPlayers[iClient].iPrestige == -1)
{
CReplyToCommand(iClient, "{lightseagreen}[MaxDB] {grey}Oops, unable to prestige.");
return Plugin_Handled;
}
if (g_pPlayers[iClient].iPrestige >= MaxPL)
{
CReplyToCommand(iClient, "{lightseagreen}[MaxDB] {grey}You have reached the highest prestige!");
return Plugin_Handled;
}
int UserLevel = GetUserLevel(iClient);
if (UserLevel != MaxPLL || UserLevel == -1)
{
CReplyToCommand(iClient, "{lightseagreen}[MaxDB] {grey}You can only prestige at level %i!", MaxPLL);
return Plugin_Handled;
}
char Update_Query[1024], Client_SteamID64[32];
GetClientAuthId(iClient, AuthId_SteamID64, Client_SteamID64, sizeof Client_SteamID64);
Format(Update_Query, sizeof Update_Query, "UPDATE Modular_LS SET `xp` = 0, `prestige`= `prestige` + 1 WHERE `steamid` = '%s'", Client_SteamID64);
DataPack pData = new DataPack();
pData.WriteCell(GetCmdReplySource());
pData.WriteCell(GetClientUserId(iClient));
hDB.Query(SQL_OnPlayerPrestige, Update_Query, pData);
return Plugin_Handled;
}
public void SQL_OnPlayerPrestige(Database db, DBResultSet results, const char[] error, DataPack pData)
{
pData.Reset();
ReplySource CmdOrigin = pData.ReadCell();
int iClient = GetClientOfUserId(pData.ReadCell());
delete pData;
if (iClient == 0)
return;
SetCmdReplySource(CmdOrigin);
if (results == null)
{
ReplyToCommand(iClient, "Fail to prestige, please try again later");
return;
}
EmitSoundToClient(iClient, Sound_Prestige);
EmitSoundToClient(iClient, Sound_Prestige);
CPrintToChat(iClient, "{lightseagreen}[MaxDB] {grey}You have prestiged!");
g_pPlayers[iClient].iXP = 0;
g_pPlayers[iClient].iPrestige++;
Call_StartForward(PrestigeForward);
Call_PushCell(iClient);
Call_PushCell(0); //Always 0 on prestige "g_pPlayers[iClient].iXP = 0;"
Call_PushCell(g_pPlayers[iClient].iPrestige);
Call_Finish();
CalculateValues(iClient);
}
void ShowTop10(int iClient)
{
char Select_Query[128];
Format(Select_Query, sizeof Select_Query, "SELECT * FROM Modular_LS ORDER BY `prestige` DESC, `xp` DESC LIMIT 10");
hDB.Query(SQL_OnShowTop10, Select_Query, iClient);
}
void ShowRank(int iClient)
{
char Select_Query[512], Client_SteamID64[32];
GetClientAuthId(iClient, AuthId_SteamID64, Client_SteamID64, sizeof Client_SteamID64);
// MariaDB 10.x OR MySQL 8.x above only
// Format(Select_Query, sizeof Select_Query, "SELECT rank, total FROM (SELECT ROW_NUMBER() OVER (ORDER BY `prestige` DESC, `xp` DESC) AS rank, (SELECT COUNT(*) FROM Modular_LS) AS total, steamid FROM Modular_LS) sub WHERE sub.steamid = '%s'", Client_SteamID64);
// MariaDB 10.x OR MySQL 8.x below only
Format(Select_Query, sizeof Select_Query, "SELECT sub.rank, sub.total FROM (SELECT t.id, t.steamid, @rownum := @rownum + 1 AS rank, (SELECT COUNT(*) FROM Modular_LS) AS total FROM Modular_LS t JOIN (SELECT @rownum := 0) r ORDER BY t.prestige DESC, t.xp DESC) sub WHERE sub.steamid = '%s'", Client_SteamID64);
hDB.Query(SQL_OnShowRank, Select_Query, iClient);
}
void ShowSession(int iClient)
{
char buffer[64];
Panel Session = new Panel();
Session.SetTitle("Current Session");
Session.DrawItem("Name");
GetClientName(iClient, buffer, sizeof buffer);
Session.DrawText(buffer);
Session.DrawItem("Rank");
GetUserPrefix(iClient, buffer, sizeof buffer, true);
Session.DrawText(buffer);
Session.DrawItem("XP Gained");
Format(buffer, sizeof buffer, "%i", g_pPlayers[iClient].iXPGained);
Session.DrawText(buffer);
Session.DrawItem("Session Time");
int Client_Time = RoundToNearest(GetClientTime(iClient));
Format(buffer, sizeof buffer, "%ih %im %is", Client_Time / 3600 % 24, Client_Time / 60 % 60, Client_Time % 60);
Session.DrawText(buffer);
Session.Send(iClient, VoidMenuHandler, MENU_TIME_FOREVER);
delete Session;
}
public void SQL_OnShowRank(Database db, DBResultSet results, const char[] error, any iClient)
{
if (results == null)
{
EL_LogPlugin(LOG_ERROR, "Unable to fetch player rank: %s", error);
CPrintToChat(iClient, "{lightseagreen}[MaxDB] {grey}Unable to fetch your rank.");
if (Verbose)
PrintToConsole(iClient, "Query Error: %s", error);
return;
}
results.FetchRow();
char Hex_Name[16], Prefix[64], Client_Name[32];
int Pos = results.FetchInt(0); //TODO: Sometimes invalid
int Total = results.FetchInt(1);
int Hex = GetColorHex(iClient);
IntToString(Hex, Hex_Name, sizeof Hex_Name);
CAddColor(Hex_Name, Hex);
GetUserPrefix(iClient, Prefix, sizeof Prefix, true);
GetClientName(iClient, Client_Name, sizeof Client_Name);
CPrintToChatAll("{lightseagreen}[MaxDB] {grey}Player {lightseagreen}[{%s}%s{lightseagreen}] {chartreuse}%s {grey}is rank {aqua}%i {gray}out of {deepskyblue}%i{grey}.", Hex_Name, Prefix, Client_Name, Pos, Total);
}
public void SQL_OnShowTop10(Database db, DBResultSet results, const char[] error, any iClient)
{
if (results == null)
{
EL_LogPlugin(LOG_ERROR, "Unable to fetch top 10: %s", error);
CPrintToChat(iClient, "{lightseagreen}[MaxDB] {grey}Unable to fetch top 10 data.");
if (Verbose)
PrintToConsole(iClient, "Query Error: %s", error);
return;
}
Panel Top10 = new Panel();
char Position[128], Name[32], Prefix[64];
int Prestige_Buffer, XP_Buffer, Index = 1;
Top10.SetTitle("Top 10 Ranking");
while (results.FetchRow())
{
results.FetchString(2, Name, sizeof Name);
XP_Buffer = results.FetchInt(3);
Prestige_Buffer = results.FetchInt(4);
GetUserPrefixFromData(Prestige_Buffer, XP_Buffer, Prefix, sizeof Prefix);
if (Index >= 10)
{
Format(Position, sizeof Position, "%i. %s - %s", Index, Name, Prefix);
Top10.DrawText(Position);
} else
{
Format(Position, sizeof Position, "%s - %s", Name, Prefix);
Top10.DrawItem(Position);
}
Index++;
}
Top10.Send(iClient, VoidMenuHandler, MENU_TIME_FOREVER);
delete Top10;
}
public int VoidMenuHandler(Menu menu, MenuAction action, int param1, int param2)
{
}
public void OnClientPostAdminCheck(int iClient)
{
if (!IsValidClientExcludeData(iClient))
return;
if (!IsClientConnected(iClient))
return;
char Select_Query[1024], Client_SteamID64[32];
GetClientAuthId(iClient, AuthId_SteamID64, Client_SteamID64, sizeof Client_SteamID64);
SteamWorks_GetUserGroupStatus(iClient, MemberGroupID32);
SteamWorks_GetUserGroupStatus(iClient, TesterGroupID32);
Format(Select_Query, sizeof Select_Query, "SELECT * FROM Modular_LS WHERE `steamid` = '%s'", Client_SteamID64);
DataPack pData = new DataPack();
pData.WriteCell(GetClientUserId(iClient));
pData.WriteString(Client_SteamID64);
hDB.Query(SQL_OnFetchPlayerData, Select_Query, pData);
}
public void OnClientDisconnect(int iClient)
{
if (g_pPlayers[iClient].bIsLoaded)
{
char Hex_Name[16], Prefix[64], Client_Name[32];
int Hex = GetColorHex(iClient);
IntToString(Hex, Hex_Name, sizeof Hex_Name);
CAddColor(Hex_Name, Hex);
GetUserPrefix(iClient, Prefix, sizeof Prefix, true);
GetClientName(iClient, Client_Name, sizeof Client_Name);
CPrintToChatAll("{lightseagreen}[MaxDB] {grey}Player {lightseagreen}[{%s}%s{lightseagreen}] {chartreuse}%s {grey}disconnected.", Hex_Name, Prefix, Client_Name);
}
g_pPlayers[iClient].bIsLoaded = false;
g_pPlayers[iClient].bInMemberGroup = false;
g_pPlayers[iClient].bInTesterGroup = false;
g_pPlayers[iClient].iXPGained = 0;
g_pPlayers[iClient].iXP = -1;
g_pPlayers[iClient].iPrestige = -1;
g_pPlayers[iClient].iLevel = -1;
g_pPlayers[iClient].iXPAtLevel = -1;
g_pPlayers[iClient].iXPToNextLevel = -1;
}
public void SQL_OnFetchPlayerData(Database db, DBResultSet results, const char[] error, DataPack pData)
{
if (results == null)
{
EL_LogPlugin(LOG_ERROR, "Unable to fetch player data: %s", error);
return;
}
pData.Reset();
int iClient = GetClientOfUserId(pData.ReadCell());
delete pData;
if (iClient == 0)
return;
if (results.RowCount == 0)
{
char Client_SteamID64[32], Insert_Query[1024], Client_Name[32], Escaped_Client_Name[65];
ReadPackString(pData, Client_SteamID64, sizeof Client_SteamID64);
GetClientName(iClient, Client_Name, sizeof Client_Name);
db.Escape(Client_Name, Escaped_Client_Name, sizeof Escaped_Client_Name);
Format(Insert_Query, sizeof Insert_Query, "INSERT INTO Modular_LS (`steamid`, `name`) VALUES ('%s', '%s')", Client_SteamID64, Escaped_Client_Name);
db.Query(SQL_OnCreatePlayerData, Insert_Query, iClient);
return;
}
results.FetchRow();
g_pPlayers[iClient].iXP = results.FetchInt(3);
g_pPlayers[iClient].iPrestige = results.FetchInt(4);
CalculateValues(iClient);
g_pPlayers[iClient].bIsLoaded = true;
Call_StartForward(LoadedForward);
Call_PushCell(iClient);
Call_Finish();
char Hex_Name[16], Prefix[64], Client_Name[32];
int Hex = GetColorHex(iClient);
IntToString(Hex, Hex_Name, sizeof Hex_Name);
CAddColor(Hex_Name, Hex);
GetUserPrefix(iClient, Prefix, sizeof Prefix, true);
GetClientName(iClient, Client_Name, sizeof Client_Name);
CPrintToChatAll("{lightseagreen}[MaxDB] {grey}Player {lightseagreen}[{%s}%s{lightseagreen}] {chartreuse}%s {grey}connected.", Hex_Name, Prefix, Client_Name);
}
public void SQL_OnCreatePlayerData(Database db, DBResultSet results, const char[] error, any iClient)
{
if (results == null)
{
EL_LogPlugin(LOG_ERROR, "Unable to create player data: %s", error);
if (Verbose)
PrintToConsole(iClient, "Unable to create player data: %s", error);
}
g_pPlayers[iClient].iXP = 0;
g_pPlayers[iClient].iPrestige = 0;
CalculateValues(iClient);
g_pPlayers[iClient].bIsLoaded = true;
Call_StartForward(LoadedForward);
Call_PushCell(iClient);
Call_Finish();
}
int GetXPValue(int iClient, int base_xp)
{
float MaxBase = 1.0;
if (g_pPlayers[iClient].bInMemberGroup)
MaxBase += 0.2;
float SessionTime = GetClientTime(iClient);
float MaxBonusMultiplier = ((MaxBonusHour * 0.5) + MaxBase);
int MaxBonusSession = (60 * 60 * MaxBonusHour);
int StandardXP;
if (SessionTime >= MaxBonusSession)
StandardXP = RoundToNearest(base_xp * MaxBonusMultiplier);
else
StandardXP = RoundToNearest(base_xp * ((SessionTime / MaxBonusSession) + MaxBase));
if (DoubleXP)
return (StandardXP * 2);
else
return StandardXP;
}
void AddXPToUser(int iClient, int xp)
{
if (!CanGainXP(iClient))
return;
char Update_Query[1024], Client_SteamID64[32], Client_Name[32], Escaped_Client_Name[65];
GetClientAuthId(iClient, AuthId_SteamID64, Client_SteamID64, sizeof Client_SteamID64);
GetClientName(iClient, Client_Name, sizeof Client_Name);
hDB.Escape(Client_Name, Escaped_Client_Name, sizeof Escaped_Client_Name);
Format(Update_Query, sizeof Update_Query, "UPDATE Modular_LS SET `xp` = `xp` + '%u', `name` = '%s' WHERE `steamid` = '%s'", xp, Escaped_Client_Name, Client_SteamID64);
DataPack pData = new DataPack();
pData.WriteCell(GetClientUserId(iClient));
pData.WriteCell(xp);
hDB.Query(SQL_OnAddXPToUser, Update_Query, pData);
}
public void SQL_OnAddXPToUser(Database db, DBResultSet results, const char[] error, DataPack pData)
{
pData.Reset();
int iClient = GetClientOfUserId(pData.ReadCell());
int xp = pData.ReadCell();
delete pData;
if (iClient == 0)
return;
if (results == null)
{
EL_LogPlugin(LOG_ERROR, "Unable to add XP to player: %s", error);
if (Verbose)
PrintToConsole(iClient, "Unable to add XP to player: %s", error);
}
g_pPlayers[iClient].iXP += xp;
g_pPlayers[iClient].iXPGained += xp;
CalculateValues(iClient);
}
LSPL_Multiplier GetMultiplierByPrestige(int iClient)
{
if (!IsValidClient(iClient))
return LSPL_Multiplier_Invalid;
switch (g_pPlayers[iClient].iPrestige)
{
case 0:
return LSPL_Multiplier_0;
case 1:
return LSPL_Multiplier_1;
case 2:
return LSPL_Multiplier_2;
case 3:
return LSPL_Multiplier_3;
case 4:
return LSPL_Multiplier_4;
default:
return LSPL_Multiplier_Invalid;
}
}
LSPL_Multiplier GetMultiplierByPrestigeData(int prestige_data)
{
switch (prestige_data)
{
case 0:
return LSPL_Multiplier_0;
case 1:
return LSPL_Multiplier_1;
case 2:
return LSPL_Multiplier_2;
case 3:
return LSPL_Multiplier_3;
case 4:
return LSPL_Multiplier_4;
default:
return LSPL_Multiplier_Invalid;
}
}
bool CanGainXP(int iClient)
{
if (g_pPlayers[iClient].iXP == -1 || g_pPlayers[iClient].iPrestige == -1)
return false;
int UserLevel = GetUserLevel(iClient);
if (UserLevel == -1)
{
if (Verbose)
CPrintToChat(iClient, "{lightseagreen}[MaxDB] {grey}Invalid Level.");
return false;
}
CalculateValues(iClient);
if (UserLevel >= MaxPLL)
{
if (g_pPlayers[iClient].iPrestige >= MaxPL) //Allow progressing further but no levels
return true;
else
{
if (Verbose)
CPrintToChat(iClient, "{lightseagreen}[MaxDB] {grey}In order to earn more levels, prestige first!");
return false;
}
}
return true;
}
void CalculateValues(int iClient)
{
int OriginLevel = g_pPlayers[iClient].iLevel;
g_pPlayers[iClient].iLevel = GetUserLevel(iClient);
if (g_pPlayers[iClient].iLevel == -1)
{
g_pPlayers[iClient].iXPToNextLevel = -1;
g_pPlayers[iClient].iXPAtLevel = -1;
return;
}
LSPL_Multiplier Multiplier = GetMultiplierByPrestige(iClient);
if (Multiplier == LSPL_Multiplier_Invalid)
{
g_pPlayers[iClient].iXPToNextLevel = -1;
g_pPlayers[iClient].iXPAtLevel = -1;
return;
}
if (g_pPlayers[iClient].iLevel >= MaxPLL)
{
int MaxXPAtCurrent = GetXPFromLevel(MaxPLL, Multiplier);
g_pPlayers[iClient].iXPToNextLevel = MaxXPAtCurrent;
g_pPlayers[iClient].iXPAtLevel = MaxXPAtCurrent;
return;
}
if (g_pPlayers[iClient].iXP < BaseXP)
{
g_pPlayers[iClient].iXPToNextLevel = 10;
g_pPlayers[iClient].iXPAtLevel = 0;
return;
}
if (OriginLevel != -1 && g_pPlayers[iClient].iLevel > OriginLevel)
{
Call_StartForward(LevelForward);
Call_PushCell(iClient);
Call_PushCell(g_pPlayers[iClient].iLevel);
Call_PushCell(g_pPlayers[iClient].iPrestige);
Call_Finish();
EmitSoundToClient(iClient, Sound_LVL);
EmitSoundToClient(iClient, Sound_LVL);
CPrintToChat(iClient, "{lightseagreen}[MaxDB] {grey}You have leveled up!");
}
int CurrentLevelXPBuffer = GetXPFromLevel(g_pPlayers[iClient].iLevel, Multiplier);
int NextLevel = g_pPlayers[iClient].iLevel + 1;
int NextLevelBuffer = GetXPFromLevel(NextLevel, Multiplier);
g_pPlayers[iClient].iXPToNextLevel = NextLevelBuffer - CurrentLevelXPBuffer;
g_pPlayers[iClient].iXPAtLevel = g_pPlayers[iClient].iXP - CurrentLevelXPBuffer;
}
int GetUserLevel(int iClient)
{
LSPL_Multiplier multiplier = GetMultiplierByPrestige(iClient);