diff --git a/discord_verificiation/scripting/unloze_player_time.sp b/discord_verificiation/scripting/unloze_player_time.sp index acfe79f5..1600217c 100644 --- a/discord_verificiation/scripting/unloze_player_time.sp +++ b/discord_verificiation/scripting/unloze_player_time.sp @@ -5,6 +5,7 @@ Database g_hDatabase; Handle g_h_time_activity = null; +char g_cTimeRecords[100][128]; public Plugin myinfo = { @@ -90,6 +91,7 @@ public void SQL_OnDatabaseConnect(Database db, const char[] error, any data) g_hDatabase = db; for (int i = 1; i <= MaxClients; i++) OnClientPostAdminCheck(i); + OnMapStart(); } public void OnClientPostAdminCheck(int client) @@ -136,12 +138,12 @@ stock bool IsValidClient(int client) return false; } -public Action Command_TopTime(int client, int args) +public void OnMapStart() { if (!g_hDatabase) { Database.Connect(SQL_OnDatabaseConnect, "unloze_playtimestats"); - return Plugin_Handled; + return; } char sQuery[512]; char sServer[32]; @@ -165,11 +167,42 @@ public Action Command_TopTime(int client, int args) } else { - return Plugin_Handled; + return; } - Format(sQuery, sizeof(sQuery), "select steam_id, player_name, sum(%s) as %s_total from unloze_playtimestats.player_time GROUP BY steam_id order by %s_total desc limit 10", sServer, sServer, sServer); - g_hDatabase.Query(SQL_OnQueryCompletedTopTime, sQuery, GetClientSerial(client)); - return Plugin_Handled; + Format(sQuery, sizeof(sQuery), "select player_name, sum(%s) as %s_total from unloze_playtimestats.player_time GROUP BY steam_id order by %s_total desc limit 100", sServer, sServer, sServer); + g_hDatabase.Query(SQL_OnQueryCompletedTopTime, sQuery); +} + +public Action Command_TopTime(int client, int args) +{ + char sTitle[64]; + char sServer[32]; + int i_port = GetConVarInt(FindConVar("hostport")); + if (i_port == 27015 || i_port == 27019) + { + Format(sServer, sizeof(sServer), "ZE"); + } + else if (i_port == 27016) + { + Format(sServer, sizeof(sServer), "ZR"); + } + else if (i_port == 27017) + { + Format(sServer, sizeof(sServer), "MG"); + } + else if (i_port == 27023) + { + Format(sServer, sizeof(sServer), "JB"); + } + Format(sTitle, sizeof(sTitle), "[UNLOZE Playtime] Top 100 Record Holders for %s:", sServer); + Menu menu = new Menu(MenuHandler1); + menu.SetTitle(sTitle); + for (int i = 0; i < sizeof(g_cTimeRecords); i++) + { + menu.AddItem("-1", g_cTimeRecords[i], ITEMDRAW_DISABLED); + } + menu.ExitButton = true; + menu.Display(client, 0); } public Action Command_Time(int client, int args) @@ -193,58 +226,35 @@ public void SQL_OnQueryCompletedTopTime(Database db, DBResultSet results, const { LogError("Query error 3: %s", error); } - int client; - if ((client = GetClientFromSerial(iSerial)) == 0) - return; - char sServer[32]; - - int i_port = GetConVarInt(FindConVar("hostport")); - if (i_port == 27015 || i_port == 27019) - { - Format(sServer, sizeof(sServer), "ze_time"); - } - else if (i_port == 27016) - { - Format(sServer, sizeof(sServer), "zr_time"); - } - else if (i_port == 27017) - { - Format(sServer, sizeof(sServer), "mg_time"); - } - else if (i_port == 27023) - { - Format(sServer, sizeof(sServer), "jb_time"); - } int iTime; char sName[MAX_NAME_LENGTH]; - char sAuthID[32]; - Panel mSayPanel = new Panel(GetMenuStyleHandle(MenuStyle_Radio)); - char sTitle[64]; - Format(sTitle, sizeof(sTitle), "[UNLOZE Playtime] Record Holders for %s:", sServer); - mSayPanel.SetTitle(sTitle); - int counter = 1; + int counter = 0; while (results.RowCount && results.FetchRow()) { char sBuffer[256]; - results.FetchString(0, sAuthID, sizeof(sAuthID)); - results.FetchString(1, sName, sizeof(sName)); - iTime = results.FetchInt(2); - + results.FetchString(0, sName, sizeof(sName)); + iTime = results.FetchInt(1); int iHours = (iTime / 60) / 60; - Format(sBuffer, sizeof(sBuffer), "%i %s %d Hours", counter, sName, iHours); + Format(sBuffer, sizeof(sBuffer), "%i %s %d Hours", counter + 1, sName, iHours); + Format(g_cTimeRecords[counter], sizeof(g_cTimeRecords[]), sBuffer); counter++; - mSayPanel.DrawText(sBuffer); } - mSayPanel.DrawItem("", ITEMDRAW_SPACER); - mSayPanel.DrawItem("1. Got it!", ITEMDRAW_RAWLINE); - - mSayPanel.SetKeys(1023); - mSayPanel.Send(client, Handler_Menu, 0); - delete mSayPanel; delete results; } +public int MenuHandler1(Menu menu, MenuAction action, int param1, int param2) +{ + switch(action) + { + case MenuAction_End: + { + delete menu; + } + } + return 0; +} + public void SQL_OnQueryCompletedTime(Database db, DBResultSet results, const char[] error, int iSerial) { if (!db || strlen(error))