GTX Posted December 26, 2011 Share Posted December 26, 2011 Hello, I'm wondering how to get player name from account. I would be grateful if someone will help me Link to comment
Castillo Posted December 26, 2011 Share Posted December 26, 2011 -- 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
GTX Posted December 26, 2011 Author Share Posted December 26, 2011 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
Castillo Posted December 26, 2011 Share Posted December 26, 2011 What returns a userdata? Link to comment
GTX Posted December 26, 2011 Author Share Posted December 26, 2011 I think this: account = getAccountPlayer(account), line 17 Link to comment
Castillo Posted December 26, 2011 Share Posted December 26, 2011 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
GTX Posted December 27, 2011 Author Share Posted December 27, 2011 (edited) 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 December 27, 2011 by Guest Link to comment
Jaysds1 Posted December 27, 2011 Share Posted December 27, 2011 Do you want to get everyone's account on your server? Link to comment
GTX Posted December 27, 2011 Author Share Posted December 27, 2011 Well, not exactly; I want to get the "owner" of account Link to comment
bandi94 Posted December 27, 2011 Share Posted December 27, 2011 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
GTX Posted December 27, 2011 Author Share Posted December 27, 2011 Thank you, I was thinking about this too. Thanks to everyone who helped me. Link to comment
GTX Posted December 27, 2011 Author Share Posted December 27, 2011 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
GanJaRuleZ Posted December 27, 2011 Share Posted December 27, 2011 As far i see , you save the data on the account . You can have 100 nicknames and 1 account , but not 100 accounts and 1 nickname , so Try to /logout , /login Link to comment
GTX Posted December 27, 2011 Author Share Posted December 27, 2011 Oh, yes, I didn't even think about this. Link to comment
Castillo Posted December 27, 2011 Share Posted December 27, 2011 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
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