RekZ Posted May 13, 2016 Posted May 13, 2016 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 )
pa3ck Posted May 13, 2016 Posted May 13, 2016 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
ViRuZGamiing Posted May 13, 2016 Posted May 13, 2016 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.
pa3ck Posted May 13, 2016 Posted May 13, 2016 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.
ViRuZGamiing Posted May 14, 2016 Posted May 14, 2016 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
rE5vK8bu Posted May 28, 2016 Posted May 28, 2016 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
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