fairyoggy Posted August 18, 2019 Share Posted August 18, 2019 How to create a command that will show getElementData(target, "name") by login? I mean if you type /find Alex Find a player with a login "Alex" and get he's elementData("name") and will appear message with he's nick But the player is not on the server UPDATE: I found this but how to use it on offline players? https://wiki.multitheftauto.com/wiki/GetPlayerFromAccountName Link to comment
Tommy. Posted August 18, 2019 Share Posted August 18, 2019 (edited) You can not do that, elementData is temporary, what you can that about is using setAccountData (when the player leaves save elementData) and getAccountData (get the data saved by the account) Try this: -- load elementData function load(_, account) local name = getAccountData(account, "name") or "N/A" setElementData(source, "name", name) end addEventHandler("onPlayerLogin", getRootElement(), load) -- save elementData function save() local name = getElementData(source, "name") or "N/A" setAccountData(getPlayerAccount(source), "name", name) end addEventHandler("onPlayerQuit", getRootElement(), save) -- find elementAccount function find (source, cmd, playerAccount) if cmd and playerAccount then if getAccount(playerAccount) then local gName = getAccountData(getAccount(playerAccount), "name") outputChatBox("Name of "..playerAccount.." is #FFFFFF"..""..gName, source, 152, 95, 161, true) end end end addCommandHandler("find", find) EDIT: I do not tested! Edited August 18, 2019 by Tommy. 1 Link to comment
HassoN Posted August 18, 2019 Share Posted August 18, 2019 Use setAccountData -- save player's nickname to his account Use the function above on login, on nick name change and on quit so it stays up to date. Then you may just call it by getAccountData to get the player's name from his account name. 1 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