Jump to content

Short question


GTX

Recommended Posts

-- server side:

addCommandHandler("getplayer", 
function (player, cmd, accountName) 
    local account = getAccount(accountName) 
    if (account and not isGuestAccount(account)) then 
        local thePlayer = getAccountPlayer(account) 
        if (thePlayer) then 
               outputChatBox("The owner of the account: ".. tostring(accountName) .." is: ".. tostring(getPlayerName(thePlayer)),player,0,255,0) 
        end 
    end 
end) 

This should work like this: /getplayer

Link to comment
  
function tables() 
    outputChatBox("Top 3 points:", getRootElement(), 255,255,255) 
    for index, data in ipairs(sortAccounts()) do 
        outputChatBox("#"..tostring(index)..": ".. tostring(data.account) .." - ".. tostring(data.points), getRootElement(), 255, 255, 255) 
        if index == 3 then 
            break 
        end 
    end 
end 
addCommandHandler("top", tables) 
  
function sortAccounts() 
    local rowdata = {} 
    for index, account in pairs(getAccounts()) do 
        rowdata[index] = { 
            account = getAccountPlayer(account), 
            points = getAccountData(account,"Points"), 
        } 
    end 
    local comparator = function (a, b) 
        return (tonumber(a.points) or 0) > (tonumber(b.points) or 0) 
    end 
    table.sort(rowdata, comparator) 
    return rowdata 
end 
  

You gave me this code, remember? Well, I tryied to make a fuse but I failed. This returns a userdata value, how can I fix it?

Link to comment

You want to get only the accounts that are in use? if so, try this:

function tables() 
    outputChatBox("Top 3 points:", getRootElement(), 255,255,255) 
    for index, data in ipairs(sortAccounts()) do 
        outputChatBox("#"..tostring(index)..": ".. tostring(data.name) .." - ".. tostring(data.points), getRootElement(), 255, 255, 255) 
        if index == 3 then 
            break 
        end 
    end 
end 
addCommandHandler("top", tables) 
  
function sortAccounts() 
    local rowdata = {} 
    for index, account in pairs(getAccounts()) do 
        if (not isGuestAccount(account)) then 
            rowdata[index] = { 
                name = getAccountPlayer(account), 
                points = getAccountData(account,"Points"), 
            } 
        end 
    end 
    local comparator = function (a, b) 
        return (tonumber(a.points) or 0) > (tonumber(b.points) or 0) 
    end 
    table.sort(rowdata, comparator) 
    return rowdata 
end 

Link to comment

This returns userdata also. But anyways, I want to edit this code:

function tables() 
    outputChatBox("Top 3 points:", getRootElement(), 255,255,255) 
    for index, data in ipairs(sortAccounts()) do 
        outputChatBox("#"..tostring(index)..": ".. tostring(data.account) .." - ".. tostring(data.points), getRootElement(), 255, 255, 255) 
        if index == 3 then 
            break 
        end 
    end 
end 
addCommandHandler("top", tables) 
  
function sortAccounts() 
    local rowdata = {} 
    for index, account in pairs(getAccounts()) do 
        rowdata[index] = { 
            account = getAccountPlayer(account), 
            points = getAccountData(account,"Points"), 
        } 
    end 
    local comparator = function (a, b) 
        return (tonumber(a.points) or 0) > (tonumber(b.points) or 0) 
    end 
    table.sort(rowdata, comparator) 
    return rowdata 
end 
  

This must get all account's "owners".

Edited by Guest
Link to comment
Hello, I'm wondering how to get player name from account. I would be grateful if someone will help me :)

i made this on my server to can get the player name from accoun't for a top list you just save on account data the player name on join and on nick change like

setAccountData(account,"Name",getPlayerName(player))  --and done  

Link to comment

Sorry for double-posting but I've got a weird problem!

When I change nick, for example: I change nick to "xG|GTX" and then I see top: it returns the previous nick name and not "xG|GTX"!

  
function save() 
  
local account = getPlayerAccount(source) 
setAccountData(account,"Name",getPlayerName(source)) 
  
end 
addEventHandler("onPlayerChangeNick", getRootElement(), save) 
addEventHandler("onPlayerLogin", getRootElement(), save) 
addEventHandler("onResourceStart", getRootElement(), save) 
  

Link to comment

Ok, I found out my error, I never get the player name, just the player himself (userdata).

function tables() 
    outputChatBox("Top 3 points:", getRootElement(), 255,255,255) 
    for index, data in ipairs(sortAccounts()) do 
        outputChatBox("#"..tostring(index)..": ".. tostring(data.name) .." - ".. tostring(data.points), getRootElement(), 255, 255, 255) 
        if (index == 3) then 
            break 
        end 
    end 
end 
addCommandHandler("top", tables) 
  
function sortAccounts() 
    local rowdata = {} 
    for index, account in pairs(getAccounts()) do 
        if (not isGuestAccount(account) and getAccountPlayer(account)) then 
            table.insert(rowdata, {name = getPlayerName(getAccountPlayer(account)), points = getAccountData(account,"Points")}) 
        end 
    end 
    local comparator = function (a, b) 
        return (tonumber(a.points) or 0) > (tonumber(b.points) or 0) 
    end 
    table.sort(rowdata, comparator) 
    return rowdata 
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...