Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.7 kB
1
Indexable
Never

std::unordered_map<std::string, int> playerLocks;
int sayi = 0;

for (const auto& p : std::filesystem::directory_iterator("players")) {
    json j;
    std::ifstream files(p.path());
    files >> j;

    int level = j["level"];
    if (level < 25) continue;

    std::string name = j["name"];
    int lock = j["opc"] / 2 + j["gems"] / 20000 + j["bpoi"] / 500;
    
    json inventory = j["inv"].get<json>();
    for (const auto& item : inventory) {
        int itemid = item["i"].get<int>();
        int itemcount = item["c"].get<int>();
        if (itemid == 242) {
            lock += itemcount;
        }
        if (itemid == 1796) {
            lock += itemcount * 100;
        }
        if (itemid == 7188) {
            lock += itemcount * 10000;
        }
    }

    playerLocks[name] = lock;
}

std::vector<std::pair<std::string, int>> players(playerLocks.begin(), playerLocks.end());
std::partial_sort(players.begin(), players.begin() + 100, players.end(),
    [](const std::pair<std::string, int>& a, const std::pair<std::string, int>& b) {
        return a.second > b.second;
    });

std::string btn = "";
for (const std::pair<std::string, int>& player : players) {
    if (sayi < 100) {
        btn += "\nadd_button|leader_" + player.first + "|`##" + std::to_string(sayi + 1) + " `w" + player.first + "|";
        sayi++;
    }
}

gamepacket_t k;
k.Insert("OnDialogRequest");
k.Insert("\nadd_label_with_icon|big|`wLeaderboard|left|394|\nadd_spacer|small|\nadd_smalltext|`1Note: Requirement is minimum 25 level!|\nadd_textbox|`oTop 100 Richest Players of Voidtopia:|\nadd_spacer|small|" + btn + "\nadd_spacer|\nadd_button|kk|Close|\nadd_quick_exit|");
k.CreatePacket(peer);