From 402548dded7e2e4cb2b5eb8ffb8797a78940dcec Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Tue, 5 Mar 2019 20:34:17 +0000 Subject: [PATCH] Added /tp /bring and /goto and some comments --- control.lua | 1 + expcore/commands.lua | 4 +-- expcore/common_parse.lua | 2 +- expcore/locale/en.cfg | 1 + locale/en/commands-local.cfg | 4 ++- locale/en/expcore.cfg | 1 + modules/commands/admin-chat.lua | 2 +- modules/commands/commands-local.cfg | 4 ++- modules/commands/kill.lua | 2 +- modules/commands/me.lua | 2 +- modules/commands/tag.lua | 6 ++-- modules/commands/teleport.lua | 55 +++++++++++++++++++++++++++++ 12 files changed, 73 insertions(+), 11 deletions(-) create mode 100644 modules/commands/teleport.lua diff --git a/control.lua b/control.lua index 64bff3f4..1d810817 100644 --- a/control.lua +++ b/control.lua @@ -20,6 +20,7 @@ local files = { 'modules.commands.kill', 'modules.commands.admin-chat', 'modules.commands.tag', + 'modules.commands.teleport', } -- Loads all files in array above and logs progress diff --git a/expcore/commands.lua b/expcore/commands.lua index ff717788..d8acbb01 100644 --- a/expcore/commands.lua +++ b/expcore/commands.lua @@ -464,14 +464,14 @@ function Commands._prototype:register(callback) end self.description = description -- registers the command under its own name - commands.add_command(self.name,description..' '..self.help,function(command_event) + commands.add_command(self.name,{'expcore-commands.command-help',description,self.help},function(command_event) local success, err = pcall(Commands.run_command,command_event) if not success then log('[ERROR] command/'..self.name..' :: '..err) end end) -- adds any aliases that it has for _,alias in pairs(self.aliases) do if not commands.commands[alias] and not commands.game_commands[alias] then - commands.add_command(alias,description..' '..self.help,function(command_event) + commands.add_command(alias,{'expcore-commands.command-help',description,self.help},function(command_event) command_event.name = self.name local success, err = pcall(Commands.run_command,command_event) Commands.internal_error(success,self.name,err) diff --git a/expcore/common_parse.lua b/expcore/common_parse.lua index ffafe46f..5da9b68b 100644 --- a/expcore/common_parse.lua +++ b/expcore/common_parse.lua @@ -114,7 +114,7 @@ end) Commands.add_parse('player-alive',function(input,player,reject) local input_player = Commands.parse('player-online',input,player,reject) if not input_player then return end -- nil check - if not input_player.character or not input_player.character.health > 0 then + if not input_player.character or not input_player.character.health or input_player.character.health <= 0 then return reject{'expcore-commands.reject-player-alive'} else return input_player diff --git a/expcore/locale/en.cfg b/expcore/locale/en.cfg index 46b051e4..b33e7ee3 100644 --- a/expcore/locale/en.cfg +++ b/expcore/locale/en.cfg @@ -11,6 +11,7 @@ reject-force=Invaild Force Name reject-surface=Invaild surface Name invalid-inputs=Invalid Input, /__1__ __2__ invalid-param=Invalid Param "__1__"; __2__ +command-help=__1__ - __2__ command-ran=Command Complete command-fail=Command failed to run: __1__ command-error-log-format=[ERROR] command/__1__ :: __2__ \ No newline at end of file diff --git a/locale/en/commands-local.cfg b/locale/en/commands-local.cfg index 57a9a17a..dae5141f 100644 --- a/locale/en/commands-local.cfg +++ b/locale/en/commands-local.cfg @@ -1,3 +1,5 @@ [exp-commands] kill-already-dead=You are already dead. -admin-chat-format=[Admin Chat] [color=__3__]__1__: __2__ \ No newline at end of file +admin-chat-format=[Admin Chat] [color=__3__]__1__: __2__ +tp-no-position-found=No position to teleport to was found, please try again later. +tp-to-self=Player can not be teleported to them selfs. \ No newline at end of file diff --git a/locale/en/expcore.cfg b/locale/en/expcore.cfg index 46b051e4..b33e7ee3 100644 --- a/locale/en/expcore.cfg +++ b/locale/en/expcore.cfg @@ -11,6 +11,7 @@ reject-force=Invaild Force Name reject-surface=Invaild surface Name invalid-inputs=Invalid Input, /__1__ __2__ invalid-param=Invalid Param "__1__"; __2__ +command-help=__1__ - __2__ command-ran=Command Complete command-fail=Command failed to run: __1__ command-error-log-format=[ERROR] command/__1__ :: __2__ \ No newline at end of file diff --git a/modules/commands/admin-chat.lua b/modules/commands/admin-chat.lua index b7373ef9..ff0d82b1 100644 --- a/modules/commands/admin-chat.lua +++ b/modules/commands/admin-chat.lua @@ -2,7 +2,7 @@ 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) +:add_param('message',false) -- the message to send in the admin chat :enable_auto_concat() :add_tag('admin_only',true) :add_alias('ac') diff --git a/modules/commands/commands-local.cfg b/modules/commands/commands-local.cfg index 57a9a17a..dae5141f 100644 --- a/modules/commands/commands-local.cfg +++ b/modules/commands/commands-local.cfg @@ -1,3 +1,5 @@ [exp-commands] kill-already-dead=You are already dead. -admin-chat-format=[Admin Chat] [color=__3__]__1__: __2__ \ No newline at end of file +admin-chat-format=[Admin Chat] [color=__3__]__1__: __2__ +tp-no-position-found=No position to teleport to was found, please try again later. +tp-to-self=Player can not be teleported to them selfs. \ No newline at end of file diff --git a/modules/commands/kill.lua b/modules/commands/kill.lua index 486cf298..dd1c99b5 100644 --- a/modules/commands/kill.lua +++ b/modules/commands/kill.lua @@ -2,7 +2,7 @@ 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_param('player',true,'player-alive') -- the player to kill, must be alive to be valid :add_defaults{player=function(player) -- default is the player unless they are dead if player.character and player.character.health > 0 then diff --git a/modules/commands/me.lua b/modules/commands/me.lua index 43cd96b0..47c1285a 100644 --- a/modules/commands/me.lua +++ b/modules/commands/me.lua @@ -1,7 +1,7 @@ local Commands = require 'expcore.commands' Commands.new_command('me','Sends an action message in the chat') -:add_param('action',false) +:add_param('action',false) -- action that is done by the player, just text its meaningless :enable_auto_concat() :register(function(player,action,raw) game.print(string.format('* %s %s *',player.name,action),player.chat_color) diff --git a/modules/commands/tag.lua b/modules/commands/tag.lua index 3cffcd15..126ff5db 100644 --- a/modules/commands/tag.lua +++ b/modules/commands/tag.lua @@ -2,16 +2,16 @@ 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) +:add_param('tag',false,'string-max-length',20) -- new tag for your player max 20 char :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_param('player',true,'player') -- player to remove the tag of, nil to apply to self :add_defaults{player=function(player) - return player + return player -- default is the user using the command end} :register(function(player,action_player,raw) if action_player.index == player.index then diff --git a/modules/commands/teleport.lua b/modules/commands/teleport.lua new file mode 100644 index 00000000..cde35570 --- /dev/null +++ b/modules/commands/teleport.lua @@ -0,0 +1,55 @@ +local Commands = require 'expcore.commands' +require 'expcore.common_parse' + +local function teleport(from_player,to_player) + local surface = to_player.surface + local position = surface.find_non_colliding_position('player',to_player.position,32,1) + if not position then return false end -- return false if no new position + from_player.teleport(position,surface) + return true +end + +Commands.new_command('teleport','Teleports a player to another player.') +:add_param('from_player',false,'player-alive') -- player that will be teleported, must be alive +:add_param('to_player',false,'player-online') -- player to teleport to, must be online (if dead goes to where they died) +:add_alias('tp') +:add_tag('admin_only',true) +:register(function(player,from_player,to_player,raw) + if from_player.index == to_player.index then + -- return if attempting to teleport to self + return Commands.error{'exp-commands.tp-to-self'} + end + if not teleport(from_player,to_player) then + -- return if the teleport failed + return Commands.error{'exp-commands.tp-no-position-found'} + end +end) + +Commands.new_command('bring','Teleports a player to you.') +:add_param('player',false,'player-alive') -- player that will be teleported, must be alive +:add_tag('admin_only',true) +:register(function(player,from_player,raw) + if from_player.index == player.index then + -- return if attempting to teleport to self + return Commands.error{'exp-commands.tp-to-self'} + end + if not teleport(from_player,player) then + -- return if the teleport failed + return Commands.error{'exp-commands.tp-no-position-found'} + end +end) + +Commands.new_command('goto','Teleports you to a player.') +:add_param('player',false,'player-online') -- player to teleport to, must be online (if dead goes to where they died) +:add_alias('tp-me','tpme') +:add_tag('admin_only',true) +:register(function(player,to_player,raw) + if to_player.index == player.index then + -- return if attempting to teleport to self + return Commands.error{'exp-commands.tp-to-self'} + end + if not teleport(player,to_player) then + -- return if the teleport failed + return Commands.error{'exp-commands.tp-no-position-found'} + end +end) \ No newline at end of file