ZH-CN/IsObjectInACLGroup: Difference between revisions
Jump to navigation
Jump to search
Qwe7769611 (talk | contribs) No edit summary |
Qwe7769611 (talk | contribs) No edit summary |
||
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.}} | ||
此函数用于确定对象是否在组中. | |||
== | ==语法== | ||
<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||[[aclgroup]]:doesContainObject||}}}} | ||
=== | ===必填参数=== | ||
*'''theObject:''' | *'''theObject:''' 要检查的对象的名称. 示例: "resource.ctf", "user.Jim". | ||
*'''theGroup:''' | *'''theGroup:''' 应该从中找到对象的组的[[ACL group]]指针函数. | ||
===Returns=== | ===Returns=== | ||
如果对象在指定的组中,则返回“true”,否则返回“false”. | |||
== | ==示例== | ||
''' | ''' 示例 1:''' 此示例添加了一个仅对管理员可用的“jetpack”命令.当输入命令时,它将切换玩家的喷气背包. | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
addCommandHandler ( "jetpack", | addCommandHandler ( "jetpack", | ||
function ( thePlayer ) | function ( thePlayer ) | ||
if doesPedHaveJetPack ( thePlayer ) then -- | if doesPedHaveJetPack ( thePlayer ) then -- 如果玩家已经有一个喷气背包,移除它 | ||
removePedJetPack ( thePlayer ) -- | removePedJetPack ( thePlayer ) -- 移除喷气背包 | ||
return -- | return -- 在这里停止函数 | ||
end | end | ||
-- Otherwise, | -- Otherwise, 给她一个 if he has access | ||
local accName = getAccountName ( getPlayerAccount ( thePlayer ) ) -- | local accName = getAccountName ( getPlayerAccount ( thePlayer ) ) -- 获取他的帐户名 | ||
if isObjectInACLGroup ("user."..accName, aclGetGroup ( "Admin" ) ) then -- | if isObjectInACLGroup ("user."..accName, aclGetGroup ( "Admin" ) ) then -- 他有权限使用管理功能吗 | ||
if not doesPedHaveJetPack ( thePlayer ) then -- | if not doesPedHaveJetPack ( thePlayer ) then -- 如果玩家没有喷气背包,就给他. | ||
givePedJetPack ( thePlayer ) -- | givePedJetPack ( thePlayer ) -- 给予喷气背包 | ||
end | end | ||
end | end | ||
Line 38: | Line 38: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
''' | '''示例2:''' 此示例显示聊天框中所有联机管理员的列表(假设ACL中的管理员组名为“admin”): | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
players = getElementsByType ( "player" ) | players = getElementsByType ( "player" ) |
Revision as of 07:34, 6 February 2021
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 Syntax Help! I don't understand this!
- Method: aclgroup:doesContainObject(...)
必填参数
- theObject: 要检查的对象的名称. 示例: "resource.ctf", "user.Jim".
- theGroup: 应该从中找到对象的组的ACL group指针函数.
Returns
如果对象在指定的组中,则返回“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
- aclCreate
- aclCreateGroup
- aclDestroy
- aclDestroyGroup
- aclGet
- aclGetGroup
- aclGetName
- aclGetRight
- aclGroupAddACL
- aclGroupAddObject
- aclGroupGetName
- aclGroupList
- aclGroupListACL
- aclGroupListObjects
- aclGroupRemoveACL
- aclGroupRemoveObject
- aclList
- aclListRights
- aclReload
- aclRemoveRight
- aclSave
- aclSetRight
- hasObjectPermissionTo
- isObjectInACLGroup