Jump to content

Help ! acl


scolen

Recommended Posts

  • Moderators

@scolen

You can give this utility function a try (untested). It is important to know that you can only check this information serverside.

--[[
    Check if the player is inside of an acl group with a specific name
    Argument 1: player element
    Argument 2: aclGroupName string
]]
function isPlayerInAclGroupWithName (player, aclGroupName) 
    -- Check if the player argument is filled in correctly
    if not isElement(player) or getElementType(player) ~= "player" then
        error("Expected player element at argument 1, got " .. inspect(player), 2)
    end

    -- Check if the aclGroupName is filled in correctly
    if type(aclGroupName) ~= "string" then
        error("Expected string at argument 2, got " .. inspect(aclGroupName), 2)
    end

    -- Get the player account and check if the player is logged in
    local account = getPlayerAccount ( player )
    if isGuestAccount(account) then return false end

    -- Get the acl group
    local aclGroup = aclGetGroup ( aclGroupName ) 
    if not aclGroup then return false end

    -- Check if the account name of the user is inside of the acl group
    local accountName = getAccountName ( account )
    return isObjectInACLGroup ("user." .. accountName, aclGroup)
end

Usage:

if isPlayerInAclGroupWithName(player, "police") then 
	outputChatBox("I am the police", player)
end

 

  • Thanks 1
Link to comment
On 28/07/2023 at 03:49, IIYAMA said:

@scolen

You can give this utility function a try (untested). It is important to know that you can only check this information serverside.

--[[
    Check if the player is inside of an acl group with a specific name
    Argument 1: player element
    Argument 2: aclGroupName string
]]
function isPlayerInAclGroupWithName (player, aclGroupName) 
    -- Check if the player argument is filled in correctly
    if not isElement(player) or getElementType(player) ~= "player" then
        error("Expected player element at argument 1, got " .. inspect(player), 2)
    end

    -- Check if the aclGroupName is filled in correctly
    if type(aclGroupName) ~= "string" then
        error("Expected string at argument 2, got " .. inspect(aclGroupName), 2)
    end

    -- Get the player account and check if the player is logged in
    local account = getPlayerAccount ( player )
    if isGuestAccount(account) then return false end

    -- Get the acl group
    local aclGroup = aclGetGroup ( aclGroupName ) 
    if not aclGroup then return false end

    -- Check if the account name of the user is inside of the acl group
    local accountName = getAccountName ( account )
    return isObjectInACLGroup ("user." .. accountName, aclGroup)
end

Usage:

if isPlayerInAclGroupWithName(player, "police") then 
	outputChatBox("I am the police", player)
end

 

thanks bro

 

  • Like 1
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...