GTX Posted February 11, 2012 Posted February 11, 2012 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
Evil-Cod3r Posted February 11, 2012 Posted February 11, 2012 https://wiki.multitheftauto.com/wiki/TriggerClientEvent
Kenix Posted February 11, 2012 Posted February 11, 2012 (edited) 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 February 11, 2012 by Guest
GTX Posted February 11, 2012 Author Posted February 11, 2012 TryServer 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
GTX Posted February 11, 2012 Author Posted February 11, 2012 (edited) Try again i update code.Use /debugscript 3. It still doesn't show, nothing in debug EDIT: It shows only "#1:" and not account name. No errors. Edited February 11, 2012 by Guest
Kenix Posted February 11, 2012 Posted February 11, 2012 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.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now