Jump to content

top list


Fury

Recommended Posts

hello guys, i have made a stats system for race with getAccountData and setAccountData. i want to make a top list for it. i have "nick" data and i want make it top "wins", "points", "second", "third" list like that.

top 5 wins 
1. F*ckN|V - 18 
2. F*ckN|Deiter - 12 
3. F*ckN|Vendetta - 10 
4. F*ckN|Deitas - 8 
5. F*ckN|Vienetta - 2 

i know i have to use table.sort. but i dont know to use account database thing.

local amountOfTopsToDisplay = 5  
addCommandHandler("top", 
    function(player, command, value) 
            if value == "wins" or value == "points" or value == "second" or value == "third" then  
                local tableOrder = {}  
                local subTable = {}  
                for i,v do  
                    subTable.name = getAccountData( v, "nick" )  
                    subTable.data = getAccountData( v, vaule )   
                    table.insert(tableOrder, subTable)  
                    subTable = {}  
                end 
                table.sort(tableOrder, function(a,b) return tonumber(a.data)>tonumber(b.data) end)  
                outputChatBox("#c0c0c0* Top 5 #abcdef"..value, player, 255,255,255,true) 
                for i,v in ipairs(tableOrder) do  
                    outputChatBox("#c0c0c0* #abcdef"..i.."#c0c0c0. #abcdef"..v.name.." #c0c0c0- #abcdef"..v.data, player, 255,255,255,true) 
                    if i == amountOfTopsToDisplay then break end  
                end 
            else 
                outputChatBox("#c0c0c0* Syntax : #abcdef/top #c0c0c0[#abcdefwins #c0c0c0| #abcdefpoints#c0c0c0]", player, 255,255,255,true) 
            end 
  
    end) 

is this code right? :/

thanks for now :)

Link to comment
what is this?
for i,v do 

i think you want to get all accounts

for i,v in ipairs(getAccounts()) do 

when i try that it gives me bad argument in

                    subTable.name = getAccountData( v, "nick" ) 
                    subTable.data = getAccountData( v, vaule )  

Link to comment
local amountOfTopsToDisplay = 5 
addCommandHandler("top", 
    function(player, command, value) 
            if value == "wins" or value == "points" or value == "second" or value == "third" then 
                local tableOrder = {} 
                for i,v in ipairs(getAccounts()) do 
                    table.insert(tableOrder,{name = getAccountData(v, "nick"),data = getAccountData(v, vaule)}) 
                end 
                table.sort(tableOrder, function(a,b) return tonumber(a.data)>tonumber(b.data) end) 
                outputChatBox("#c0c0c0* Top 5 #abcdef"..value, player, 255,255,255,true) 
                for i,v in ipairs(tableOrder) do 
                    outputChatBox("#c0c0c0* #abcdef"..i.."#c0c0c0. #abcdef"..v.name.." #c0c0c0- #abcdef"..v.data, player, 255,255,255,true) 
                    if i == amountOfTopsToDisplay then break end 
                end 
            else 
                outputChatBox("#c0c0c0* Syntax : #abcdef/top #c0c0c0[#abcdefwins #c0c0c0| #abcdefpoints#c0c0c0]", player, 255,255,255,true) 
            end 
    end) 

Link to comment
  • Moderators

I think there's a spelling error in getAccountData() function ('vaule'). Also, the second argument of the getAccountData() function is a string ('The Key').

Edited by Guest
Link to comment
local amountOfTopsToDisplay = 5 
addCommandHandler("top", 
    function(player, command, value) 
            if value == "wins" or value == "points" or value == "second" or value == "third" then 
                local tableOrder = {} 
                for i,v in ipairs(getAccounts()) do 
                    table.insert(tableOrder,{name = getAccountData(v, "nick"),data = getAccountData(v, vaule)}) 
                end 
                table.sort(tableOrder, function(a,b) return tonumber(a.data)>tonumber(b.data) end) 
                outputChatBox("#c0c0c0* Top 5 #abcdef"..value, player, 255,255,255,true) 
                for i,v in ipairs(tableOrder) do 
                    outputChatBox("#c0c0c0* #abcdef"..i.."#c0c0c0. #abcdef"..v.name.." #c0c0c0- #abcdef"..v.data, player, 255,255,255,true) 
                    if i == amountOfTopsToDisplay then break end 
                end 
            else 
                outputChatBox("#c0c0c0* Syntax : #abcdef/top #c0c0c0[#abcdefwins #c0c0c0| #abcdefpoints#c0c0c0]", player, 255,255,255,true) 
            end 
    end) 

bad argument in

table.insert(tableOrder,{name = getAccountData(v, "nick"),data = getAccountData(v, vaule)}) 

Link to comment
Guest Guest4401
bad argument in
table.insert(tableOrder,{name = getAccountData(v, "nick"),data = getAccountData(v, vaule)}) 

