IsObjectInACLGroup: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
mNo edit summary
Line 16: Line 16:


==Example==  
==Example==  
This example adds a ''jetpack'' command that is only available to admins.  When entering the command, it will toggle the player's jetpack.
''' Example 1:''' This example adds a ''jetpack'' command that is only available to admins.  When entering the command, it will toggle the player's jetpack.
<section name="Server" class="server" show="true">
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
addCommandHandler ( "jetpack",
addCommandHandler ( "jetpack",
Line 36: Line 35:
     end
     end
)
)
</section>
</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==
{{ACL_functions}}
{{ACL_functions}}

Revision as of 01:47, 6 June 2010

This function is used to determine if an object is in a group.

Syntax

bool isObjectInACLGroup ( string theObject, aclgroup theGroup )

Required Arguments

  • theObject: the name of the object to check. Examples: "resource.ctf", "user.Jim".
  • theGroup: the ACL group pointer of the group from which the object should be found.

Returns

Returns true if the object is in the specified group, false otherwise.

Example

Example 1: This example adds a jetpack command that is only available to admins. When entering the command, it will toggle the player's jetpack.

addCommandHandler ( "jetpack",
    function ( thePlayer )
        -- If the player has a jetpack already, remove it
        if doesPedHaveJetPack ( thePlayer ) then
            removePedJetPack ( thePlayer ) -- Remove the jetpack
            return -- And stop the function here
        end
		
        -- Otherwise, give him one if he has access
        local playerName = getPlayerName ( thePlayer )
        -- Does he have access to Admin functions?
        if isObjectInACLGroup ( "user." .. playerName, aclGetGroup ( "Admin" ) ) then
            -- He's an admin. Give him a jetpack
            givePedJetPack ( thePlayer )
        end
    end
)

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