Added /tag and /tag-clear

This commit is contained in:
Cooldude2606
2019-03-04 19:01:34 +00:00
parent d6aa2e0225
commit 08038272b6
7 changed files with 41 additions and 9 deletions

View File

@@ -18,7 +18,8 @@ local files = {
'modules.test',
'modules.commands.me',
'modules.commands.kill',
'modules.commands.admin-chat'
'modules.commands.admin-chat',
'modules.commands.tag',
}
-- Loads all files in array above and logs progress

View File

@@ -506,7 +506,7 @@ end
function Commands.internal_error(success,command_name,error_message)
if not success then
Commands.error('Internal Error, Please contact an admin','utility/cannot_build')
log('[ERROR] command/'..command_name..' :: '..error_message)
log{'expcore-commands.command-error-log-format',command_name,error_message}
end
return not success
end
@@ -613,8 +613,7 @@ function Commands.run_command(command_event)
-- used below as the reject function
local parse_fail = function(error_message)
error_message = error_message or ''
Commands.error('Invalid Param "'..param_name..'"; '..error_message)
return
return Commands.error{'expcore-commands.invalid-param',param_name,error_message}
end
-- input: string, player: LuaPlayer, reject: function, ... extra args
local success,param_parsed = pcall(parse_callback,raw_params[index],player,parse_fail,unpack(param_data.parse_args))
@@ -629,7 +628,9 @@ function Commands.run_command(command_event)
end
elseif param_parsed == nil or param_parsed == Commands.defines.error or param_parsed == parse_fail then
-- no value was returned or error was returned, if nil then give generic error
if not param_parsed == Commands.defines.error then Commands.error('Invalid Param "'..param_name..'"; please make sure it is the correct type') end
if not param_parsed == Commands.defines.error then
Commands.error{'expcore-commands.command-error-param-format',param_name,'please make sure it is the correct type'}
end
return
end
-- adds the param to the table to be passed to the command callback

View File

@@ -94,7 +94,7 @@ end)
Commands.add_parse('player',function(input,player,reject)
if not input then return end -- nil check
local input_player = Game.get_player_from_any(input)
if not player then
if not input_player then
return reject{'expcore-commands.reject-player',input}
else
return input_player

View File

@@ -10,5 +10,7 @@ reject-player-alive=Player is dead.
reject-force=Invaild Force Name
reject-surface=Invaild surface Name
invalid-inputs=Invalid Input, /__1__ __2__
invalid-param=Invalid Param "__1__"; __2__
command-ran=Command Complete
command-fail=Command failed to run: __1__
command-fail=Command failed to run: __1__
command-error-log-format=[ERROR] command/__1__ :: __2__

View File

@@ -10,5 +10,7 @@ reject-player-alive=Player is dead.
reject-force=Invaild Force Name
reject-surface=Invaild surface Name
invalid-inputs=Invalid Input, /__1__ __2__
invalid-param=Invalid Param "__1__"; __2__
command-ran=Command Complete
command-fail=Command failed to run: __1__
command-fail=Command failed to run: __1__
command-error-log-format=[ERROR] command/__1__ :: __2__

View File

@@ -1,5 +1,4 @@
local Commands = require 'expcore.commands'
require 'expcore.common_parse'
Commands.new_command('me','Sends an action message in the chat')
:add_param('action',false)

27
modules/commands/tag.lua Normal file
View File

@@ -0,0 +1,27 @@
local Commands = require 'expcore.commands'
require 'expcore.common_parse'
Commands.new_command('tag','Sets your player tag.')
:add_param('tag',false,'string-max-length',20)
:enable_auto_concat()
:register(function(player,tag,raw)
player.tag = ' - '..tag
end)
Commands.new_command('tag-clear','Clears your tag. Or another player if you are admin.')
:add_param('player',true,'player')
:add_defaults{player=function(player)
return player
end}
:register(function(player,action_player,raw)
if action_player.index == player.index then
-- no player given so removes your tag
action_player.tag = ''
elseif player.admin then
-- player given and user is admin so clears that player's tag
action_player.tag = ''
else
-- user is not admin and tried to clear another users tag
return Commands.error{'expcore-commands.unauthorized'}
end
end)