ZH-CN/aclGroupListObjects

From Multi Theft Auto: Wiki
Revision as of 06:43, 6 February 2021 by Qwe7769611 (talk | contribs) (Created page with "__NOTOC__ {{Server function}} <!-- Change this to "Client function" or "Server function" appropriately--> <!-- Describe in plain english what this function does. Don't go int...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

此函数用于返回给定ACL组中存在的所有对象的表。这些都是像玩家和资源这样的对象.

Syntax

table aclGroupListObjects ( aclgroup theGroup )

OOP Syntax Help! I don't understand this!

Method: aclgroup:listObjects(...)
Variable: .objects


Required Arguments

  • theGroup: 要从中获取对象的ACL组

Returns

Returns a table of strings in the given ACL group. This table might be empty. Returns false or nil if theGroup is invalid or it fails for some other reason.

Examples

This example outputs a list of Objects if the ACL Group is given. (TESTED!)

Click to collapse [-]
Example 1: Server
addCommandHandler("aclObjectList",function(player,command,aclGroup)
	if(aclGroup~="")then
		table = aclGroupListObjects(aclGetGroup(aclGroup))
		count = 0
		for objects,name in pairs(table)do
			outputChatBox("ACL LIST: "..aclGroup.." #"..tostring(count).." Object: "..name..".",player)
			count = count + 1
		end
	else
		outputChatBox("Please add the aclGroup you want the list of.",player)
		outputChatBox("Syntax: /aclObjectList aclGroup",player)
	end
end)


This example outputs through the command "getAdminAccounts" all accounts added to the "Admin" group.

Click to collapse [-]
Example 2: Server
function outputAdminGroupAccounts( player )
    local admins = {} -- creates the table in which will be added the accounts of "Admin" group
    local group = aclGetGroup( "Admin" )
    -- should return the "aclgroup" if the "Admin" group be found in ACL
    if (group) then
        for _, object in ipairs(aclGroupListObjects(group) or {}) do
            local objType = gettok( object, 1, string.byte('.') )
            -- objType: gets the object type only, which can be either "user" or "resource"
            if (objType == "user") then -- checks if it's a player account
                local _name = gettok( object, 2, string.byte('.') ) -- ignores "user." by separating that from the account name
                table.insert( admins, _name ) -- adds the account name to the "admins" table
            end
        end
    end
    for i, name in ipairs(admins) do -- loop through the table "admins"
        outputChatBox(tostring(i).." : "..tostring(name), player, 140, 220, 140)
        -- output will look like this: "1 : John"
    end
end
addCommandHandler("getAdminAccounts", outputAdminGroupAccounts)
-- adds the command "getAdminAccounts" and attaches it to the function "outputAdminGroupAccounts"


See Also