~DarkRacer~ Posted May 9, 2013 Share Posted May 9, 2013 Hi there, i have this script .. function top(playerSource, cmd, toptype) if toptype == "cash" then local moneyB = {} outputChatBox("Top 5 of rich players:",getRootElement(),255,120,0) for i,v in ipairs(getElementsByType('player')) do if i > 0 and i <= 5 then local serial = getPlayerSerial(v) local Money = executeSQLSelect ( "MoneyB", "Money","serial = '" .. serial .. "'") Money = Money[1]["Money"] outputChatBox("- "..i..": "..string.gsub(getPlayerName(v),"#%x%x%x%x%x%x","").." have $"..Money,getRootElement(),255,255,0) end end end end addCommandHandler("top",top) it outputs on chat 5 players with their names and money amounts. i want it to be arranged from the bigger player's money to the lower player's money, how can i do that? Example: - 1 : Player1 have $5000 - 2 : Player2 have $3500 - 3 : Player3 have $2000 - 4 : Player4 have $1500 - 5 : Player5 have $500 not - 1 : Player1 have $3500 - 2 : Player2 have $5000 - 3 : Player3 have $1500 - 4 : Player4 have $2000 - 5 : Player5 have $500 Link to comment
~DarkRacer~ Posted May 9, 2013 Author Share Posted May 9, 2013 but how can i use these functions i tried but it didn't work Link to comment
PaiN^ Posted May 9, 2013 Share Posted May 9, 2013 Hmm, Maybe stor the moneys in a table and then use : table.sort Link to comment
~DarkRacer~ Posted May 9, 2013 Author Share Posted May 9, 2013 Hmm, Maybe stor the moneys in a table and then use : table.sort i didn't understand the second parameter of the function table.sort (table [, comp]) Link to comment
~DarkRacer~ Posted May 9, 2013 Author Share Posted May 9, 2013 i have stored it all in a table like: tCash = { "Player1" = 5000, "Player2" = 4000, "Player3" = 3000, "Player4" = 2000, "Player5" = 1000, } but i don't know how to output it using loop .. Link to comment
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