IsObjectInACLGroup: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
m (Updated both examples to look nicer (didn't change what they do) and not display bad practices (like global variables) so new devs can learn with good code)
 
(8 intermediate revisions by 6 users not shown)
Line 1: Line 1:
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
__NOTOC__
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
{{Server function}}
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
{{Important Note|You must '''NOT''' to use this function to limit features to users that belong to specific groups. Instead you '''MUST''' use [[hasObjectPermissionTo]]. Using this function forces the server owner to name their group a certain way, whereas using hasObjectPermissionTo allows the owner to give permission for whatever features you restrict to whatever groups they have set up in their ACL.}}
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
This function is used to determine if an object is in a group.
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
 
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
==Syntax==
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
<syntaxhighlight lang="lua">
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
bool isObjectInACLGroup ( string theObjectName, aclgroup theGroup )
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
</syntaxhighlight>
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
{{New feature/item|3.0141|1.4.0|6994|{{OOP||[[aclgroup]]:doesContainObject||}}}}
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
===Required Arguments===
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
*'''theObjectName:''' the name of the object to check. Examples: "resource.ctf", "user.Jim".
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
*'''theGroup:''' the [[AclGroup|ACL group]] pointer of the group from which the object should be found.
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
 
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
===Returns===
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
Returns ''true'' if the object is in the specified group, ''false'' otherwise.
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
 
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
==Example==
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
''' 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.
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
<syntaxhighlight lang="lua">
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
addCommandHandler ( "jetpack", function ( thePlayer )
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
    if doesPedHaveJetPack ( thePlayer ) then -- If the player have a jetpack already, remove it
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
        removePedJetPack ( thePlayer ) -- Remove the jetpack
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
        return -- And stop the function here
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
    end
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
 
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
    -- Otherwise, give him one if he has access
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
 
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
    local accName = getAccountName ( getPlayerAccount ( thePlayer ) ) -- get his account name
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
    if isObjectInACLGroup ("user."..accName, aclGetGroup ( "Admin" ) ) then -- Does he have access to Admin functions?
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
        if not doesPedHaveJetPack ( thePlayer ) then -- If the player doesn't have a jetpack give it.
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
            givePedJetPack ( thePlayer )  -- Give the jetpack
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
        end
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
    end
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
end)
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
</syntaxhighlight>
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
 
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
'''Example 2:''' This example displays a list of all the online admins in the chat box (assuming your administrator's group in your ACL is called 'Admin'):
Extrem liże hazowi dupsko a Barcioo liże cipsko Trinowi
<syntaxhighlight lang="lua">
local admins = ""
local players = getElementsByType("player")
for k, v in ipairs(players) do
  if not isGuestAccount(getPlayerAccount(v)) then
      local 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(" " .. admins, getRootElement(), 255, 255, 0)
</syntaxhighlight>
 
==See Also==
{{ACL_functions}}
[[zh-cn:IsObjectInACLGroup]]

Latest revision as of 20:48, 13 May 2024

[[{{{image}}}|link=|]] Important Note: You must NOT to use this function to limit features to users that belong to specific groups. Instead you MUST use hasObjectPermissionTo. Using this function forces the server owner to name their group a certain way, whereas using hasObjectPermissionTo allows the owner to give permission for whatever features you restrict to whatever groups they have set up in their ACL.

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

Syntax

bool isObjectInACLGroup ( string theObjectName, aclgroup theGroup )

OOP Syntax Help! I don't understand this!

Method: aclgroup:doesContainObject(...)

Required Arguments

  • theObjectName: 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 doesPedHaveJetPack ( thePlayer ) then -- If the player have a jetpack already, remove it
        removePedJetPack ( thePlayer ) -- Remove the jetpack
        return -- And stop the function here
    end

    -- Otherwise, give him one if he has access

    local accName = getAccountName ( getPlayerAccount ( thePlayer ) ) -- get his account name
    if isObjectInACLGroup ("user."..accName, aclGetGroup ( "Admin" ) ) then -- Does he have access to Admin functions?
        if not doesPedHaveJetPack ( thePlayer ) then -- If the player doesn't have a jetpack give it.
            givePedJetPack ( thePlayer )  -- Give the jetpack
        end
    end
end)

Example 2: This example displays a list of all the online admins in the chat box (assuming your administrator's group in your ACL is called 'Admin'):

local admins = ""
local players = getElementsByType("player")
for k, v in ipairs(players) do
   if not isGuestAccount(getPlayerAccount(v)) then
      local 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(" " .. admins, getRootElement(), 255, 255, 0)

See Also