Jump to content

get Max value


RekZ

Recommended Posts

Posted

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 ) 
  

Posted
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

Posted

Apart from the 0 you can also use the 1st value, this is how I usually go to work.

For example:

Array => [8, 4, 2, 3, 7, 9]

greatest = array[0]

array > greatest ? => greatest = array

I hope you understand my 'weird' explanation.

Posted

The first value is either higher than the initial (0) or is 0, so having it initialised to 0 is the same as using your code, but yea, yours would work too.

Posted
The first value is either higher than the initial (0) or is 0, so having it initialised to 0 is the same as using your code, but yea, yours would work too.

I know but doesn't my way skip 1 step :) overwriting the 0, but yeah it's not that much of a difference

  • 2 weeks later...
Posted

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 
  

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