Jump to content

I need some help.


GTX

Recommended Posts

Hello, I have this:

function tables() 
    outputChatBox("Top 3 points:", getRootElement(), 255,255,255) 
    for index, data in ipairs(sortAccounts()) do 
        outputChatBox("#"..tostring(index)..": ".. tostring(data.account) .." - ".. tostring(data.points), getRootElement(), 255, 255, 255) 
        if index == 3 then 
            break 
        end 
    end 
end 
addCommandHandler("top", tables) 
  
function sortAccounts() 
    local rowdata = {} 
    for index, account in pairs(getAccounts()) do 
        rowdata[index] = { 
            account = getAccountName(account), 
            points = getAccountData(account,"Points"), 
        } 
    end 
    local comparator = function (a, b) 
        return (tonumber(a.points) or 0) > (tonumber(b.points) or 0) 
    end 
    table.sort(rowdata, comparator) 
    return rowdata 
end 

But now I need to get that into client-side like:

for index, data in ipairs(getElementsByType("player")) do 
lbl_f_block10[i] = guiCreateLabel(13,53 * i,26,276,"#"..tostring(index)..": "..tostring(data.account).." - "..tostring(data.points),false,tab_leaderboard) 
guiSetFont(lbl_f_block10[i],"clear-normal") 
if index == 10 then 
    break 
end 
end 

But I have no idea.

Thanks in advance

Link to comment

Try

Server

function sortAccounts( ) 
    local rowdata = { } 
    for _, account in pairs( getAccounts( ) ) do 
        rowdata[ #rowdata + 1 ] = { 
            account = getAccountName( account ), 
            points = getAccountData( account,"Points" ) 
        } 
    end 
    table.sort(  
        rowdata,  
        function ( a, b ) 
            return ( tonumber( a.points ) or 0 ) > ( tonumber( b.points ) or 0 )  
        end 
    )    
    return rowdata 
end 
  
function tables( ) 
    outputChatBox( "Top 3 points:", root, 255,255,255 ) 
    for index, data in ipairs( sortAccounts( ) ) do 
        outputChatBox("#"..tostring( index )..": ".. tostring( data.account ) .." - ".. tostring( data.points ), root, 255, 255, 255 ) 
        if index == 3 then 
            break 
        end 
    end 
    triggerClientEvent( 'onAccountsSend',root,sortAccounts( ) ) 
end 
addCommandHandler( "top", tables ) 

Client

  
addEvent( 'onAccountsSend',true ) 
  
addEventHandler( 'onAccountsSend',root, 
    function( t ) 
        for index, data in ipairs( t ) do 
            local label = guiCreateLabel(13,53 * index,26,276,"#"..tostring( index )..": "..tostring( data.account ).."\ 
            - "..tostring( data.points ),false,tab_leaderboard ) 
            guiSetFont( label,"clear-normal" ) 
            if index == 10 then 
                break 
            end 
        end 
    end 
) 

Updated again.

Edited by Guest
Link to comment
Try

Server

function sortAccounts( ) 
    local rowdata = { } 
    for index, account in pairs( getAccounts( ) ) do 
        rowdata[ index ] = { 
            account = getAccountName( account ), 
            points = getAccountData( account,"Points" ) 
        } 
    end 
    table.sort(  
        rowdata,  
        function ( a, b ) 
            return ( tonumber( a.points ) or 0 ) > ( tonumber( b.points ) or 0 )  
        end 
    )    
    return rowdata 
end 
  
function tables( ) 
    outputChatBox( "Top 3 points:", root, 255,255,255 ) 
    for index, data in ipairs( sortAccounts( ) ) do 
        outputChatBox("#"..tostring( index )..": ".. tostring( data.account ) .." - ".. tostring( data.points ), root, 255, 255, 255 ) 
        if index == 3 then 
            break 
        end 
    end 
    triggerClientEvent( 'onAccountsSend',root,sortAccounts( ) ) 
end 
addCommandHandler( "top", tables ) 

Client

  
addEvent( 'onAccountsSend',true ) 
  
addEventHandler( 'onAccountsSend',root, 
    function( t ) 
        for index, data in pairs( t ) do 
            local label = guiCreateLabel(13,53 * index,26,276,"#"..tostring( index )..": "..tostring( data.account ).."\ 
            - "..tostring( data.points ),false,tab_leaderboard ) 
            guiSetFont( label,"clear-normal" ) 
            if index == 10 then 
                break 
            end 
        end 
    end 
) 

Updated again.

It doesn't show label

Link to comment

Client

addEvent( 'onAccountsSend',true ) 
  
local labels = { } 
  
addEventHandler( 'onAccountsSend',root, 
    function( t ) 
        for index, data in ipairs( t ) do 
            labels[ index ] = guiCreateLabel(13,53 * index,526,276,"#"..tostring( index )..": "..tostring( data.account ).."- "..tostring( data.points ),false,tab_leaderboard ) 
            guiSetFont( labels[ index ],"clear-normal" ) 
            if index == 10 then 
                break 
            end 
        end 
    end 
) 

Server

function sortAccounts( ) 
    local rowdata = { } 
    for _, account in pairs( getAccounts( ) ) do 
        rowdata[ #rowdata + 1 ] = { 
            account = getAccountName( account ), 
            points = getAccountData( account,"Points" ) 
        } 
    end 
    table.sort(  
        rowdata,  
        function ( a, b ) 
            return ( tonumber( a.points ) or 0 ) > ( tonumber( b.points ) or 0 )  
        end 
    )    
    return rowdata 
end 
  
function tables( ) 
    outputChatBox( "Top 3 points:", root, 255,255,255 ) 
    for index, data in ipairs( sortAccounts( ) ) do 
        outputChatBox("#"..tostring( index )..": ".. tostring( data.account ) .." - ".. tostring( data.points ), root, 255, 255, 255 ) 
        if index == 3 then 
            break 
        end 
    end 
    triggerClientEvent( 'onAccountsSend',root,sortAccounts( ) ) 
end 
addCommandHandler( "top", tables ) 

Tested.

Updated.

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