diff --git a/config/file_loader.lua b/config/file_loader.lua index 993582b8..caa0a1a8 100644 --- a/config/file_loader.lua +++ b/config/file_loader.lua @@ -14,6 +14,7 @@ return { 'modules.commands.cheat-mode', 'modules.commands.interface', 'modules.commands.help', + 'modules.commands.roles', -- QoL Addons 'modules.addons.chat-popups', 'modules.addons.damage-popups', diff --git a/config/roles.lua b/config/roles.lua index 4cead3dd..81cf5b7d 100644 --- a/config/roles.lua +++ b/config/roles.lua @@ -58,6 +58,8 @@ Roles.new_role('Moderator','Mod') :set_flag('is_spectator') :set_parent('Trainee') :allow{ + 'command/assign-role', + 'command/unassign-role' } Roles.new_role('Trainee','TrMod') @@ -141,7 +143,8 @@ Roles.new_role('Guest','') 'command/me', 'command/tag', 'command/tag-clear', - 'command/chelp' + 'command/chelp', + 'command/list-roles' } --- Jail role diff --git a/locale/en/commands.cfg b/locale/en/commands.cfg index ddf4213b..e1cff318 100644 --- a/locale/en/commands.cfg +++ b/locale/en/commands.cfg @@ -7,4 +7,7 @@ chelp-title=Help results for "__1__": chelp-footer=(__1__ results found; page __2__ of __3__) chelp-format=/__1__ __2__ - __3__ __4__ chelp-alias=Alias: __1__ -chelp-out-of-range=__1__ is an invalid page number. \ No newline at end of file +chelp-out-of-range=__1__ is an invalid page number. +roles-higher-role=The role you tried to assign is higher than your highest. +roles-list=All active roles are: +roles-list-element=__1__, [color=__2__]__3__ \ No newline at end of file diff --git a/modules/commands/roles.lua b/modules/commands/roles.lua new file mode 100644 index 00000000..64bdb74e --- /dev/null +++ b/modules/commands/roles.lua @@ -0,0 +1,45 @@ +local Commands = require 'expcore.commands' +local Roles = require 'expcore.roles' +local Colours = require 'resources.color_presets' + +Commands.new_command('assign-role','Assigns a role to a player') +:add_param('player',false,'player-role') +:add_param('role',false,'role') +:set_flag('admin-only',true) +:add_alias('rpromote','assign','role','add-role') +:register(function(player,action_player,role,raw) + local player_highest = Roles.get_player_highest(player) + if player_highest.index < role.index then + Roles.assign_player(action_player,role,player.name) + else + return Commands.error{'exp-commands.roles-higher-role'} + end +end) + +Commands.new_command('unassign-role','Unassigns a role from a player') +:add_param('player',false,'player-role') +:add_param('role',false,'role') +:set_flag('admin-only',true) +:add_alias('rdemote','unassign','remove-role') +:register(function(player,action_player,role,raw) + local player_highest = Roles.get_player_highest(player) + if player_highest.index < role.index then + Roles.unassign_player(action_player,role,player.name) + else + return Commands.error{'exp-commands.roles-higher-role'} + end +end) + +Commands.new_command('list-roles','Lists all roles in they correct order') +:add_alias('lroles','roles') +:register(function(player,raw) + local roles = Roles.config.order + local message = {'exp-commands.roles-list'} + for _,role_name in pairs(roles) do + local role = Roles.get_role_by_name(role_name) + local colour = role.custom_color or Colours.white + colour = string.format('%d,%d,%d',colour.r,colour.g,colour.b) + message = {'exp-commands.roles-list-element',message,colour,role_name} + end + return Commands.success(message) +end) \ No newline at end of file