ZH-CN/aclGetRight: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
mNo edit summary
 
Line 46: Line 46:
<!-- 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}}
[[en:aclGetRight]]
 
[[ar:aclGetRight]]
[[en:AclGetRight]]
[[zh-cn:aclGetRight]]

Latest revision as of 18:25, 21 February 2021

此函数返回ACL中给定权限的访问权限设置为true还是false.

语法

bool aclGetRight ( acl theAcl, string rightName )

OOP 语法 什么是OOP?

方法: acl:getRight(...)
对称函数: aclSetRight

必填参数

  • theAcl: 要从中获取权限的ACL
  • rightName: 返回的访问值的正确名称.

返回值

如果ACL允许或不允许访问给定函数,则返回“true”或“false”。如果由于某种原因失败,例如指定了无效的ACL或ACL中不存在指定的权限,则返回“nil”.

示例

这个例子允许玩家检查ACL组是否有权访问某些东西.

--theACL examples: Admin, Default, Moderator
--theRight examples: command.debugscript, function.banPlayer

function aclRightCheck(player, command, theACL, theRight)
	if (theACL and theRight) then -- Make sure atleast two arguments were entered.
		local theACL = aclGet(theACL) -- 如果ACL存在,则将其从字符串转换为ACL指针变量(pointer).
		if (theACL) then -- 如果找到ACL.
			local theReturn = aclGetRight(theACL, theRight) -- 如果在ACL中找到,则返回true.
			outputChatBox("The ACL right was found and returned: "..tostring(theReturn), player, 0, 255, 0)
		else
			outputChatBox("The ACL you entered was not found to exist in the ACL file.", player, 255, 0, 0) -- 当未找到ACL时.
		end
	else
		outputChatBox("You need to enter an ACL, and a right name.", player, 255, 0, 0) -- 当两个参数(argument)没有被输入时.
	end
end
addCommandHandler("aclgetright", aclRightCheck) -- 当玩家执行aclgetright命令时,它会调用上面的aclRightCheck函数.
-- Example of use: /aclgetright Admin command.debugscript (this should return true)
-- Example of use: /aclgetright Default command.debugscript (this should return false)

See Also