Jump to content

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


WalkinG

Recommended Posts

Posted

Sorry for my English

I wanted to make a simple rank but do not know how I can do this

take account of all the players and get the most value from a AccountData

value = getAccountData (source, "Kills") 
list = #value .... ????? 

Posted

Not sure what you mean but I assume you want to put every player in order of their kills. Start by storing all of the values into a table using a loop.

You can then use table.sort to sort the table as you wish, in your case by order of their kills. Good luck.

Posted
You can put all the kills into a table with the account name and use table.sort.

Op would not understand that, To be specific ill give you example

  
local t = {5, 1, 4, 2, 3} 
table.sort( t, function( a, b ) return a > b end ) 
outputChatBox(table.concat(t, ", ")) 
--result: 5, 4, 3, 2, 1 
  

Posted

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) 

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

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