AclList: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 12: Line 12:


==Example==  
==Example==  
<!-- Explain what the example is in a single sentance -->
This example adds a command ''listacls'' which prints out a name list of all ACLs to the console.
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 printOutAllACLs ( thePlayer )
    -- get a table over all the ACLs
    local allACLs = aclList()
    -- if the table is empty (there are no ACLs)
    if #allACLs == 0 then
        -- print out a message to console and exit function
        outputConsole ( "There are no ACLs!", thePlayer )
        return
    else
        -- print out a list of the names
        outputConsole ( "List of all ACLs:", thePlayer )
        for key, singleACL in ipairs ( allACLs ) do
            local ACLName = aclGetName ( singleACL )
            outputConsole ( "- " .. tostring ( ACLName ), thePlayer )
        end
  end
end
addCommandHandler ( "listacls", printOutAllACLs )
</syntaxhighlight>
</syntaxhighlight>


==See Also==
==See Also==
{{ACL_functions}}
{{ACL_functions}}
[[Category:Needs_Example]]

Revision as of 18:41, 22 June 2009

This function returns a list of all the ACLs.

Syntax

table aclList ()

Returns

Returns a table of all the ACLs. This table can be empty if no ACLs exist. It can also return false/nil if it failed for some reason.

Example

This example adds a command listacls which prints out a name list of all ACLs to the console.

function printOutAllACLs ( thePlayer )
    -- get a table over all the ACLs
    local allACLs = aclList()
    -- if the table is empty (there are no ACLs)
    if #allACLs == 0 then
        -- print out a message to console and exit function
        outputConsole ( "There are no ACLs!", thePlayer )
        return
    else
        -- print out a list of the names
        outputConsole ( "List of all ACLs:", thePlayer )
        for key, singleACL in ipairs ( allACLs ) do
            local ACLName = aclGetName ( singleACL )
            outputConsole ( "- " .. tostring ( ACLName ), thePlayer )
        end
   end
end
addCommandHandler ( "listacls", printOutAllACLs )

See Also