AclGetGroup: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(added example)
Line 19: Line 19:


==Example==  
==Example==  
<!-- Explain what the example is in a single sentance -->
 
This example makes every player able to use a command named "giveAccountAdminRights" that will add a specific accountname as an ACL object to the "Admin" group.
'''Example 1:''' This example makes every player able to use a command named "giveAccountAdminRights" that will add a specific accountname as an ACL object to the "Admin" group.
<!-- 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">
function giveAdminRights (playerSource, commandName, accountName) --add the function giveAdminRights and specify its arguments
function giveAdminRights (playerSource, commandName, accountName) --add the function giveAdminRights and specify its arguments
Line 35: Line 34:
addCommandHandler ("giveAccountAdminRights", giveAdminRights) --add a command "giveAccountAdminRights" and attch the function "giveAdminRights" to it  
addCommandHandler ("giveAccountAdminRights", giveAdminRights) --add a command "giveAccountAdminRights" and attch the function "giveAdminRights" to it  
</syntaxhighlight>
</syntaxhighlight>
'''Example 2:''' This example displays a list of all the online admins in the chat box:
<syntaxhighlight lang="lua">
players = getElementsByType ( "player" )
admins = ""
for k,v in ipairs(players) do
  local accountname = ""
  if (isGuestAccount(getPlayerAccount(v)) == false) then
      accountname = getAccountName (getPlayerAccount(v))
      if isObjectInACLGroup ( "user." .. accountname, aclGetGroup ( "admin" ) ) then
        if (admins == "") then
            admins = getPlayerName(v)
        else
            admins = admins .. ", " .. getPlayerName(v)
        end
      end
  end
end
outputChatBox( "Online Admins:", getRootElement(), 255, 255, 0)
outputChatBox( " " .. tostring ( admins ), getRootElement(), 255, 255, 0)
</syntaxhighlight>[lua]


==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 -->
<!-- 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}}

Revision as of 01:48, 6 June 2010

This function is used to get the ACL group with the given name. If you need most of the groups you should consider using aclGroupList instead to get a table containing them all.

Syntax

aclgroup aclGetGroup ( string groupName )

Required Arguments

  • groupName: The name to get the ACL group from

Returns

Returns the ACL group if it could be found. Returns false/nil if it did not exist or failed for some reason.

Example

Example 1: This example makes every player able to use a command named "giveAccountAdminRights" that will add a specific accountname as an ACL object to the "Admin" group.

function giveAdminRights (playerSource, commandName, accountName) --add the function giveAdminRights and specify its arguments
	if accountName then --if there was an accountName entered then
		aclGroupAddObject (aclGetGroup("Admin"), "user."..accountName)) --add an ACL object using the form "user.[accountName]" to the ACL group "Admin"
		outputChatBox ("Account '"..accountName.."' succesfully added to the admin group", playerSource) --output a notification to the player who entered the command that the acocunt was successfully added
	else --else output an error message and the correct syntax of the command to the player who entered it
		outputChatBox ("No account name specified.", playerSource)
		outputChatBox ("Correct syntax: /giveAccountAdminRights [accountName]", playerSource)
	end
end

addCommandHandler ("giveAccountAdminRights", giveAdminRights) --add a command "giveAccountAdminRights" and attch the function "giveAdminRights" to it 

Example 2: This example displays a list of all the online admins in the chat box:

players = getElementsByType ( "player" )
admins = ""
for k,v in ipairs(players) do
   local accountname = ""
   if (isGuestAccount(getPlayerAccount(v)) == false) then
      accountname = getAccountName (getPlayerAccount(v))
      if isObjectInACLGroup ( "user." .. accountname, aclGetGroup ( "admin" ) ) then
         if (admins == "") then
            admins = getPlayerName(v)
         else
            admins = admins .. ", " .. getPlayerName(v)
         end
      end
   end
end
outputChatBox( "Online Admins:", getRootElement(), 255, 255, 0)
outputChatBox( " " .. tostring ( admins ), getRootElement(), 255, 255, 0)

[lua]

See Also