ZH-CN/aclGroupListObjects: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(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...")
 
No edit summary
 
(2 intermediate revisions by the same user not shown)
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 39: Line 39:




This example outputs through the command "getAdminAccounts" all accounts added to the "Admin" group.
本例通过命令“getadmincounts”输出添加到“Admin”组的所有帐户.
<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>
Line 69: Line 69:
<!-- Change FunctionArea to the area that this function is in on the main function list page, e.g. Server, Player, Vehicle etc -->
<!-- Change FunctionArea to the area that this function is in on the main function list page, e.g. Server, Player, Vehicle etc -->
{{ACL_functions}}
{{ACL_functions}}
[[zh-cn:aclGroupListObjects]]
[[en:aclGroupListObjects]]

Latest revision as of 06:47, 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)


本例通过命令“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