ZH-CN/aclSetRight: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
Line 1: Line 1:
__NOTOC__  
__NOTOC__  
{{Server function}}  
{{Server function}}  
This functions changes or adds the given right in the given ACL. The access can be ''true'' or ''false'' and specifies whether the ACL gives access to the right or not.
此函数用于更改或添加给定ACL中的给定权限。访问可以是“true”或“false”,并指定ACL是否允许访问权限.


==Syntax==  
==语法==  
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
bool aclSetRight ( acl theAcl, string rightName, bool hasAccess )
bool aclSetRight ( acl theAcl, string rightName, bool hasAccess )
</syntaxhighlight>  
</syntaxhighlight>  
{{OOP||[[acl]]:setRight||aclGetRight}}
{{OOP_ZH-CN||[[acl]]:setRight||aclGetRight}}
===Required Arguments===  
===必填参数===  
*'''theAcl:''' The ACL to change the right of
*'''theAcl:''' 要更改其权限的ACL
*'''rightName:''' The right to add/change the access property of
*'''rightName:''' 添加/更改的访问属性的权限
*'''hasAccess:''' Whether the access should be set to true or false
*'''hasAccess:''' 访问是否应设置为true或false


===Returns===
===返回值===
Returns ''true'' if the access was successfully changed, ''false'' or ''nil'' if it failed for some reason, ie. invalid ACL or the rightname is invalid.
如果访问已成功更改,则返回“true”;如果由于某种原因(例如无效的ACL或rightname无效)而失败,则返回“false”或“nil”.


==Example==  
==示例==  
This example adds a command ''setaclright'' with which you can easily add new rights to specified access control lists.
此示例添加了命令“setaclright”,使用该命令可以轻松地向指定的访问控制列表添加新权限.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function setACLRight ( thePlayer, commandName, aclName, rightName, access )
function setACLRight ( thePlayer, commandName, aclName, rightName, access )
     local ourACL = aclGet ( aclName )
     local ourACL = aclGet ( aclName )
     -- if there is no previous ACL with this name, we need to create one
     -- 如果以前没有具有此名称的ACL,则需要创建一个
     if not ourACL then
     if not ourACL then
         ourACL = aclCreate ( aclName )
         ourACL = aclCreate ( aclName )
     end
     end


     -- turn the boolean string to lower case
     -- 将布尔字符串转换为小写
     access = string.lower ( access )
     access = string.lower ( access )
     -- access has to be either true or false (booleans)
     -- 访问必须是true或false(布尔值)
     if not (access == "true" or access == "false") then
     if not (access == "true" or access == "false") then
         -- print out error message to debug window
         -- 将错误消息发送到调试窗口
         return outputDebugString ( "Invalid access; true and false are only accepted", 1 )
         return outputDebugString ( "Invalid access; true and false are only accepted", 1 )
     end
     end


     -- change the access to boolean
     -- 将访问权限更改为布尔值
     if access == "true" then
     if access == "true" then
         access = true
         access = true
Line 41: Line 41:
     end
     end


     -- and finally let's set the right
     -- 最后让我们确定正确的方向
     aclSetRight ( ourACL, rightName, access )
     aclSetRight ( ourACL, rightName, access )
     -- don't forget to save the ACL after it has been modified
     -- 不要忘记在修改ACL后保存它
     aclSave ()
     aclSave ()
end
end

Latest revision as of 07:16, 6 February 2021

此函数用于更改或添加给定ACL中的给定权限。访问可以是“true”或“false”,并指定ACL是否允许访问权限.

语法

bool aclSetRight ( acl theAcl, string rightName, bool hasAccess )

OOP 语法 什么是OOP?

方法: acl:setRight(...)
对称函数: aclGetRight

必填参数

  • theAcl: 要更改其权限的ACL
  • rightName: 添加/更改的访问属性的权限
  • hasAccess: 访问是否应设置为true或false

返回值

如果访问已成功更改,则返回“true”;如果由于某种原因(例如无效的ACL或rightname无效)而失败,则返回“false”或“nil”.

示例

此示例添加了命令“setaclright”,使用该命令可以轻松地向指定的访问控制列表添加新权限.

function setACLRight ( thePlayer, commandName, aclName, rightName, access )
    local ourACL = aclGet ( aclName )
    -- 如果以前没有具有此名称的ACL,则需要创建一个
    if not ourACL then
        ourACL = aclCreate ( aclName )
    end

    -- 将布尔字符串转换为小写
    access = string.lower ( access )
    -- 访问必须是true或false(布尔值)
    if not (access == "true" or access == "false") then
        -- 将错误消息发送到调试窗口
        return outputDebugString ( "Invalid access; true and false are only accepted", 1 )
    end

    -- 将访问权限更改为布尔值
    if access == "true" then
        access = true
    else 
        access = false
    end

    -- 最后让我们确定正确的方向
    aclSetRight ( ourACL, rightName, access )
    -- 不要忘记在修改ACL后保存它
    aclSave ()
end
addCommandHandler ( "setaclright", setACLRight )

See Also