From d6aa2e02258036580fceebdb35f75a7ae2b19bcb Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Sun, 3 Mar 2019 16:47:37 +0000 Subject: [PATCH] Added /kill and /admin-chat --- control.lua | 4 +++- expcore/commands.lua | 4 ++-- locale/en/commands-local.cfg | 3 +++ modules/commands/admin-chat.lua | 18 ++++++++++++++++++ modules/commands/commands-local.cfg | 3 +++ modules/commands/kill.lua | 19 +++++++++++++++++++ 6 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 locale/en/commands-local.cfg create mode 100644 modules/commands/admin-chat.lua create mode 100644 modules/commands/commands-local.cfg create mode 100644 modules/commands/kill.lua diff --git a/control.lua b/control.lua index 1014d21a..2709a4e2 100644 --- a/control.lua +++ b/control.lua @@ -16,7 +16,9 @@ require 'resources.version' local files = { 'modules.test', - 'modules.commands.me' + 'modules.commands.me', + 'modules.commands.kill', + 'modules.commands.admin-chat' } -- Loads all files in array above and logs progress diff --git a/expcore/commands.lua b/expcore/commands.lua index 6e324f7e..5947bb71 100644 --- a/expcore/commands.lua +++ b/expcore/commands.lua @@ -541,7 +541,7 @@ function Commands.run_command(command_event) end -- splits the arguments - local input_string = command_event.parameter + local input_string = command_event.parameter or '' local quote_params = {} -- stores any " " params input_string = input_string:gsub('"[^"]-"',function(w) -- finds all " " params are removes spaces for the next part @@ -642,7 +642,7 @@ function Commands.run_command(command_event) table.insert(params,input_string) local success, err = pcall(command_data.callback,player,unpack(params)) if Commands.internal_error(success,command_data.name,err) then return end - if err ~= Commands.defines.error and err ~= Commands.defines.success then Commands.success(err) end + if err ~= Commands.defines.error and err ~= Commands.defines.success and err ~= Commands.error and err ~= Commands.success then Commands.success(err) end end return Commands \ No newline at end of file diff --git a/locale/en/commands-local.cfg b/locale/en/commands-local.cfg new file mode 100644 index 00000000..57a9a17a --- /dev/null +++ b/locale/en/commands-local.cfg @@ -0,0 +1,3 @@ +[exp-commands] +kill-already-dead=You are already dead. +admin-chat-format=[Admin Chat] [color=__3__]__1__: __2__ \ No newline at end of file diff --git a/modules/commands/admin-chat.lua b/modules/commands/admin-chat.lua new file mode 100644 index 00000000..b7373ef9 --- /dev/null +++ b/modules/commands/admin-chat.lua @@ -0,0 +1,18 @@ +local Commands = require 'expcore.commands' +require 'expcore.common_parse' + +Commands.new_command('admin-chat','Sends a message in chat that only admins can see.') +:add_param('message',false) +:enable_auto_concat() +:add_tag('admin_only',true) +:add_alias('ac') +:register(function(player,message,raw) + local pcc = player.chat_color + local colour = string.format('%s,%s,%s',pcc.r,pcc.g,pcc.b) + for _,return_player in pairs(game.connected_players) do + if return_player.admin then + return_player.print{'exp-commands.admin-chat-format',player.name,message,colour} + end + end + return Commands.success -- prevents command complete message from showing +end) \ No newline at end of file diff --git a/modules/commands/commands-local.cfg b/modules/commands/commands-local.cfg new file mode 100644 index 00000000..57a9a17a --- /dev/null +++ b/modules/commands/commands-local.cfg @@ -0,0 +1,3 @@ +[exp-commands] +kill-already-dead=You are already dead. +admin-chat-format=[Admin Chat] [color=__3__]__1__: __2__ \ No newline at end of file diff --git a/modules/commands/kill.lua b/modules/commands/kill.lua new file mode 100644 index 00000000..486cf298 --- /dev/null +++ b/modules/commands/kill.lua @@ -0,0 +1,19 @@ +local Commands = require 'expcore.commands' +require 'expcore.common_parse' + +Commands.new_command('kill','Kills yourself or another player.') +:add_param('player',true,'player-alive') +:add_defaults{player=function(player) + -- default is the player unless they are dead + if player.character and player.character.health > 0 then + return player + end +end} +:add_tag('admin_only',true) +:register(function(player,action_player,raw) + if not action_player then + -- can only be nil if no player given and the user is dead + return Commands.error{'exp-commands.kill-already-dead'} + end + action_player.character.die() +end) \ No newline at end of file