Jump to content

[Help] How to create a list of highest to lowest


WalkinG

Recommended Posts

then is it???

function rank (source) 
for p,contas in ipairs (getElementsByType('player')) do  
conta = getPlayerAccount(contas) 
nomes = getAccountName (conta) 
  kill= getAccountData (conta,"players.kills") 
  table.sort( kill, function( a, b ) return a > b end ) 
  outputChatBox(table.concat(kill, ", ")) 
  end 
end 
addCommandHandler ("ranking",rank) 

Link to comment
  
local kills = {} 
  
addEventHandler ("onResourceStart", getRootElement(), 
    function () 
        for _,player in ipairs (getElementsByType ("player")) do 
            local account = getPlayerAccount (player) 
            local playerKills = getAccountData (account, "player.kills") 
            table.insert (kills, playerKills) 
        end 
    end 
) 
  
addCommandHandler ("ranking", 
    function () 
        table.sort (kills, 
            function (a, b) 
                return a > b 
            end 
        ) 
         
        for _,v in ipairs (kills) do 
            outputChatBox (v) --is gonna output kills from highest to lowest 
        end 
    end 
) 
  

So firstly, you put all the players in a table (actually player's account) when the resource starts (you can change that as you wish, just an example). Once you do that, when you write /ranking the table is gonna sort and then the output with all the row as you want.

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...