A role is a group of players that share a set of permissions, such as gamemaster. A role has a name, a description, a color, an icon, an immunity level that Bolt:check_immunity compares between players, and optionally a base role (base) whose permissions it shares. Roles are normally defined by a file in a plugin's roles folder, which fills in the ROLE global and may define define_permissions to allow or deny actions with can, cannot and allow_anything; see Role:register. The role files are what decides which permissions each role has by default. A role file whose ID is already registered adds its permissions to that role (and to the roles based on it) instead of defining a new one, so that a plugin or schema can give the existing roles the permissions of its own commands. The actions that a role's own files allow or deny stay as they are when a base role gets new permissions (own_permissions, see Role:set_own). A player's role is read with Player:get_role and set with Player:SetUserGroup.

Summary

Methods

Allows this role to perform an action, optionally only on one kind of object.
Makes every permission check against this role pass.
Checks whether this role allows an action.
Explicitly denies an action for this role, overriding a permission inherited from its base.
Returns the ID of the role this role is based on.
Returns the role's color.
Returns the role's description, usually a language phrase.
Returns the role's icon.
get_id()shared
Returns the role's ID.
Returns the role's immunity level, which Bolt:check_immunity compares between roles.
Returns the role's display name.
Returns the role's permission table.
init(id)shared
Sets the role's ID and gives it empty permission tables.
Checks whether the role is flagged as protected.
Called when the player's role is being set to this role.
Called when the player's role is taken or modified.
Registers the role with Bolt.
Records that the role's own role files decided an action, so that the permissions its base role gets later leave that action alone.

Methods

Role:allow(action, object, callback)

shared plugins/admin/plugin/lib/classes/sh_role.lua:48

Allows this role to perform an action, optionally only on one kind of object. If a callback is given, it decides the outcome of each check.

function ROLE:define_permissions()
  self:allow('kick')
  self:allow('noclip', nil, function(actor, object)
    return actor:Alive()
  end)
end

Parameters

  • action String permission ID
  • object String/Map optional, defaults to 'anything' object name, or a class table whose class_name is used
  • callback Function optional, defaults to nil called as callback(actor, object) on every check; its return value becomes the result

Makes every permission check against this role pass.

Role:can(actor, action, object)

shared plugins/admin/plugin/lib/classes/sh_role.lua:109

Checks whether this role allows an action. Only the role's own permission table is consulted; use actor:can for the full check that includes per-player permissions.

Parameters

  • actor Player passed on to the permission's callback
  • action String permission ID; an empty string always passes
  • object String optional, defaults to 'anything' object name the permission was allowed for

Returns

  • Boolean whether the action is allowed (a permission callback's return value is passed through as is)

Role:disallow(action, object)

shared plugins/admin/plugin/lib/classes/sh_role.lua:66

Explicitly denies an action for this role, overriding a permission inherited from its base.

Parameters

  • action String permission ID
  • object String/Map optional, defaults to 'anything' object name, or a class table whose class_name is used

Returns the ID of the role this role is based on.

Returns

  • String base role ID, or nil if there is none

Returns the role's color.

Returns

  • Color

Role:get_description()

shared plugins/admin/plugin/lib/classes/sh_role.lua:156

Returns the role's description, usually a language phrase.

Returns

  • String

Returns the role's icon.

Returns

  • String icon path or Font Awesome icon name

Returns the role's ID.

Returns

  • String

Returns the role's immunity level, which Bolt:check_immunity compares between roles.

Returns

  • Number

Returns the role's display name.

Returns

  • String

Role:get_permissions()

shared plugins/admin/plugin/lib/classes/sh_role.lua:180

Returns the role's permission table.

Returns

  • Map permission entries (allowed, callback) keyed by object name, then by action

Sets the role's ID and gives it empty permission tables. Does nothing without an ID.

Parameters

  • id String role ID, normalized with string.to_id

Checks whether the role is flagged as protected.

Returns

  • Boolean

Role:on_role_set(_target, _old_group)

shared plugins/admin/plugin/lib/classes/sh_role.lua:134

Called when the player's role is being set to this role. Return any non-nil value to keep the new role from being saved to the database.

Parameters

  • _target Player
  • _old_group Role the player's previous role

Role:on_role_taken(_target, _new_group)

shared plugins/admin/plugin/lib/classes/sh_role.lua:140

Called when the player's role is taken or modified. Return any non-nil value to keep the new role from being saved to the database.

Parameters

  • _target Player
  • _new_group Role the role the player is being given

Registers the role with Bolt. If the role has a define_permissions method, it is run first with the can, cannot and allow_anything globals temporarily bound to this role, followed by the OnDefinePermissions hook. A role file whose ID is already registered adds its permissions to that role and to the roles based on it that have nothing of their own for the same actions; its other fields are ignored, see Bolt:create_role.

-- roles/sh_helper.lua
ROLE.name = 'Helper'
ROLE.immunity = 50
ROLE.base = 'user'

function ROLE:define_permissions()
  can 'kick'
  cannot 'ban'
end

See also

Role:set_own(action, object)

shared plugins/admin/plugin/lib/classes/sh_role.lua:85

Records that the role's own role files decided an action, so that the permissions its base role gets later leave that action alone. Role:allow and Role:disallow call this.

Parameters

  • action String permission ID
  • object String optional, defaults to 'anything' object name

Defined in