AclGet: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
mNo edit summary
 
(7 intermediate revisions by 7 users not shown)
Line 1: Line 1:
__NOTOC__  
__NOTOC__  
{{Server function}}  
{{Server function}}  
<!-- Describe in plain english what this function does. Don't go into details, just give an overview -->
Get the ACL with the given name. If need to get most of the ACL's, you should consider using [[aclList]] to get a table of them all.
Get the ACL with the given name. If need to get most of the ACL's, you should consider using [[aclList]] to get a table of them all.


==Syntax==  
==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 -->
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
acl aclGet ( string aclName )
acl aclGet ( string aclName )
</syntaxhighlight>  
</syntaxhighlight>  
 
{{OOP|This function is a static function underneath the ACL class.|[[ACL]].get||}}
===Required Arguments===  
===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 -->
*'''aclName:''' The name to get the ACL belonging to
*'''aclName:''' The name to get the ACL belonging to


===Returns===
===Returns===
<!-- Make this descriptive. Explain what cases will return false. If you're unsure, add a tag to it so we can check -->
Returns the ACL with that name if it could be retrieved, ''false''/''nil'' if the ACL does not exist or it fails for some other reason.
Returns the ACL with that name if it could be retrieved, ''false''/''nil'' if the ACL does not exist or it fails for some other reason.


==Example==  
==Example==  
<!-- Explain what the example is in a single sentance -->
This example adds a command ''setaclright'' with which you can easily add new rights to specified access control lists.
This example does...
<!-- Add the code below, an emphasis should be on making it clear, not optimized. You could provide two versions if you wish, one clear and well commented, the other optimized -->
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
--TODO
function setACLRight ( thePlayer, commandName, aclName, rightName, access )
    local ourACL = aclGet ( aclName )
    -- if there is no previous ACL with this name, we need to create one
    if not ourACL then
        ourACL = aclCreate ( aclName )
    end
 
    -- turn the boolean string to lower case
    access = string.lower ( access )
    -- access has to be either true or false (booleans)
    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 )
    end
 
    -- change the access to boolean
    if access == "true" then
        access = true
    else
        access = false
    end
 
    -- and finally let's set the right
    aclSetRight ( ourACL, rightName, access )
    -- don't forget to save the ACL after it has been modified
    aclSave ()
end
addCommandHandler ( "setaclright", setACLRight )
</syntaxhighlight>
</syntaxhighlight>


==See Also==
==See Also==
<!-- 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}}
[[Category:Needs_Example]]
 
[[ar:aclGet]]
[[en:AclGet]]
[[zh-cn:AclGet]]

Latest revision as of 18:21, 21 February 2021

Get the ACL with the given name. If need to get most of the ACL's, you should consider using aclList to get a table of them all.

Syntax

acl aclGet ( string aclName )

OOP Syntax Help! I don't understand this!

Note: This function is a static function underneath the ACL class.
Method: ACL.get(...)


Required Arguments

  • aclName: The name to get the ACL belonging to

Returns

Returns the ACL with that name if it could be retrieved, false/nil if the ACL does not exist or it fails for some other reason.

Example

This example adds a command setaclright with which you can easily add new rights to specified access control lists.

function setACLRight ( thePlayer, commandName, aclName, rightName, access )
    local ourACL = aclGet ( aclName )
    -- if there is no previous ACL with this name, we need to create one
    if not ourACL then
        ourACL = aclCreate ( aclName )
    end

    -- turn the boolean string to lower case
    access = string.lower ( access )
    -- access has to be either true or false (booleans)
    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 )
    end

    -- change the access to boolean
    if access == "true" then
        access = true
    else 
        access = false
    end

    -- and finally let's set the right
    aclSetRight ( ourACL, rightName, access )
    -- don't forget to save the ACL after it has been modified
    aclSave ()
end
addCommandHandler ( "setaclright", setACLRight )

See Also