ZH-CN/aclGetRight: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
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 -->
This function returns whether the access for the given right is set to true or false in the ACL.
此函数返回ACL中给定权限的访问权限设置为true还是false.


==Syntax==  
==语法==  
<!-- 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">
bool aclGetRight ( acl theAcl, string rightName )
bool aclGetRight ( acl theAcl, string rightName )
</syntaxhighlight>  
</syntaxhighlight>  
{{OOP||[[acl]]:getRight||aclSetRight}}
{{OOP_ZH-CN||[[acl]]:getRight||aclSetRight}}
===Required Arguments===  
===必填参数===  
<!-- 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 -->
*'''theAcl:''' The ACL to get the right from
*'''theAcl:''' 要从中获取权限的ACL
*'''rightName:''' The right name to return the access value of.
*'''rightName:''' 返回的访问值的正确名称.


===Returns===
===返回值===
<!-- 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 -->
Returns ''true'' or ''false'' if the ACL gives access or not to the given function. Returns ''nil'' if it failed for some reason, e.g. an invalid ACL was specified or the right specified does not exist in the ACL.
如果ACL允许或不允许访问给定函数,则返回“true”或“false”。如果由于某种原因失败,例如指定了无效的ACL或ACL中不存在指定的权限,则返回“nil”.


==Example==  
==示例==  
This example lets players check if an ACL group has access to something or not.
这个例子允许玩家检查ACL组是否有权访问某些东西.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
--theACL examples: Admin, Default, Moderator
--theACL examples: Admin, Default, Moderator
Line 27: Line 27:
function aclRightCheck(player, command, theACL, theRight)
function aclRightCheck(player, command, theACL, theRight)
if (theACL and theRight) then -- Make sure atleast two arguments were entered.
if (theACL and theRight) then -- Make sure atleast two arguments were entered.
local theACL = aclGet(theACL) -- If theACL exists then convert it into an ACL pointer from a string.
local theACL = aclGet(theACL) -- 如果ACL存在,则将其从字符串转换为ACL指针变量(pointer).
if (theACL) then -- If the ACL was found.
if (theACL) then -- 如果找到ACL.
local theReturn = aclGetRight(theACL, theRight) -- Will return true if it was found in the ACL.
local theReturn = aclGetRight(theACL, theRight) -- 如果在ACL中找到,则返回true.
outputChatBox("The ACL right was found and returned: "..tostring(theReturn), player, 0, 255, 0)
outputChatBox("The ACL right was found and returned: "..tostring(theReturn), player, 0, 255, 0)
else
else
outputChatBox("The ACL you entered was not found to exist in the ACL file.", player, 255, 0, 0) -- When the ACL was not found.
outputChatBox("The ACL you entered was not found to exist in the ACL file.", player, 255, 0, 0) -- 当未找到ACL时.
end
end
else
else
outputChatBox("You need to enter an ACL, and a right name.", player, 255, 0, 0) -- When 2 arguements weren't entered.
outputChatBox("You need to enter an ACL, and a right name.", player, 255, 0, 0) -- 当两个参数(argument)没有被输入时.
end
end
end
end
addCommandHandler("aclgetright", aclRightCheck) -- When a player does the aclgetright command it calls aclRightCheck function above.
addCommandHandler("aclgetright", aclRightCheck) -- 当玩家执行aclgetright命令时,它会调用上面的aclRightCheck函数.
-- Example of use: /aclgetright Admin command.debugscript (this should return true)
-- Example of use: /aclgetright Admin command.debugscript (this should return true)
-- Example of use: /aclgetright Default command.debugscript (this should return false)
-- Example of use: /aclgetright Default command.debugscript (this should return false)

Revision as of 03:49, 6 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