AclSetRight: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(New page: __NOTOC__ <!-- Describe in plain english what this function does. Don't go into details, just give an overview --> This fake function is for use with blah & blah and does blahblahblabhalb...)
 
m (Added "resource" as the ACL rights type)
 
(14 intermediate revisions by 10 users not shown)
Line 1: Line 1:
__NOTOC__  
__NOTOC__  
<!-- Describe in plain english what this function does. Don't go into details, just give an overview -->
{{Server function}}
This fake function is for use with blah & blah and does blahblahblabhalbhl
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.


==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">
bool aclSetRight ( acl theAcl, string rightname, bool access )
bool aclSetRight ( acl theAcl, string rightName, bool hasAccess )
</syntaxhighlight>  
</syntaxhighlight>  
 
{{OOP||[[acl]]:setRight||aclGetRight}}
===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 -->
*'''theAcl:''' The ACL to change the right of
*'''argumentName:''' description
*'''rightName:''' The right to add/change the access property of. It '''must''' be prefixed with "'''function.'''" or "'''command.'''" or "'''general.'''" or "'''resource.'''"
 
*'''hasAccess:''' Whether the access should be set to true or false
<!-- Only include this section below if there are optional arguments -->
===Optional Arguments===
{{OptionalArg}}
*'''argumentName2:''' description
*'''argumentName3:''' description


===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 ''true'' if the access was successfully changed, ''false'' or ''nil'' if it failed for some reason, ie. invalid ACL or the rightname is invalid.
Returns ''true'' if blah, ''false'' otherwise.


==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">
--This line does...
function setACLRight ( thePlayer, commandName, aclName, rightName, access )
blabhalbalhb --abababa
    local ourACL = aclGet ( aclName )
--This line does this...
    -- if there is no previous ACL with this name, we need to create one
mooo
    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:Incomplete]] -- leave this unless you complete the function
[[zh-cn:aclSetRight]]

Latest revision as of 16:21, 1 March 2023

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.

Syntax

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

OOP Syntax Help! I don't understand this!

Method: acl:setRight(...)
Counterpart: aclGetRight


Required Arguments

  • theAcl: The ACL to change the right of
  • rightName: The right to add/change the access property of. It must be prefixed with "function." or "command." or "general." or "resource."
  • hasAccess: Whether the access should be set to true or 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.

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