ZH-CN/AclGetGroup: 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}} | ||
<!-- Describe in plain english what this function does. Don't go into details, just give an overview --> | <!-- Describe in plain english what this function does. Don't go into details, just give an overview --> | ||
此函数用于获取具有给定名称的ACL组.如果需要大多数组,应该考虑使用[[aclGroupList]]来获得包含所有组的表. | |||
== | ==语法== | ||
<!-- 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"> | ||
aclgroup aclGetGroup ( string groupName ) | aclgroup aclGetGroup ( string groupName ) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
{{ | {{OOP_ZH-CN|This function is a static function underneath the ACL Group class.|[[aclgroup|ACLGroup]].get||}} | ||
=== | ===必填参数=== | ||
<!-- 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 --> | ||
*'''groupName:''' | *'''groupName:''' 从中获取ACL组的名称 | ||
=== | ===返回值=== | ||
<!-- 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 --> | ||
返回ACL组(如果可以找到).如果它不存在或由于某种原因失败,则返回false/nil. | |||
== | ==示例== | ||
''' | '''例子 1:''' 这个例子使每个玩家都能使用一个名为“giveAccountAdminRights”的命令,该命令会将一个特定的账户名作为ACL对象添加到“Admin”组中. | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
function giveAdminRights (playerSource, commandName, accountName) -- | function giveAdminRights (playerSource, commandName, accountName) --添加函数giveAdminRights并指定其参数 | ||
if accountName then --if there was an accountName entered then | if accountName then --if there was an accountName entered then | ||
aclGroupAddObject (aclGetGroup("Admin"), "user."..accountName)) -- | aclGroupAddObject (aclGetGroup("Admin"), "user."..accountName)) --使用“user.[accountName]”格式将ACL对象添加到ACL组“Admin” | ||
outputChatBox ("Account '"..accountName.."' succesfully added to the admin group", playerSource) -- | outputChatBox ("Account '"..accountName.."' succesfully added to the admin group", playerSource) --向输入命令的玩家输出一个通知,通知其acocunt已成功添加 | ||
else -- | else --否则,将错误消息和命令的正确语法输出给输入它的玩家 | ||
outputChatBox ("No account name specified.", playerSource) | outputChatBox ("No account name specified.", playerSource) | ||
outputChatBox ("Correct syntax: /giveAccountAdminRights [accountName]", playerSource) | outputChatBox ("Correct syntax: /giveAccountAdminRights [accountName]", playerSource) | ||
Line 32: | Line 32: | ||
end | end | ||
addCommandHandler ("giveAccountAdminRights", giveAdminRights) -- | addCommandHandler ("giveAccountAdminRights", giveAdminRights) --添加一个命令“giveAccountAdminRights”并将函数“giveAdminRights”添加到其中 | ||
</syntaxhighlight> | </syntaxhighlight> | ||
''' | '''例子 2:''' 此示例显示聊天框中所有在线管理员的列表(假设ACL中的管理员组名为“admin”): | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
players = getElementsByType ( "player" ) | players = getElementsByType ( "player" ) |
Revision as of 03:35, 6 February 2021
此函数用于获取具有给定名称的ACL组.如果需要大多数组,应该考虑使用aclGroupList来获得包含所有组的表.
语法
aclgroup aclGetGroup ( string groupName )
OOP 语法 什么是OOP?
- 提示: This function is a static function underneath the ACL Group class.
- 方法: ACLGroup.get(...)
必填参数
- groupName: 从中获取ACL组的名称
返回值
返回ACL组(如果可以找到).如果它不存在或由于某种原因失败,则返回false/nil.
示例
例子 1: 这个例子使每个玩家都能使用一个名为“giveAccountAdminRights”的命令,该命令会将一个特定的账户名作为ACL对象添加到“Admin”组中.
function giveAdminRights (playerSource, commandName, accountName) --添加函数giveAdminRights并指定其参数 if accountName then --if there was an accountName entered then aclGroupAddObject (aclGetGroup("Admin"), "user."..accountName)) --使用“user.[accountName]”格式将ACL对象添加到ACL组“Admin” outputChatBox ("Account '"..accountName.."' succesfully added to the admin group", playerSource) --向输入命令的玩家输出一个通知,通知其acocunt已成功添加 else --否则,将错误消息和命令的正确语法输出给输入它的玩家 outputChatBox ("No account name specified.", playerSource) outputChatBox ("Correct syntax: /giveAccountAdminRights [accountName]", playerSource) end end addCommandHandler ("giveAccountAdminRights", giveAdminRights) --添加一个命令“giveAccountAdminRights”并将函数“giveAdminRights”添加到其中
例子 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