Jump to content

Need help with TOP 10 player points.


Chilco

Recommended Posts

Hello people,

I already made a little system to collect points by playing games in (race) dd/dm.

You can see the points in TAB (I created a column)

Now I wanna make a top 10 of the players with the most points.

I already made a GUI with 10 labels (1. [NAME] ([NUMBER POINTS] Points) 2. [NAME] ([NUMBER POINTS] Points) etc.)

Now I need help, I dont know how to make it.

If someone can help me, that will be great.

-Chilco

Link to comment

You can easily sort values within SQL queries. That's only if you use SQL tables to store points. You can also sort numbers in tables.

points = { 4, 6, 7, 8, 5, 9 }
table.sort( points );
for k, v in ipairs( points ) do
print( k .. ".  " .. v );
end
--[[
1. 4
2. 6
3. 7
4. 8
5. 5
6. 9
]]

If you want the highest to be on top and the lowest on bottom then you have to make a function which will compare 2 numbers and return the higher one. And use this function in table.sort function. Like so:

table.sort( points, function( a, b ) return a > b end );
--[[
output:
1. 9
2. 8
3. 7
4. 6
5. 5
6. 4 
]]

If you want to know more about table.sort function or sorting in Lua go here:

http://www.lua.org/manual/5.1/manual.ht ... table.sort

http://www.lua.org/pil/19.3.html

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