IsObjectInACLGroup: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
mNo edit summary
Line 5: Line 5:
==Syntax==  
==Syntax==  
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
bool isObjectInACLGroup ( string theObject, string theGroup )
bool isObjectInACLGroup ( string theObject, aclgroup theGroup )
</syntaxhighlight>  
</syntaxhighlight>  
===Required Arguments===  
===Required Arguments===  


*'''theObject:''' the name of the object to check. Examples: "resource.ctf", "user.Jim".
*'''theObject:''' the name of the object to check. Examples: "resource.ctf", "user.Jim".
*'''theGroup:''' the name of the group to look in. Example: "Admin"
*'''theGroup:''' the [[ACL group]] pointer of the group from which the object should be found.


===Returns===
===Returns===
Line 30: Line 30:
         local playerName = getPlayerName ( thePlayer )
         local playerName = getPlayerName ( thePlayer )
         -- Does he have access to Admin functions?
         -- Does he have access to Admin functions?
         if isObjectInACLGroup ( "user." .. playerName, "Admin" ) then
         if isObjectInACLGroup ( "user." .. playerName, aclGetGroup ( "Admin" ) ) then
             -- He's an admin. Give him a jetpack
             -- He's an admin. Give him a jetpack
             givePedJetPack ( thePlayer )
             givePedJetPack ( thePlayer )

Revision as of 19:04, 31 March 2009

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

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

Click to collapse [-]
Server

<syntaxhighlight lang="lua"> 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

)

See Also