Added command parse for roles

This commit is contained in:
Cooldude2606
2019-04-09 21:48:09 +01:00
parent 9df2a958f8
commit 7cfcedd97b
5 changed files with 56 additions and 24 deletions

View File

@@ -1,9 +1,10 @@
local Commands = require 'expcore.commands'
local Roles = require 'expcore.roles'
require 'config.command_parse_general'
require 'config.command_parse_role'
Commands.new_command('kill','Kills yourself or another player.')
:add_param('player',true,'player-alive') -- the player to kill, must be alive to be valid
:add_param('player',true,'player-role-alive') -- the player to kill, must be alive to be valid
:set_defaults{player=function(player)
-- default is the player unless they are dead
if player.character and player.character.health > 0 then
@@ -18,13 +19,7 @@ end}
if player == action_player then
action_player.character.die()
elseif Roles.player_allowed(player,'command/kill/always') then
local player_highest = Roles.get_player_highest_role(player)
local action_player_highest = Roles.get_player_highest_role(action_player)
if player_highest.index < action_player_highest.index then
action_player.character.die()
else
return Commands.error{'expcore-roles.command-error-higher-role',action_player.name}
end
action_player.character.die()
else
return Commands.error{'expcore-commands.unauthorized'}
end

View File

@@ -1,6 +1,7 @@
local Commands = require 'expcore.commands'
local Roles = require 'expcore.roles'
require 'config.command_parse_general'
require 'config.command_parse_role'
Commands.new_command('tag','Sets your player tag.')
:add_param('tag',false,'string-max-length',20) -- new tag for your player max 20 char
@@ -10,7 +11,7 @@ Commands.new_command('tag','Sets your player tag.')
end)
Commands.new_command('tag-clear','Clears your tag. Or another player if you are admin.')
:add_param('player',true,'player') -- player to remove the tag of, nil to apply to self
:add_param('player',true,'player-role') -- player to remove the tag of, nil to apply to self
:set_defaults{player=function(player)
return player -- default is the user using the command
end}
@@ -20,13 +21,7 @@ end}
action_player.tag = ''
elseif Roles.player_allowed(player,'command/clear-tag/always') then
-- player given and user is admin so clears that player's tag
local player_highest = Roles.get_player_highest_role(player)
local action_player_highest = Roles.get_player_highest_role(action_player)
if player_highest.index < action_player_highest.index then
action_player.tag = ''
else
return Commands.error{'expcore-roles.command-error-higher-role',action_player.name}
end
action_player.tag = ''
else
-- user is not admin and tried to clear another users tag
return Commands.error{'expcore-commands.unauthorized'}