Jump to content

Top ten


Memory

Recommended Posts

Hello, please, help me create Top ten panel.

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 10 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 == 10 then 
            break 
        end 
    end 
    triggerClientEvent( 'onAccountsSend',root,sortAccounts( ) ) 
end 
addEvent("onSortTopTen", true) 
addEventHandler("onSortTopTen", root, tables) 
addCommandHandler( "top", tables ) 
  

Client

function clientsideResourceStart () 
        local playerList = guiCreateGridList ( 0.80, 0.10, 0.15, 0.60, true ) 
        local column = guiGridListAddColumn( playerList, "Player", 0.6 ) 
        local points = guiGridListAddColumn( playerList, "Points", 0.3 ) 
        if ( column ) then 
                        triggerServerEvent("onSortTopTen", getLocalPlayer()) 
                        local row = guiGridListAddRow ( playerList ) 
                        guiGridListSetItemText ( playerList, row, column, data.account, false, false ) 
         end 
         if ( points ) then 
                        triggerServerEvent("onSortTopTen", getLocalPlayer()) 
                        local row = guiGridListAddRow ( playerList ) 
                        guiGridListSetItemText ( playerList, row, points, data.points, false, false ) 
        end 
end 
addEventHandler ( "onClientResourceStart", getResourceRootElement(), clientsideResourceStart ) 

Link to comment

You haven't added the event 'onAccountsSend' in client side.

data.account and data.points not defined here:

guiGridListSetItemText ( playerList, row, column, data.account, false, false ) 

guiGridListSetItemText ( playerList, row, points, data.points, false, false ) 

Link to comment

try this,

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 10 points:", root, 255,255,255 ) 
    local topPoints = sortAccounts() 
    for index, data in ipairs(topPoints)do 
        outputChatBox(tostring( index )..": ".. tostring( data.account ) .." - ".. tostring( data.points ), root, 255, 255, 255 ) 
        triggerClientEvent( 'onAccountsSend',root,index,data.account,data.points) 
        if index == 10 then break end 
    end 
end 
addEvent("onSortTopTen", true) 
addEventHandler("onSortTopTen", root, tables) 
addCommandHandler( "top", tables ) 

Client:

addEventHandler ( "onClientResourceStart",resourceRoot,function() 
    local playerList = guiCreateGridList ( 0.80, 0.10, 0.15, 0.60, true ) 
    guiGridListAddColumn( playerList, "Player", 0.6 ) 
    guiGridListAddColumn( playerList, "Points", 0.3 ) 
     
    triggerServerEvent("onSortTopTen",localPlayer) 
end) 
  
addEvent("onAccountsSend",true) 
addEventHandler("onAccountsSend",root,function(topNum,name,points) 
    local row = guiGridListAddRow(playerList) 
    guiGridListSetItemText(playerList, row, 1, data.account, false, false ) 
    guiGridListSetItemText(playerList, row, 2, data.points, false, true ) 
end) 

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