Jump to content

Client Account name


Recommended Posts

Posted (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 by JAVAAA
Posted (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 by JAVAAA
Posted
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. 

Posted

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

Posted

Alright, thanks! Another question if you don't mind to answer it, how can I use "isObjectInACLGroup" function in client side?

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

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

Posted

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.

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