ZH-CN/AclCreate: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
mNo edit summary
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
__NOTOC__  
__NOTOC__  
{{Server function}}
{{Server function}}
This function creates an ACL entry in the Access Control List system with the specified name.
此函数用于在访问控制列表系统中创建具有指定名称的ACL条目.


==Syntax==  
==语法==  
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
acl aclCreate ( string aclName )
acl aclCreate ( string aclName )
</syntaxhighlight>  
</syntaxhighlight>  
{{OOP||[[ACL]]||}}
{{OOP_ZH-CN||[[ACL]]||}}
===Required Arguments===  
===必填函数===  
*'''aclName:''' The name of the ACL entry to add.
*'''aclName:''' 要添加的ACL条目的名称.


===Returns===
===返回值===
Returns the created ACL object if successful. Returns false if an ACL of the given name could not be created.
如果成功,返回创建的ACL对象.如果无法创建给定名称的ACL,则返回false.


==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 )
     -- 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 34: Line 34:


     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 )
Line 41: Line 41:
     -- and finally let's set the right
     -- 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
Line 49: Line 49:
==See Also==
==See Also==
{{ACL_functions}}
{{ACL_functions}}
[[ar:aclCreate]]
[[en:aclCreate]]
[[zh-cn:AclCreate]]
[[zh-cn:AclCreate]]
[[en:AclCreate]]

Latest revision as of 18:09, 21 February 2021

此函数用于在访问控制列表系统中创建具有指定名称的ACL条目.

语法

acl aclCreate ( string aclName )

OOP 语法 什么是OOP?

方法: ACL(...)

必填函数

  • aclName: 要添加的ACL条目的名称.

返回值

如果成功,返回创建的ACL对象.如果无法创建给定名称的ACL,则返回false.

示例

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

function setACLRight ( thePlayer, commandName, aclName, rightName, access )
    -- 将布尔字符串转换为小写
    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

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

    -- and finally let's set the right
    aclSetRight ( ourACL, rightName, access )
    -- 不要忘记在修改ACL后保存它
    aclSave ()
end
addCommandHandler ( "setaclright", setACLRight )

See Also