ZH-CN/IsObjectInACLGroup

From Multi Theft Auto: Wiki
Jump to navigation Jump to search

[[{{{image}}}|link=|]] Important Note: You must NOT to use this function to limit features to users that belong to specific groups. Instead you MUST use hasObjectPermissionTo. Using this function forces the server owner to name their group a certain way, whereas using hasObjectPermissionTo allows the owner to give permission for whatever features you restrict to whatever groups they have set up in their ACL.

此函数用于确定对象是否在组中.

语法

bool isObjectInACLGroup ( string theObject, aclgroup theGroup )

OOP 语法 什么是OOP?

方法: aclgroup:doesContainObject(...)

必填参数

  • theObject: 要检查的对象的名称. 示例: "resource.ctf", "user.Jim".
  • theGroup: 应该从中找到对象的组的ACL group指针函数.

返回值

如果对象在指定的组中,则返回“true”,否则返回“false”.

示例

示例 1: 此示例添加了一个仅对管理员可用的“jetpack”命令.当输入命令时,它将切换玩家的喷气背包.

addCommandHandler ( "jetpack",
    function ( thePlayer )
        if doesPedHaveJetPack ( thePlayer ) then -- 如果玩家已经有一个喷气背包,移除它
            removePedJetPack ( thePlayer ) -- 移除喷气背包
            return -- 在这里停止函数
        end
		
     -- Otherwise, 给她一个 if he has access

     local accName = getAccountName ( getPlayerAccount ( thePlayer ) ) -- 获取他的帐户名
     if isObjectInACLGroup ("user."..accName, aclGetGroup ( "Admin" ) ) then -- 他有权限使用管理功能吗
          if not doesPedHaveJetPack ( thePlayer ) then -- 如果玩家没有喷气背包,就给他.
               givePedJetPack ( thePlayer )  -- 给予喷气背包
          end
     end
end
)

示例2: 此示例显示聊天框中所有联机管理员的列表(假设ACL中的管理员组名为“admin”):

players = getElementsByType ( "player" )
admins = ""
for k,v in ipairs(players) do
   local accountname = ""
   if (isGuestAccount(getPlayerAccount(v)) == false) then
      accountname = getAccountName (getPlayerAccount(v))
      if isObjectInACLGroup ( "user." .. accountname, aclGetGroup ( "admin" ) ) then
         if (admins == "") then
            admins = getPlayerName(v)
         else
            admins = admins .. ", " .. getPlayerName(v)
         end
      end
   end
end
outputChatBox( "Online Admins:", getRootElement(), 255, 255, 0)
outputChatBox( " " .. tostring ( admins ), getRootElement(), 255, 255, 0)

See Also