ZH-CN/aclGroupListObjects: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 5: Line 5:
此函数用于返回给定ACL组中存在的所有对象的表。这些都是像玩家和资源这样的对象.
此函数用于返回给定ACL组中存在的所有对象的表。这些都是像玩家和资源这样的对象.


==Syntax==  
==语法==  
<!-- NOTE: don't use 'special' names for variable names, e.g. you shouldn't be writing things like 'player player, vehicle vehicle', instead write something like 'player thePlayer, vehicle vehicleToGetInto'. This is less confusing and prevents the syntax highlighting being odd -->
<!-- NOTE: don't use 'special' names for variable names, e.g. you shouldn't be writing things like 'player player, vehicle vehicle', instead write something like 'player thePlayer, vehicle vehicleToGetInto'. This is less confusing and prevents the syntax highlighting being odd -->
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
table aclGroupListObjects ( aclgroup theGroup )
table aclGroupListObjects ( aclgroup theGroup )
</syntaxhighlight>  
</syntaxhighlight>  
{{OOP||[[aclgroup]]:listObjects|objects|}}
{{OOP_ZH-CN||[[aclgroup]]:listObjects|objects|}}
===Required Arguments===  
===必填参数===  
<!-- List each argument one per line. This should be the argument's name as in the argument list above, NOT the argument's data type -->
<!-- List each argument one per line. This should be the argument's name as in the argument list above, NOT the argument's data type -->
*'''theGroup:''' 要从中获取对象的ACL组
*'''theGroup:''' 要从中获取对象的ACL组


===Returns===
===返回值===
<!-- Make this descriptive. Explain what cases will return false. If you're unsure, add a tag to it so we can check -->
<!-- Make this descriptive. Explain what cases will return false. If you're unsure, add a tag to it so we can check -->
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.
返回给定ACL组中的字符串表。这张表子可能是空的。如果组无效或由于其他原因失败,则返回“false”或“nil”.


==Examples==  
==示例==  
This example outputs a list of Objects if the ACL Group is given. (TESTED!)
如果给定了ACL组,本例将输出对象列表.(已测试!)
<section name="Example 1: Server" class="server" show="true">
<section name="Example 1: Server" class="server" show="true">
<syntaxhighlight lang="lua">addCommandHandler("aclObjectList",function(player,command,aclGroup)
<syntaxhighlight lang="lua">addCommandHandler("aclObjectList",function(player,command,aclGroup)
Line 42: Line 42:
<section name="Example 2: Server" class="server" show="true">
<section name="Example 2: Server" class="server" show="true">
<syntaxhighlight lang="lua" >function outputAdminGroupAccounts( player )
<syntaxhighlight lang="lua" >function outputAdminGroupAccounts( player )
     local admins = {} -- creates the table in which will be added the accounts of "Admin" group
     local admins = {} -- 创建将在其中添加“Admin”组帐户的表
     local group = aclGetGroup( "Admin" )
     local group = aclGetGroup( "Admin" )
     -- should return the "aclgroup" if the "Admin" group be found in ACL
     -- 如果在ACL中找到“Admin”组,则应返回“aclgroup”
     if (group) then
     if (group) then
         for _, object in ipairs(aclGroupListObjects(group) or {}) do
         for _, object in ipairs(aclGroupListObjects(group) or {}) do
             local objType = gettok( object, 1, string.byte('.') )
             local objType = gettok( object, 1, string.byte('.') )
             -- objType: gets the object type only, which can be either "user" or "resource"
             -- objType:只获取对象类型,可以是“user”或“resource”
             if (objType == "user") then -- checks if it's a player account
             if (objType == "user") then -- 检查是否是玩家帐户
                 local _name = gettok( object, 2, string.byte('.') ) -- ignores "user." by separating that from the account name
                 local _name = gettok( object, 2, string.byte('.') ) -- 忽略“user.”,将其与帐户名分开
                 table.insert( admins, _name ) -- adds the account name to the "admins" table
                 table.insert( admins, _name ) -- 将帐户名添加到“admins”表中
             end
             end
         end
         end
     end
     end
     for i, name in ipairs(admins) do -- loop through the table "admins"
     for i, name in ipairs(admins) do -- 在“admins”表中循环
         outputChatBox(tostring(i).." : "..tostring(name), player, 140, 220, 140)
         outputChatBox(tostring(i).." : "..tostring(name), player, 140, 220, 140)
         -- output will look like this: "1 : John"
         -- 输出如下:“1:John”
     end
     end
end
end
addCommandHandler("getAdminAccounts", outputAdminGroupAccounts)
addCommandHandler("getAdminAccounts", outputAdminGroupAccounts)
-- adds the command "getAdminAccounts" and attaches it to the function "outputAdminGroupAccounts"
-- 添加命令“getAdminAccounts”并将其附加到函数“outputAdminGroupAccounts”
</syntaxhighlight>
</syntaxhighlight>
</section>
</section>

Revision as of 06:46, 6 February 2021

此函数用于返回给定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)


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 = {} -- 创建将在其中添加“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