ZH-CN/IsObjectInACLGroup: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(2 intermediate revisions by the same user not shown)
Line 2: Line 2:
{{Server function}}  
{{Server function}}  
{{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.}}
{{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.}}
This function is used to determine if an object is in a group.
此函数用于确定对象是否在组中.


==Syntax==  
==语法==  
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
bool isObjectInACLGroup ( string theObject, aclgroup theGroup )
bool isObjectInACLGroup ( string theObject, aclgroup theGroup )
</syntaxhighlight>  
</syntaxhighlight>  
{{New feature/item|3.0141|1.4.0|6994|{{OOP||[[aclgroup]]:doesContainObject||}}}}
{{New feature/item|3.0141|1.4.0|6994|{{OOP_ZH-CN||[[aclgroup]]:doesContainObject||}}}}
===Required Arguments===  
===必填参数===  
*'''theObject:''' the name of the object to check. Examples: "resource.ctf", "user.Jim".
*'''theObject:''' 要检查的对象的名称. 示例: "resource.ctf", "user.Jim".
*'''theGroup:''' the [[ACL group]] pointer of the group from which the object should be found.
*'''theGroup:''' 应该从中找到对象的组的[[ACL group]]指针函数.


===Returns===
===返回值===
Returns ''true'' if the object is in the specified group, ''false'' otherwise.
如果对象在指定的组中,则返回“true”,否则返回“false”.


==Example==  
==示例==  
''' Example 1:''' This example adds a ''jetpack'' command that is only available to admins. When entering the command, it will toggle the player's jetpack.
''' 示例 1:''' 此示例添加了一个仅对管理员可用的“jetpack”命令.当输入命令时,它将切换玩家的喷气背包.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
addCommandHandler ( "jetpack",
addCommandHandler ( "jetpack",
     function ( thePlayer )
     function ( thePlayer )
         if doesPedHaveJetPack ( thePlayer ) then -- If the player have a jetpack already, remove it
         if doesPedHaveJetPack ( thePlayer ) then -- 如果玩家已经有一个喷气背包,移除它
             removePedJetPack ( thePlayer ) -- Remove the jetpack
             removePedJetPack ( thePlayer ) -- 移除喷气背包
             return -- And stop the function here
             return -- 在这里停止函数
         end
         end
     -- Otherwise, give him one if he has access
     -- Otherwise, 给她一个 if he has access


     local accName = getAccountName ( getPlayerAccount ( thePlayer ) ) -- get his account name
     local accName = getAccountName ( getPlayerAccount ( thePlayer ) ) -- 获取他的帐户名
     if isObjectInACLGroup ("user."..accName, aclGetGroup ( "Admin" ) ) then -- Does he have access to Admin functions?
     if isObjectInACLGroup ("user."..accName, aclGetGroup ( "Admin" ) ) then -- 他有权限使用管理功能吗
           if not doesPedHaveJetPack ( thePlayer ) then -- If the player doesn't have a jetpack give it.
           if not doesPedHaveJetPack ( thePlayer ) then -- 如果玩家没有喷气背包,就给他.
               givePedJetPack ( thePlayer )  -- Give the jetpack
               givePedJetPack ( thePlayer )  -- 给予喷气背包
           end
           end
     end
     end
Line 38: Line 38:
</syntaxhighlight>
</syntaxhighlight>


'''Example 2:''' This example displays a list of all the online admins in the chat box (assuming your administrator's group in your ACL is called 'admin'):
'''示例2:''' 此示例显示聊天框中所有联机管理员的列表(假设ACL中的管理员组名为“admin”):
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
players = getElementsByType ( "player" )
players = getElementsByType ( "player" )

Latest revision as of 07:34, 6 February 2021

[[{{{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