Jump to content

get Max value


RekZ

Recommended Posts

how i can get the best value of all accounts Data in the server using these ?

for _, cuentas in ipairs (getAccounts()) do 
 local accountData = getAccountData ( cuentas , "Value" ) 
 DataValue = tonumber(accountData) 
 end 
  
outputChatBox ( "The best Value is "..DataValue ) 
  

Link to comment
local greatest = 0 
  
for _, cuentas in ipairs (getAccounts()) do 
    local accountData = getAccountData ( cuentas , "Value" ) 
    if tonumber(accountData) and tonumber(accountData) > greatest then 
        greatest = tonumber(accountData) 
    end 
end 
  
outputChatBox ( "The best Value is "..greatest ) 
  

Something like that

Link to comment
  • 2 weeks later...

Perhaps this should work.

  
local accountValue = {} 
  
for _,cuentas in ipairs(getAccounts())do 
    table.insert(accountValue,getAccountData(cuentas,"Value")) 
end 
  
table.sort(accountValue,function(a,b) 
    return b < a 
end) 
  
outputChatBox("The best Value is "..accountValue[1]) 
  

My explanation:

  
--table: 
t = {3,2,5,1,4} 
  
--returns from highest to lowest: 
table.sort(t,function(a,b) 
    return b < a 
end) 
  
--results: 
5,4,3,2,1 
  

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