Jump to content

Help With Getting Player Groups


Zuher Laith

Recommended Posts

Greetings Everyone ..

Recently I was looking for an Code to Get The Player Groups

to Make the Idea Clear ..

Example: In Admin Panel (P) , On Selected Player, it Gave's you the Player Groups , Like (Console, Admin, Everyone) etc.

So Basically What I want is to Get the Logged User Groups & Insert it On a Label ..

So it's Only Give's the Player Groups Information the Source Player, Not for Another Player.

Here is What i Tried:

- I tried to Copy the Code in Admin Panel Of Setting the Player Groups, but After Taking a Look on the Code, It was Difficult for Me because I'am not that "PRO" Level At Lua.

Any Suggestions Or help Please ? ..

Waiting for Reply.

Link to comment

Admin panel is quite complicated but it doesn't do anything more complex (in that respect) than syncing clientside table with serverside ACL and then looping the table, checking whether such groups in particular apply to the context (the player you're checking against) and concatenation the names of such groups into one string.

Link to comment
Admin panel is quite complicated but it doesn't do anything more complex (in that respect) than syncing clientside table with serverside ACL and then looping the table, checking whether such groups in particular apply to the context (the player you're checking against) and concatenation the names of such groups into one string.

Could you tell me more please ? or Giving me an Example Code at least ? ..

I Didn't Got the Idea ..

Link to comment

If I understand it you want to show player's groups, yea?

If so, function would look like that

-- serverside 
function getGroups(player) 
    if (isElement(player) and getElementType(player) == "player") then 
        local allGroups = aclGroupList(); 
        local groups = ""; 
        for _, v in ipairs(allGroups) do 
            if (isObjectInACLGroup("user." .. getAccountName(getPlayerAccount(player)), v)) then 
                groups = aclGroupGetName(v) .. ", " .. groups; 
            end 
        end 
         
        return groups; 
    end 
end 

It should return a string which will contain all names of groups that declared player is in.

Link to comment

Okay, then in the event that you create this label add following lines

triggerServerEvent("s_getGroups", localPlayer) --insert this into event you create CurrentGroupLabel 
  
addEvent("c_getGroups", true) 
addEventHandler("c_getGroups", localPlayer, 
    function (groups) 
        guiSetText(Project.CurrentGroupLabel, groups) 
    end 
); 

And the serverside code should look like that

function getGroups() 
    if (isElement(source) and getElementType(source) == "player") then 
        local allGroups = aclGroupList(); 
        local groups = ""; 
        for _, v in ipairs(allGroups) do 
            if (isObjectInACLGroup("user." .. getAccountName(getPlayerAccount(source)), v)) then 
                groups = aclGroupGetName(v) .. ", " .. groups; 
            end 
        end 
         
        triggerClientEvent(source, "c_getGroups", source, groups); 
    end 
end 
addEvent("s_getGroups", true) 
addEventHandler("s_getGroups", root, getGroups) 

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