Jump to content

if player in acl group, then set element data


Annas

Recommended Posts

Hello community members,

Just i need something , when a player in ACL group Name , it setElementData "something" , i tried to make this:

SERVER SIDE

function hitdbs(player) 
    accName = getAccountName(getPlayerAccount(player)) 
    if isObjectInACLGroup ("user."..accName, aclGetGroup ( "DL1" )) then 
    setElementData (player, "CSThit", "DL1") 
    end 
    if isObjectInACLGroup ("user."..accName, aclGetGroup ( "DL2" )) then 
    setElementData (player, "CSThit", "DL2") 
    end 
    if isObjectInACLGroup ("user."..accName, aclGetGroup ( "DL3" )) then 
    setElementData (player, "CSThit", "DL3") 
else 
setElementData (player, "CSThit", "None") 
end 
end 
end 

When a player in DL1 Acl group , i need this element data setted to him ("CSThit", "DL1") , and when a player DL2 ("CSThit", "DL2") and DL3 ("CSThit", "DL3") , but not work :/ , please help me , i can explain more.. , and i need it if you enter exemple to acl DL1 , it added that element data ("CSThit", "DL1") and when i leave it it back to 0 ("CSThit", "None")

Sorry for my bad english :mrgreen:

Link to comment

You should use elseif not just if. You have an extra end as well.

function hitdbs(player) 
    accName = getAccountName(getPlayerAccount(player)) 
    if isObjectInACLGroup ("user."..accName, aclGetGroup ( "DL1" )) then 
    setElementData (player, "CSThit", "DL1") 
    elseif isObjectInACLGroup ("user."..accName, aclGetGroup ( "DL2" )) then 
    setElementData (player, "CSThit", "DL2") 
    elseif isObjectInACLGroup ("user."..accName, aclGetGroup ( "DL3" )) then 
    setElementData (player, "CSThit", "DL3") 
else 
setElementData (player, "CSThit", "None") 
end 
end 

Link to comment

I thought this was part of your code. If this is the full code then you need to use it with onPlayerLogin.

function hitdbs(old, new) 
    local accName = getAccountName(new) 
    if isObjectInACLGroup ("user."..accName, aclGetGroup ( "DL1" )) then 
        setElementData (source, "CSThit", "DL1") 
    elseif isObjectInACLGroup ("user."..accName, aclGetGroup ( "DL2" )) then 
        setElementData (source, "CSThit", "DL2") 
    elseif isObjectInACLGroup ("user."..accName, aclGetGroup ( "DL3" )) then 
        setElementData (source, "CSThit", "DL3") 
        else 
            setElementData (source, "CSThit", "None") 
        end 
end 
addEventHandler('onPlayerLogin', root, hitdbs) 

Link to comment

You don't need to do all fo this simply it can be like this.

local dlGroups = { "DL1", "DL2", "DL3"}; 
  
addEventHandler ( "onPlayerLogin", root, 
    function ( _, theAccount ) 
        for a, g in ipairs (dlGroup) do 
            if ( isObjectInACLGroup ( "user."..getAccountName(theAccount) , aclGetGroup (g))) then 
                setElementData (source, "CSThit", "DL"..a) 
                return; 
            end 
        end 
    end 
); 

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