Jump to content

Top ten


Memory

Recommended Posts

Posted

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 ) 

Ingame name: [sV]Kostya

Name in scripts: Kostya

Posted

If you don't explain your problem, we can't help you.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

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 ) 

CiTLh.png
Posted

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) 

My in-game name: Jaysds1

Retired CMG Scripter

World Of Tanks GameMode (Open-Source): https://github.com/Jaysds1/mtasa-wot-gamemode

Online GUI-Editor (WIP): https://forum.mtasa.com/topic/47678-online-gui-editor/

 

sE5Qm.png

TiV3C.png

img.php?id=0&text=Lua%20Scripter

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