Jump to content

Client Account name


Recommended Posts

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 by JAVAAA
Link to comment
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 by JAVAAA
Link to comment

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
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
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

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...