Do you mind reading what I wrote once again?
There is actually a spelling mistake. You've misspelled value as vaule and yes, value is a string.
Link to comment

ah i didnt see your post :/ now i have got this problem..

local amountOfTopsToDisplay = 5 
addCommandHandler("top", 
    function(player, command, value) 
            if value == "wins" or value == "points" then 
                local tableOrder = {} 
                for i,v in ipairs(getAccounts()) do 
                    table.insert(tableOrder,{name = getAccountData(v, "nick"),data = getAccountData(v, value)}) 
                end 
                table.sort(tableOrder, function(a,b) return ( tonumber(a.data) or 0 ) > ( tonumber(b.data) or 0 ) end) 
                outputChatBox("#c0c0c0* Top 5 #abcdef"..value, player, 255,255,255,true) 
                for i,v in ipairs(tableOrder) do 
                    outputChatBox("#c0c0c0* #abcdef"..i.."#c0c0c0. #abcdef"..v.name.." #c0c0c0- #abcdef"..v.data, player, 255,255,255,true) 
                    if i == amountOfTopsToDisplay then break end 
                end 
            else 
                outputChatBox("#c0c0c0* Syntax : #abcdef/top #c0c0c0[#abcdefwins #c0c0c0| #abcdefpoints#c0c0c0]", player, 255,255,255,true) 
            end 
    end) 

992lp.png

on line of 12

Edited by Guest
Link to comment
ah i didnt see your post :/ now i have got this problem..
local amountOfTopsToDisplay = 5 
addCommandHandler("top", 
    function(player, command, value) 
            if value == "wins" or value == "points" then 
                local tableOrder = {} 
                for i,v in ipairs(getAccounts()) do 
                    table.insert(tableOrder,{nick = getAccountData(v, "nick"),data = getAccountData(v, value)}) 
                end 
                table.sort(tableOrder, function(a,b) return ( tonumber(a.data) or 0 ) > ( tonumber(b.data) or 0 ) end) 
                outputChatBox("#c0c0c0* Top 5 #abcdef"..value, player, 255,255,255,true) 
                for i,v in ipairs(tableOrder) do 
                    outputChatBox("#c0c0c0* #abcdef"..i.."#c0c0c0. #abcdef"..v.nick.." #c0c0c0- #abcdef"..v.data, player, 255,255,255,true) 
                    if i == amountOfTopsToDisplay then break end 
                end 
            else 
                outputChatBox("#c0c0c0* Syntax : #abcdef/top #c0c0c0[#abcdefwins #c0c0c0| #abcdefpoints#c0c0c0]", player, 255,255,255,true) 
            end 
    end) 

992lp.png

on line of 12

i can't find 'name' in your code, it's nick

check your code again.

Link to comment
local amountOfTopsToDisplay = 5 
addCommandHandler("top", 
    function(player, command, value) 
            if value == "wins" or value == "points" then 
                local tableOrder = {} 
                for i,v in ipairs(getAccounts()) do 
                    table.insert(tableOrder,{name = getAccountData(v, "nick"),data = getAccountData(v, value)}) 
                end 
                table.sort(tableOrder, function(a,b) return ( tonumber(a.data) or 0 ) > ( tonumber(b.data) or 0 ) end) 
                outputChatBox("#c0c0c0* Top 5 #abcdef"..value, player, 255,255,255,true) 
                for i,v in ipairs(tableOrder) do 
                    outputChatBox("#c0c0c0* #abcdef"..i.."#c0c0c0. #abcdef"..v.name.." #c0c0c0- #abcdef"..v.data, player, 255,255,255,true) 
                    if i == amountOfTopsToDisplay then break end 
                end 
            else 
                outputChatBox("#c0c0c0* Syntax : #abcdef/top #c0c0c0[#abcdefwins #c0c0c0| #abcdefpoints#c0c0c0]", player, 255,255,255,true) 
            end 
    end) 

992lp.png

on line of 12

Link to comment
local amountOfTopsToDisplay = 5 
  
addCommandHandler ( "top", 
    function ( player, command, value ) 
        if ( value == "wins" or value == "points" ) then 
            local tableOrder = { } 
            for i, v in ipairs ( getAccounts ( ) ) do 
                table.insert ( 
                    tableOrder, 
                    { 
                        name = getAccountData ( v, "nick" ), 
                        data = getAccountData ( v, value ) 
                    } 
                ) 
            end 
            table.sort ( 
                tableOrder, 
                function ( a, b ) 
                    return ( tonumber ( a.data ) or 0 ) > ( tonumber ( b.data ) or 0 ) 
                end 
            ) 
            outputChatBox ( "#c0c0c0* Top 5 #abcdef".. value, player, 255, 255, 255, true ) 
            for i = 1, amountOfTopsToDisplay do 
                outputChatBox ( "#c0c0c0* #abcdef".. i .."#c0c0c0. #abcdef".. tostring ( tableOrder [ i ].name ) .." #c0c0c0- #abcdef".. tostring ( tableOrder [ i ].data ), player, 255, 255, 255, true ) 
            end 
        else 
            outputChatBox ( "#c0c0c0* Syntax : #abcdef/top #c0c0c0[#abcdefwins #c0c0c0| #abcdefpoints#c0c0c0]", player, 255, 255, 255, true ) 
        end 
    end 
) 

