Jump to content

Check if player is admin on client side


Dzsozi (h03)

Recommended Posts

Hello community! I have a question. How can I check if the player is in the ACL admin group on client side? I've made an export function for this, but it only works on server side. How could I make this work on client side as well?

function isPlayerAdmin(player) 
    if isObjectInACLGroup ( "user." .. getAccountName ( getPlayerAccount ( player ) ), aclGetGroup ( "Admin" ) ) then 
        return true 
    end 
    return false 
end 

Link to comment

you can use this:

function isPlayerAdmin(player) 
    if(getElementData(player,"Admin")) then 
        return true 
    end 
    return false 
end 
  
addEventHandler("onPlayerLogin",root, 
function() 
if isObjectInACLGroup ( "user." .. getAccountName ( getPlayerAccount ( source ) ), aclGetGroup ( "Admin" ))then 
setElementData(source,"Admin",true) 
end 
end) 

Link to comment

Ohh, forgot this one. I have one more question: How can I get an element data on client side which was set on server side? I use 50p's bank system and I want to make a custom HUD which is draws the current bank balance, but the "bank.balance" elementdata was set on server side. How could I get this element data on client side?

Link to comment

if you want use trigger:

server

local Admins = {} 
  
function isPlayerAdmin(player) 
    if(Admins[player]) then 
        return true 
    end 
    return false 
end 
  
addEventHandler("onPlayerLogin",root, 
function() 
if isObjectInACLGroup ( "user." .. getAccountName ( getPlayerAccount ( source ) ), aclGetGroup ( "Admin" ))then 
if not(Admins[source])then 
 Admins[source]= source 
 triggerClientEvent("updateAdmins",source,Admins) 
end 
end 
end) 
  
addEventHandler("onPlayerQuit",root, 
function() 
if(Admins[source])then 
 Admins[source]= nil 
  triggerClientEvent("updateAdmins",source,Admins) 
end 
end) 

client

local Admins = {} 
  
addEvent("updateAdmins",true) 
addEventHandler("updateAdmins",root, 
function(t) 
Admins = t 
end) 
  
function isPlayerAdmin(player) 
    if(Admins[player]) then 
        return true 
    end 
    return false 
end 

Link to comment
just use getElementData, elementData is syncronized(if you set in server or client both will have it)

If it's syncronized then what could cause this? What could be the problem?

zIXDeTv.png

Here's the part of my client side code:

  
    local fontSize = 1.15 
     
    local money = getPlayerMoney(getLocalPlayer()) 
    local bankMoney = getElementData(getLocalPlayer(), "bank.balance") 
    if money < 0 then 
        moneyColor = tocolor(175, 30, 30, 255) -- piros (red) 
        bankMoneyColor = tocolor(215,100,100,255) 
    else 
        moneyColor = tocolor(35, 130, 50, 255) -- zöld (green) 
        bankMoneyColor = tocolor(115,235,140,255) 
    end 
    dxDrawBorderedText("$"..money,x*1850, y*50, x*1850, y*40,moneyColor, fontSize,"pricedown","right","top",false,false,false) -- készpénz (money in pocket) 
    dxDrawBorderedText("$"..bankMoney,x*1850, y*80, x*1850, y*40,bankMoneyColor, fontSize,"pricedown","right","top",false,false,false) -- bank egyenleg (money in bank) 
  

I've even tried write tostring and tonumber before bankMoney, but if I leave it like this or write tonumber then it gives me this error, if I write tostring it writes $false.

Link to comment

you need use setElementDatabwhen you'r use setAccountData or you can use this...

addEventHandler("onAccountDataChange", root, 
function (account, key, value) 
    local thePlayer = getAccountPlayer(account) 
    if (thePlayer) then 
        setElementData(thePlayer, "account_"..key, value) 
    end 
end) 
  
addEventHandler("onPlayerLogin", root, 
function (_, account) 
    local alldata = getAllAccountData(account) 
    for key, value in pairs(alldata) do 
        setElementData(source, "account_"..key, value) 
    end 
end) 
  
addEventHandler("onPlayerLogout", root, 
function (_, account) 
    local alldata = getAllAccountData(account) 
    for key, value in pairs(alldata) do 
        removeElementData(source, "account_"..key, value) 
    end 
end) 

Exmple:

  
    local bankMoney = getElementData(getLocalPlayer(), "account_bank.balance") 
  

Edited by Guest
Link to comment

Never use element data for SUCH THINGS. You can use tables always! Element data uses alot of memory and CPU as far as I have listened.

  
bankbalances = {} 
  
addEventHandler("onAccountDataChange", root, 
function (account, key, value) 
    local thePlayer = getAccountPlayer(account) 
    if (thePlayer and key == "bank.balance") then 
        bankbalances[ thePlayer ] = value 
        triggerClientEvent( "onClientRequestBankBalance", thePlayer, bankbalances ) 
    end 
end) 
  
addEventHandler("onPlayerLogin", root, 
function (_, account) 
    local alldata = getAccountData( getPlayerAccount(source), "bank.balance" ) 
    bankbalances[ source ] = alldata  
    triggerClientEvent( "onClientRequestBankBalance", thePlayer, bankbalances ) 
end) 
  
addEventHandler("onPlayerLogout", root, 
function (_, account) 
    if bankbalances[ source ] then 
        bankbalances[ source ] = nil 
    end 
end) 
  

Client:

  
balancesClient = {} 
  
function getPlayerBankMoney( player ) 
    if balancesClient[ player ] then 
        return balancesClient[ player ] 
    else 
    return false  
    end 
end 
  
addEvent( "onClientRequestBankBalance", true ) 
addEventHandler( "onClientRequestBankBalance", root, 
    function( table ) 
        balancesClient = table  
    end 
) 
  

BTW: You can ask for help on skype: anubhav.agarwal80, i'd be happy to help you out. If you need further assistance with the code feel free to contact me!

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