AclGetGroup: Difference between revisions
Jump to navigation
Jump to search
m (→See Also) |
mNo edit summary |
||
(15 intermediate revisions by 9 users not shown) | |||
Line 1: | Line 1: | ||
__NOTOC__ | __NOTOC__ | ||
{{Server function}} | |||
<!-- Describe in plain english what this function does. Don't go into details, just give an overview --> | <!-- Describe in plain english what this function does. Don't go into details, just give an overview --> | ||
This | 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== | ==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 --> | <!-- 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"> | ||
aclgroup aclGetGroup ( string | aclgroup aclGetGroup ( string groupName ) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
{{OOP|This function is a static function underneath the ACL Group class.|[[aclgroup|ACLGroup]].get||}} | |||
===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 --> | <!-- 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 --> | ||
*''' | *'''groupName:''' The name to get the ACL group 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 --> | <!-- Make this descriptive. Explain what cases will return false. If you're unsure, add a tag to it so we can check --> | ||
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== | ||
< | |||
'''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. | |||
<syntaxhighlight lang="lua"> | |||
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 | |||
</syntaxhighlight> | |||
'''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'): | |||
<syntaxhighlight lang="lua"> | <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> | </syntaxhighlight> | ||
Line 37: | Line 59: | ||
<!-- 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}} | ||
[[ | |||
[[ar:aclGetGroup]] | |||
[[en:AclGetGroup]] | |||
[[zh-cn:AclGetGroup]] |
Latest revision as of 18:22, 21 February 2021
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 )
OOP Syntax Help! I don't understand this!
- Note: This function is a static function underneath the ACL Group class.
- Method: ACLGroup.get(...)
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 (assuming your administrator's group in your ACL is called 'admin'):
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)
See Also
- aclCreate
- aclCreateGroup
- aclDestroy
- aclDestroyGroup
- aclGet
- aclGetGroup
- aclGetName
- aclGetRight
- aclGroupAddACL
- aclGroupAddObject
- aclGroupGetName
- aclGroupList
- aclGroupListACL
- aclGroupListObjects
- aclGroupRemoveACL
- aclGroupRemoveObject
- aclList
- aclListRights
- aclReload
- aclRemoveRight
- aclSave
- aclSetRight
- hasObjectPermissionTo
- isObjectInACLGroup