Jump to content

[BUG] Top Players


WASSIm.

Recommended Posts

Hi guys i am back for long time,  i working for top 20 players like top player have high level and much money i hope help me for this errors

1) Its show all players not only 20

2) Its make server laggy so much when start resource or on select type of list

3) Got ERROR: Aborting infinite running script ZA-info when start resource

4) Some time got table nil

Server side

local statsList = {
    {"level", "Level", "lvl"},
    {"money", "Money", "$"},
    {"playTime", "Play Time"},
    {"kills", "Kills"},
    {"deaths", "Deaths"},
    {"zombieKills", "Zombie Kills"},
    {"bossKills", "Boss Kills"}
}

addEventHandler("onResourceStart", resourceRoot,
function()
    for i, list in ipairs(statsList) do
        local key = list[1]
        local accounts = getAccounts()
        local playerList = {}
        for i, account in ipairs(accounts) do
        	local data = exports["ZA-account"]:getAccountData(account, key)
        	local name = exports["ZA-account"]:getAccountData(account, "nick")
            if (data and tonumber(data)) then
            	table.insert(playerList, {name, tonumber(data)})
                --outputDebugString("Name: "..name.. " / "..key..": "..data or "N/A")
            end
        end
		table.sort(playerList, function(a, b) return a[2] > b[2] end)
        for i=20, #playerList do
        	table.remove(playerList, i)
        end
        statsList[i][4] = playerList
    end
end)

addEvent("onPlayerOpenTopPanel", true)
addEventHandler("onPlayerOpenTopPanel", root,
function( )
    triggerClientEvent(source, "onClientPlayerOpenTopPanel", source, statsList)
end)

 

Thanks for help!

NB: I edited this topic

Edited by WASSIm.
Fix some bugs
Link to comment
addEventHandler("onResourceStart", resourceRoot, function()
    local accounts = getAccounts()
    local accountsList = {}
    local keys = {}
    for index = 1, #statsList do
        accountsList[statsList[index][1]] = {}
        table.insert(keys, statsList[index][1])
    end
    for index = 1, #accounts do
        local account = accounts[index]
        local toRemove = {}
        for index = 1, #keys do
            local key = keys[index]
            local data = exports["ZA-account"]:getAccountData(account, key)
            local name = exports["ZA-account"]:getAccountData(account, "nick")
            if tonumber(data) then
                table.insert(accountsList[key], {name, tonumber(data)})
                if accountsList[key] >= 20 then
                    table.insert(toRemove, index)
                end
            end
        end
        for index = 1, #toRemove do
            table.remove(keys, toRemove[index])
        end
    end
    for index = 1, #statsList do
        table.sort(accountsList[statsList[index][1]], function(a, b) return a[2] > b[2] end)
        statsList[index][4] = accountsList[statsList[index][1]]
    end
end)

 

Edited by #,xiRocKyz
Link to comment

Sorry, I missed up a little bit on the previous code and I didn't notice.

Use this code instead :

addEventHandler("onResourceStart", resourceRoot, function()
    local accounts = getAccounts()
    local accountsList = {}
    for index = 1, #statsList do
        accountsList[statsList[index][1]] = {}
    end
    for index = 1, #accounts do
        local account = accounts[index]
        for index = 1, #statsList do
            local key = statsList[index][1]
            local data = exports["ZA-account"]:getAccountData(account, key)
            local name = exports["ZA-account"]:getAccountData(account, "nick")
            if tonumber(data) then
                table.insert(accountsList[key], {name, tonumber(data)})
            end
        end
    end
    for index = 1, #statsList do
        local accountsCount = #accountsList[statsList[index][1]]
        local accounts = {}
        if accountsCount >= 1 then
            table.sort(accountsList[statsList[index][1]], function(a, b) return a[2] > b[2] end)
            accounts = {unpack(accountsList[statsList[index][1]], 1, math.min(20, accountsCount))}
        end
        statsList[index][4] = accounts
    end
end)

 

Edited by #,xiRocKyz
Link to comment
10 hours ago, WASSIm. said:

Hi #,xiRocKyz sorry but your code complicated and is wrong its shows everything wrong on list anyway i fixed it and thank for your help

Which code were you using, maybe you used the first code that I gave you not the second.

Edited by #,xiRocKyz
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...