ZH-CN/aclGroupListObjects

From Multi Theft Auto: Wiki
Revision as of 06:47, 6 February 2021 by Qwe7769611 (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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

语法

table aclGroupListObjects ( aclgroup theGroup )

OOP 语法 什么是OOP?

方法: aclgroup:listObjects(...)
变量: .objects

必填参数

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

返回值

返回给定ACL组中的字符串表。这张表子可能是空的。如果组无效或由于其他原因失败,则返回“false”或“nil”.

示例

如果给定了ACL组,本例将输出对象列表.(已测试!)

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)


本例通过命令“getadmincounts”输出添加到“Admin”组的所有帐户.

Click to collapse [-]
Example 2: Server
function outputAdminGroupAccounts( player )
    local admins = {} -- 创建将在其中添加“Admin”组帐户的表
    local group = aclGetGroup( "Admin" )
    -- 如果在ACL中找到“Admin”组,则应返回“aclgroup”
    if (group) then
        for _, object in ipairs(aclGroupListObjects(group) or {}) do
            local objType = gettok( object, 1, string.byte('.') )
            -- objType:只获取对象类型,可以是“user”或“resource”
            if (objType == "user") then -- 检查是否是玩家帐户
                local _name = gettok( object, 2, string.byte('.') ) -- 忽略“user.”,将其与帐户名分开
                table.insert( admins, _name ) -- 将帐户名添加到“admins”表中
            end
        end
    end
    for i, name in ipairs(admins) do -- 在“admins”表中循环
        outputChatBox(tostring(i).." : "..tostring(name), player, 140, 220, 140)
        -- 输出如下:“1:John”
    end
end
addCommandHandler("getAdminAccounts", outputAdminGroupAccounts)
-- 添加命令“getAdminAccounts”并将其附加到函数“outputAdminGroupAccounts”


See Also