#include #include #include public Plugin myinfo = { name = "Toplvl", author = "jenz", description = "show toplvl for racetimer", version = "1.1", url = "" }; char g_cTimeRecords[100][128]; public void OnPluginStart() { RegConsoleCmd("sm_toplvl", Command_topLVL, "Displays top 100 players with highest level"); OnMapStart(); } public void OnTransferComplete(HTTPResponse response, any value) { if (response.Status != HTTPStatus_OK || response.Data == null) { LogError("Request-Error: %d", response.Status); return; } JSONObject obj = view_as(response.Data); int counter = 0; while (counter < 100) { char s_counter[4]; IntToString(counter, s_counter, sizeof(s_counter)); if (!obj.HasKey(s_counter)) { g_cTimeRecords[counter][0] = '\0'; counter++; continue; } JSONObject position_obj = view_as(obj.Get(s_counter)); int I_player_points = position_obj.GetInt("PlayerPoints"); char player_name[64]; if (!position_obj.GetString("name", player_name, sizeof(player_name))) player_name[0] = '\0'; Format(g_cTimeRecords[counter], sizeof(g_cTimeRecords[]), "%s LVL: %i", player_name, I_player_points/1000); delete position_obj; counter++; } delete obj; } public void OnMapStart() { char sRequest[256]; FormatEx(sRequest, sizeof(sRequest), "https://racebackend.unloze.com/racetimer_endpoints-1.0/api/timers/leaderboard/minified/0"); HTTPRequest hRequest = new HTTPRequest(sRequest); hRequest.Get(OnTransferComplete); } public int MenuHandler1(Menu menu, MenuAction action, int param1, int param2) { switch(action) { case MenuAction_End: { delete menu; } } return 0; } public Action Command_topLVL(int client, int args) { char sTitle[64]; Format(sTitle, sizeof(sTitle), "[UNLOZE RaceTimer] Top 100 highest levels"); 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); return Plugin_Handled; }