WalkinG Posted August 22, 2016 Posted August 22, 2016 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 .... ?????
StefanAlmighty Posted August 22, 2016 Posted August 22, 2016 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.
xXMADEXx Posted August 22, 2016 Posted August 22, 2016 You can put all the kills into a table with the account name and use table.sort.
roaddog Posted August 23, 2016 Posted August 23, 2016 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
WalkinG Posted August 23, 2016 Author Posted August 23, 2016 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)
LabiVila Posted August 23, 2016 Posted August 23, 2016 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.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now