AclGroupListObjects: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
m (Removed comments, improved examples)
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
__NOTOC__  
__NOTOC__  
{{Server function}}
{{Server function}}
<!-- Change this to "Client function" or "Server function" appropriately-->
<!-- Describe in plain english what this function does. Don't go into details, just give an overview -->
This function returns a table over all the objects that exist in a given ACL group. These are objects like players and resources.
This function returns a table over all the objects that exist in a given ACL group. These are objects like players and resources.


==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">
table aclGroupListObjects ( aclgroup theGroup )
table aclGroupListObjects ( aclgroup theGroup )
Line 12: Line 9:
{{OOP||[[aclgroup]]:listObjects|objects|}}
{{OOP||[[aclgroup]]:listObjects|objects|}}
===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 -->
*'''theGroup:''' The ACL group to get the objects from
*'''theGroup:''' The ACL group to get the objects from


===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 a table of strings in the given ACL group. This table might be empty. Returns ''false'' or ''nil'' if theGroup is invalid or it fails for some other reason.
Returns a table of strings in the given ACL group. This table might be empty. Returns ''false'' or ''nil'' if theGroup is invalid or it fails for some other reason.


==Examples==  
==Examples==  
This example outputs a list of Objects if the ACL Group is given. (TESTED!)
This example outputs a list of Objects if the ACL Group is given
<section name="Example 1: Server" class="server" show="true">
<section name="Example 1: Server" class="server" show="true">
<syntaxhighlight lang="lua">addCommandHandler("aclObjectList",function(player,command,aclGroup)
<syntaxhighlight lang="lua">
if(aclGroup~="")then
addCommandHandler("aclObjectList",function(player,command,aclGroup)
table = aclGroupListObjects(aclGetGroup(aclGroup))
if aclGroup == '' then
count = 0
outputChatBox("Please add the aclGroup you want the list of.", player)
for objects,name in pairs(table)do
outputChatBox("Syntax: /aclObjectList aclGroup", player)
outputChatBox("ACL LIST: "..aclGroup.." #"..tostring(count).." Object: "..name..".",player)
return
count = count + 1
end
end
local objects = aclGroupListObjects(aclGetGroup(aclGroup))
else
for k,v in ipairs(objects) do
outputChatBox("Please add the aclGroup you want the list of.",player)
outputChatBox("ACL LIST: "..aclGroup.." #"..k.." Object: "..v,player)
outputChatBox("Syntax: /aclObjectList aclGroup",player)
end
end
end)
end)
Line 41: Line 35:
This example outputs through the command "getAdminAccounts" all accounts added to the "Admin" group.
This example outputs through the command "getAdminAccounts" all accounts added to the "Admin" group.
<section name="Example 2: Server" class="server" show="true">
<section name="Example 2: Server" class="server" show="true">
<syntaxhighlight lang="lua" >function outputAdminGroupAccounts( player )
<syntaxhighlight lang="lua">
    local admins = {} -- creates the table in which will be added the accounts of "Admin" group
function outputAdminGroupAccounts(player)
    local group = aclGetGroup( "Admin" )
local admins = {} -- creates the table in which will be added the accounts of "Admin" group
    -- should return the "aclgroup" if the "Admin" group be found in ACL
local group = aclGetGroup("Admin")
    if (group) then
-- should return the "aclgroup" if the "Admin" group be found in ACL
        for _, object in ipairs(aclGroupListObjects(group) or {}) do
if not group then return end
            local objType = gettok( object, 1, string.byte('.') )
for _, object in ipairs(aclGroupListObjects(group) or {}) do
            -- objType: gets the object type only, which can be either "user" or "resource"
local objType = gettok( object, 1, string.byte('.') )
            if (objType == "user") then -- checks if it's a player account
-- objType: gets the object type only, which can be either "user" or "resource"
                local _name = gettok( object, 2, string.byte('.') ) -- ignores "user." by separating that from the account name
if objType == "user" then -- checks if it's a player account
                table.insert( admins, _name ) -- adds the account name to the "admins" table
local _name = gettok( object, 2, string.byte('.') ) -- ignores "user." by separating that from the account name
            end
table.insert( admins, _name ) -- adds the account name to the "admins" table
        end
end
    end
end
     for i, name in ipairs(admins) do -- loop through the table "admins"
     for i, name in ipairs(admins) do -- loop through the table "admins"
         outputChatBox(tostring(i).." : "..tostring(name), player, 140, 220, 140)
         outputChatBox(tostring(i).." : "..tostring(name), player, 140, 220, 140)
Line 67: Line 61:


==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}}
[[zh-cn:aclGroupListObjects]]

Latest revision as of 12:09, 18 October 2023

This function returns a table over all the objects that exist in a given ACL group. These are objects like players and resources.

Syntax

table aclGroupListObjects ( aclgroup theGroup )

OOP Syntax Help! I don't understand this!

Method: aclgroup:listObjects(...)
Variable: .objects


Required Arguments

  • theGroup: The ACL group to get the objects from

Returns

Returns a table of strings in the given ACL group. This table might be empty. Returns false or nil if theGroup is invalid or it fails for some other reason.

Examples

This example outputs a list of Objects if the ACL Group is given

Click to collapse [-]
Example 1: Server
addCommandHandler("aclObjectList",function(player,command,aclGroup)
	if aclGroup == '' then
		outputChatBox("Please add the aclGroup you want the list of.", player)
		outputChatBox("Syntax: /aclObjectList aclGroup", player)
		return
	end
	local objects = aclGroupListObjects(aclGetGroup(aclGroup))
	for k,v in ipairs(objects) do
		outputChatBox("ACL LIST: "..aclGroup.." #"..k.." Object: "..v,player)
	end
end)


This example outputs through the command "getAdminAccounts" all accounts added to the "Admin" group.

Click to collapse [-]
Example 2: Server
function outputAdminGroupAccounts(player)
	local admins = {} -- creates the table in which will be added the accounts of "Admin" group
	local group = aclGetGroup("Admin")
	-- should return the "aclgroup" if the "Admin" group be found in ACL
	if not group then return end
	for _, object in ipairs(aclGroupListObjects(group) or {}) do
		local objType = gettok( object, 1, string.byte('.') )
		-- objType: gets the object type only, which can be either "user" or "resource"
		if objType == "user" then -- checks if it's a player account
			local _name = gettok( object, 2, string.byte('.') ) -- ignores "user." by separating that from the account name
			table.insert( admins, _name ) -- adds the account name to the "admins" table
		end
	end
    for i, name in ipairs(admins) do -- loop through the table "admins"
        outputChatBox(tostring(i).." : "..tostring(name), player, 140, 220, 140)
        -- output will look like this: "1 : John"
    end
end
addCommandHandler("getAdminAccounts", outputAdminGroupAccounts)
-- adds the command "getAdminAccounts" and attaches it to the function "outputAdminGroupAccounts"


See Also