Jump to content

getAccountData for all accounts


crismar

Recommended Posts

Ok, so I want to make a /tops for my server. This command will basically loop through all accounts on the server, and have 2 variables: highest value and owner of the account.

To be more precise, something like:

  
for i, v in pairs(getAccounts()) 
          local current = getAccountData(getAccount(v), "ucpMinutesPlayed") 
          if tonumber(current) >= highest or 0 then 
          local highest = getAccountData(getAccount(v), "ucpMinutesPlayed") 
          end 
end 
  

The problem I have though is that when I try to use the above code it says 'current' and 'highest' are nil (both variables are nil). Could you please tell me what am I doing wrong ? In the end, I want to end up with the highest value of ucpMinutesPlayed among all the accounts. Any ideas ?

Link to comment

I believe it returns a indexed table, thus you'll need to change pairs to ipairs first of all.

Second, why are you doing getAccount after getting all accounts? It returns the account element, not their name.

local current = getAccountData(v, "ucpMinutesPlayed") 

Link to comment

You forgot to put "do" after the for loop, and make sure you define the "highest" variable before you run the loop.

local highest = 0 
for i, v in pairs(getAccounts()) do 
    local current = getAccountData(getAccount(v), "ucpMinutesPlayed") or 0 
    if tonumber( current ) or 0 > highest then 
        highest = getAccountData(getAccount(v), "ucpMinutesPlayed") 
    end 
end 
  

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