S3M Posted May 25, 2012 Posted May 25, 2012 Hi all. Is it possible to make a rank bankmoney top 5 that views which player have the most bankmoney on screen?. See image. Which way on wiki would i be looking? or are there is already a usable resource for this kind of scoreboard on screen? Thx.
Kenix Posted May 25, 2012 Posted May 25, 2012 getPlayerMoney dxDrawText + event https://wiki.multitheftauto.com/wiki/OnClientRender
S3M Posted May 25, 2012 Author Posted May 25, 2012 He said bank money, maybe 50p's bank system. Sorry yes i mean with 50p bank system.
Kenix Posted May 25, 2012 Posted May 25, 2012 (edited) Try this function FindReachPlayers( nPlayersCount ) if type( nPlayersCount ) == 'number' then local nStart = 0 local pAddPlayer local nIndexRemove = 0 local aReturnPlayers = { } local aReachPlayers = { } for _, pPlayer in pairs( getElementsByType 'player' ) do table.insert( aReachPlayers, { [ pPlayer ] = getPlayerMoney( pPlayer ) } ) end for n = 1, nPlayersCount do for nIndex, a in ipairs( aReachPlayers ) do for pPlayer, nMoney in pairs( a ) do if nStart <= nMoney then nStart = nMoney nIndexRemove = nIndex pAddPlayer = pPlayer end end end if not aReachPlayers[ nIndexRemove ] then return aReturnPlayers end table.insert( aReturnPlayers, { [ pAddPlayer ] = nStart } ) table.remove( aReachPlayers, nIndexRemove ) nIndexRemove = 0 nStart = 0 end return aReturnPlayers end return false end Updated again. Example of use: for _, a in ipairs( FindReachPlayers( 3 ) ) do for pPlayer, nMoney in pairs( a ) do outputChatBox( 'Player = ' .. getPlayerName( pPlayer ) .. ' , Money = ' .. nMoney ) end end Edited May 25, 2012 by Guest
Flaker Posted May 25, 2012 Posted May 25, 2012 Or try this, if u want export bank balance from 50'p bank system: function FindReachPlayers( nPlayersCount ) if type( nPlayersCount ) == 'number' then local nStart = 0 local nIndexRemove = 0 local aReturnPlayers = { } local aReachPlayers = { } for _, pPlayer in pairs( getElementsByType 'player' ) do local accountName = getAccountName ( getPlayerAccount ( pPlayer ) ) local bank_money = tonumber( exports.bank:getBankAccountBalance(accountName) ) -- exports.RESOURCE_NAME:FUNCTION( ARGUMENTS ) table.insert( aReachPlayers, { [ pPlayer ] = bank_money } ) end for n = 1, nPlayersCount do for nIndex, a in ipairs( aReachPlayers ) do for pPlayer, nMoney in pairs( a ) do if nStart < nMoney then table.insert( aReturnPlayers, { [ pPlayer ] = nMoney } ) nStart = nMoney nIndexRemove = #aReturnPlayers end end end table.remove( aReachPlayers, nIndexRemove ) nIndexRemove = 0 nStart = 0 end return aReturnPlayers end return false end
Alpha Posted May 25, 2012 Posted May 25, 2012 (edited) table.sort Is better to use it in such situation. http://lua-users.org/wiki/TableLibraryTutorial Edited May 25, 2012 by Guest
Kenix Posted May 25, 2012 Posted May 25, 2012 table.sort Is better to use in such situation. http://lua-users.org/wiki/TableLibraryTutorial It's not solution in this situation.
Alpha Posted May 25, 2012 Posted May 25, 2012 It is actually, you can use it to sort/order the table containing the bank money descendingly.
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