Memory Posted December 13, 2012 Posted December 13, 2012 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
Castillo Posted December 13, 2012 Posted December 13, 2012 If you don't explain your problem, we can't help you. San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
Jaysds1 Posted December 13, 2012 Posted December 13, 2012 It seems like he wants a top ten playlist, which gets every account on his server and sort them out with the highest points. His problem is on line 22 in the server-side script 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/
Cadu12 Posted December 13, 2012 Posted December 13, 2012 Jaysds1, that's not problem, it will stop looping. On: Memory, what is your problem/error? We can't fix for you. Ingame nick: Cadu12
TAPL Posted December 13, 2012 Posted December 13, 2012 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 )
Jaysds1 Posted December 13, 2012 Posted December 13, 2012 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/
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