Link to comment
local amountOfTopsToDisplay = 5 
  
addCommandHandler ( "top", 
    function ( player, command, value ) 
        if ( value == "wins" or value == "points" ) then 
            local tableOrder = { } 
            for i, v in ipairs ( getAccounts ( ) ) do 
                table.insert ( 
                    tableOrder, 
                    { 
                        name = getAccountData ( v, "nick" ), 
                        data = getAccountData ( v, value ) 
                    } 
                ) 
            end 
            table.sort ( 
                tableOrder, 
                function ( a, b ) 
                    return ( tonumber ( a.data ) or 0 ) > ( tonumber ( b.data ) or 0 ) 
                end 
            ) 
            outputChatBox ( "#c0c0c0* Top 5 #abcdef".. value, player, 255, 255, 255, true ) 
            for i = 1, amountOfTopsToDisplay do 
                outputChatBox ( "#c0c0c0* #abcdef".. i .."#c0c0c0. #abcdef".. tostring ( tableOrder [ i ].name ) .." #c0c0c0- #abcdef".. tostring ( tableOrder [ i ].data ), player, 255, 255, 255, true ) 
            end 
        else 
            outputChatBox ( "#c0c0c0* Syntax : #abcdef/top #c0c0c0[#abcdefwins #c0c0c0| #abcdefpoints#c0c0c0]", player, 255, 255, 255, true ) 
        end 
    end 
) 

thanks you :) okay its done but i have this now. if player is not in the server it shows "false" ...

99k3x.png

Link to comment
local amountOfTopsToDisplay = 5 
  
addCommandHandler ( "top", 
    function ( player, command, value ) 
        if ( value == "wins" or value == "points" ) then 
            local tableOrder = { } 
            for i, v in ipairs ( getAccounts ( ) ) do 
                table.insert ( 
                    tableOrder, 
                    { 
                        name = getAccountData ( v, "nick" ) or getAccountName ( v ), 
                        data = getAccountData ( v, value ) 
                    } 
                ) 
            end 
            table.sort ( 
                tableOrder, 
                function ( a, b ) 
                    return ( tonumber ( a.data ) or 0 ) > ( tonumber ( b.data ) or 0 ) 
                end 
            ) 
            outputChatBox ( "#c0c0c0* Top 5 #abcdef".. value, player, 255, 255, 255, true ) 
            for i = 1, amountOfTopsToDisplay do 
                outputChatBox ( "#c0c0c0* #abcdef".. i .."#c0c0c0. #abcdef".. tostring ( tableOrder [ i ].name ) .." #c0c0c0- #abcdef".. tostring ( tableOrder [ i ].data ), player, 255, 255, 255, true ) 
            end 
        else 
            outputChatBox ( "#c0c0c0* Syntax : #abcdef/top #c0c0c0[#abcdefwins #c0c0c0| #abcdefpoints#c0c0c0]", player, 255, 255, 255, true ) 
        end 
    end 
) 

You can do that, so if the account doesn't has 'nick' data, it'll set name as account name.

Link to comment
local amountOfTopsToDisplay = 5 
  
addCommandHandler ( "top", 
    function ( player, command, value ) 
        if ( value == "wins" or value == "points" ) then 
            local tableOrder = { } 
            for i, v in ipairs ( getAccounts ( ) ) do 
                table.insert ( 
                    tableOrder, 
                    { 
                        name = getAccountData ( v, "nick" ) or getAccountName ( v ), 
                        data = getAccountData ( v, value ) 
                    } 
                ) 
            end 
            table.sort ( 
                tableOrder, 
                function ( a, b ) 
                    return ( tonumber ( a.data ) or 0 ) > ( tonumber ( b.data ) or 0 ) 
                end 
            ) 
            outputChatBox ( "#c0c0c0* Top 5 #abcdef".. value, player, 255, 255, 255, true ) 
            for i = 1, amountOfTopsToDisplay do 
                outputChatBox ( "#c0c0c0* #abcdef".. i .."#c0c0c0. #abcdef".. tostring ( tableOrder [ i ].name ) .." #c0c0c0- #abcdef".. tostring ( tableOrder [ i ].data ), player, 255, 255, 255, true ) 
            end 
        else 
            outputChatBox ( "#c0c0c0* Syntax : #abcdef/top #c0c0c0[#abcdefwins #c0c0c0| #abcdefpoints#c0c0c0]", player, 255, 255, 255, true ) 
        end 
    end 
) 

You can do that, so if the account doesn't has 'nick' data, it'll set name as account name.

thank you so much :)

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