GTX Posted December 26, 2011 Posted December 26, 2011 Hello, I'm wondering how to get player name from account. I would be grateful if someone will help me Do you require a paid scripter? Contact me! (Unavailable) Currently I am experienced in Lua, PHP, HTML, CSS, SQL and JS. Developer and owner of https://projectbea.st - Project Beast
Castillo Posted December 26, 2011 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 San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
GTX Posted December 26, 2011 Author 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? Do you require a paid scripter? Contact me! (Unavailable) Currently I am experienced in Lua, PHP, HTML, CSS, SQL and JS. Developer and owner of https://projectbea.st - Project Beast
Castillo Posted December 26, 2011 Posted December 26, 2011 What returns a userdata? San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
GTX Posted December 26, 2011 Author Posted December 26, 2011 I think this: account = getAccountPlayer(account), line 17 Do you require a paid scripter? Contact me! (Unavailable) Currently I am experienced in Lua, PHP, HTML, CSS, SQL and JS. Developer and owner of https://projectbea.st - Project Beast
Castillo Posted December 26, 2011 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 San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
GTX Posted December 27, 2011 Author 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 Do you require a paid scripter? Contact me! (Unavailable) Currently I am experienced in Lua, PHP, HTML, CSS, SQL and JS. Developer and owner of https://projectbea.st - Project Beast
Jaysds1 Posted December 27, 2011 Posted December 27, 2011 Do you want to get everyone's account on your server? My in-game name: Jaysds1 Retired CMG Scripter World Of Tanks GameMode (Open-Source): https://github.com/Jaysds1/mtasa-wot-gamemode Online GUI-Editor (WIP): https://forum.mtasa.com/topic/47678-online-gui-editor/
GTX Posted December 27, 2011 Author Posted December 27, 2011 Well, not exactly; I want to get the "owner" of account Do you require a paid scripter? Contact me! (Unavailable) Currently I am experienced in Lua, PHP, HTML, CSS, SQL and JS. Developer and owner of https://projectbea.st - Project Beast
bandi94 Posted December 27, 2011 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 Ingame Name : |DGT|Puma DGT Clan Server 24/7 Owner/Scripter MultiGameMode in progress :
GTX Posted December 27, 2011 Author Posted December 27, 2011 Thank you, I was thinking about this too. Thanks to everyone who helped me. Do you require a paid scripter? Contact me! (Unavailable) Currently I am experienced in Lua, PHP, HTML, CSS, SQL and JS. Developer and owner of https://projectbea.st - Project Beast
GTX Posted December 27, 2011 Author 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) Do you require a paid scripter? Contact me! (Unavailable) Currently I am experienced in Lua, PHP, HTML, CSS, SQL and JS. Developer and owner of https://projectbea.st - Project Beast
GanJaRuleZ Posted December 27, 2011 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 My Projects! No one.
GTX Posted December 27, 2011 Author Posted December 27, 2011 Oh, yes, I didn't even think about this. Do you require a paid scripter? Contact me! (Unavailable) Currently I am experienced in Lua, PHP, HTML, CSS, SQL and JS. Developer and owner of https://projectbea.st - Project Beast
Castillo Posted December 27, 2011 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 San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
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