JAVAAA Posted May 6, 2017 Share Posted May 6, 2017 (edited) Hey, how to get player's account name in client script? I used triggerServerEvent but doesn't work. Also, I want it returns as a string so I could use it in different ways, thanks. Edited May 6, 2017 by JAVAAA Link to comment
Ahmed Araby Posted May 6, 2017 Share Posted May 6, 2017 (edited) addEventHandler("onPlayerLogin",root, function() AccountName = getAccountName(getPlayerAccount(source)) setElementData(source,"AccountName",tostring(AccountName)) end) -------------------------- -- client side AccountName = getElementData(localPlayer,"AccountName") that is an easy way when player log in put data on player value is Account name Edited May 6, 2017 by Ahmed Araby Link to comment
JAVAAA Posted May 6, 2017 Author Share Posted May 6, 2017 (edited) 21 minutes ago, Ahmed Araby said: addEventHandler("onPlayerLogin",root, function() AccountName = getAccountName(getPlayerAccount(source)) setElementData(source,"AccountName",tostring(AccountName)) end) -------------------------- -- client side AccountName = getElementData(localPlayer,"AccountName") that is an easy way when player log in put data on player value is Account name Nvm, worked. Can't I use event handler "onResourceStart"? Since event handler "onPlayerJoin" isn't suitable for me Edited May 6, 2017 by JAVAAA Link to comment
^iiEcoo'x_) Posted May 6, 2017 Share Posted May 6, 2017 addEventHandler ( 'onPlayerLogin' , root , function ( ) triggerClientEvent ( source , 'Account' , source , getAccountName ( getPlayerAccount ( source ) ) ) end ) addEvent ( 'Account' , true ) addEventHandler ( 'Account' , root , function ( aAccName_ ) guiSetText ( aLabel , tostring ( aAccName_ ) ) -- ex end ) Link to comment
pa3ck Posted May 6, 2017 Share Posted May 6, 2017 17 minutes ago, JAVAAA said: Nvm, worked. Can't I use event handler "onResourceStart"? Since event handler "onPlayerJoin" isn't suitable for me No, for this purpose, onResourceStart wouldn't work. Link to comment
Ahmed Araby Posted May 6, 2017 Share Posted May 6, 2017 addEventHandler("onResourceStart",root, function( res ) if res == getThisResource() then for i,v in ipairs(getElementsByType ( "player" )) do AccountName = getAccountName(getPlayerAccount(v)) setElementData(v,"AccountName",tostring(AccountName)) end end end ) but when any player enter server and login he won't take data AccountName with the value of his account name .. Link to comment
JAVAAA Posted May 6, 2017 Author Share Posted May 6, 2017 Alright, thanks! Another question if you don't mind to answer it, how can I use "isObjectInACLGroup" function in client side? Link to comment
Ahmed Araby Posted May 6, 2017 Share Posted May 6, 2017 1 hour ago, JAVAAA said: Alright, thanks! Another question if you don't mind to answer it, how can I use "isObjectInACLGroup" function in client side? addEventHandler("onPlayerLogin",root, function() local accName = getAccountName ( getPlayerAccount ( source ) ) if isObjectInACLGroup ("user."..accName, aclGetGroup ( "Admin" ) ) then setElementData(source,"Admin",true) end end ) --- client if getElementData(localPlayer,"Admin") then the same previous ex. not at all .. Link to comment
1B0Y Posted May 7, 2017 Share Posted May 7, 2017 addEventHandler("onPlayerLogin",root, function() local account = getPlayerAccount(source) setElementData(source,"account",getAccountName(account),true) --Syncs to the client end end) Setting the 4th argument to true will sync the element data from the server to client. Link to comment
DNL291 Posted May 7, 2017 Share Posted May 7, 2017 Elements-data are synchronized by default. Link to comment
3aGl3 Posted May 7, 2017 Share Posted May 7, 2017 I think the version posted above with the triggerClientevent is a much better solution. No one except the server and the client himself should really know the account name. Link to comment
JAVAAA Posted May 7, 2017 Author Share Posted May 7, 2017 Thanks everyone who answered! I appreciate it. 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