From 95ef808341b9eb9e252240295783d4b21bb48f3a Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Wed, 12 Jun 2019 22:36:59 +0100 Subject: [PATCH 1/2] Added home command --- config/_file_loader.lua | 1 + config/roles.lua | 8 +++++ locale/en/commands.cfg | 9 ++++- modules/commands/home.lua | 70 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 modules/commands/home.lua diff --git a/config/_file_loader.lua b/config/_file_loader.lua index f30d0368..3dc92dae 100644 --- a/config/_file_loader.lua +++ b/config/_file_loader.lua @@ -24,6 +24,7 @@ return { 'modules.commands.warnings', 'modules.commands.find', 'modules.commands.bonus', + 'modules.commands.home', -- QoL Addons 'modules.addons.chat-popups', 'modules.addons.damage-popups', diff --git a/config/roles.lua b/config/roles.lua index c51e7d0e..19c3fa2e 100644 --- a/config/roles.lua +++ b/config/roles.lua @@ -82,6 +82,10 @@ Roles.new_role('Moderator','Mod') 'command/clear-temp-ban', 'command/clear-inventory', 'command/bonus', + 'command/home', + 'command/home-set', + 'command/home-get', + 'command/return', 'gui/rocket-info/toggle-active', 'gui/rocket-info/remote_launch', } @@ -128,6 +132,10 @@ Roles.new_role('Pay to Win','P2W') 'gui/rocket-info/toggle-active', 'gui/rocket-info/remote_launch', 'command/bonus', + 'command/home', + 'command/home-set', + 'command/home-get', + 'command/return', } Roles.new_role('Donator','Don') diff --git a/locale/en/commands.cfg b/locale/en/commands.cfg index 12812c63..3e218eca 100644 --- a/locale/en/commands.cfg +++ b/locale/en/commands.cfg @@ -53,4 +53,11 @@ cleared=__1__ had all they warnings cleared by __2__. unavailable=They was a problem getting you to spawn, please try again later. [expcom-repair] -result=__1__ entites were revived and __2__ were healed to max health. \ No newline at end of file +result=__1__ entites were revived and __2__ were healed to max health. + +[expcom-home] +no-home=You have no home set. +no-return=You cant return when home has not yet been used. +home-set=Your home point has been set to x: __1__ y: __2__ +return-set=Your return point has been set to x: __1__ y: __2__ +home-get=Your home point is at x: __1__ y: __2__ \ No newline at end of file diff --git a/modules/commands/home.lua b/modules/commands/home.lua new file mode 100644 index 00000000..be733517 --- /dev/null +++ b/modules/commands/home.lua @@ -0,0 +1,70 @@ +local Commands = require 'expcore.commands' +local Global = require 'utils.global' +require 'config.expcore-commands.parse_general' + +local homes = {} +Global.register(homes,function(tbl) + homes = tbl +end) + +local function teleport(player,position) + local surface = player.surface + local pos = surface.find_non_colliding_position('character',position,32,1) + if not position then return false end + if player.driving then player.driving = false end -- kicks a player out a vehicle if in one + player.teleport(pos,surface) + return true +end + +local function floor_pos(position) + return { + x=math.floor(position.x), + y=math.floor(position.y) + } +end + +Commands.new_command('home','Teleports you to your home location') +:register(function(player,raw) + local home = homes[player.index] + if not home or not home[1] then + return Commands.error{'expcom-home.no-home'} + end + local rtn = floor_pos(player.position) + teleport(player,home[1]) + home[2] = rtn + Commands.print{'expcom-home.return-set',rtn.x,rtn.y} +end) + +Commands.new_command('home-set','Sets your home location to your current position') +:register(function(player,raw) + local home = homes[player.index] + if not home then + home = {} + homes[player.index] = home + end + local pos = floor_pos(player.position) + home[1] = pos + Commands.print{'expcom-home.home-set',pos.x,pos.y} +end) + +Commands.new_command('home-get','Returns your current home location') +:register(function(player,raw) + local home = homes[player.index] + if not home or not home[1] then + return Commands.error{'expcom-home.no-home'} + end + local pos = home[1] + Commands.print{'expcom-home.home-get',pos.x,pos.y} +end) + +Commands.new_command('return','Teleports you to previous location') +:register(function(player,raw) + local home = homes[player.index] + if not home or not home[2] then + return Commands.error{'expcom-home.no-return'} + end + local rtn = floor_pos(player.position) + teleport(player,home[2]) + home[2] = rtn + Commands.print{'expcom-home.return-set',rtn.x,rtn.y} +end) \ No newline at end of file From 18d42461629a4deefe15b2a854abca7bb11532cb Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Wed, 12 Jun 2019 22:37:45 +0100 Subject: [PATCH 2/2] Moved files to done --- old/modules/{ => DONE/Commands}/ExpGamingCommands/softmod.json | 0 old/modules/{ExpGamingCommands => DONE/Commands}/home/control.lua | 0 .../{ExpGamingCommands => DONE/Commands}/home/locale/en.cfg | 0 .../{ExpGamingCommands => DONE/Commands}/home/softmod.json | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename old/modules/{ => DONE/Commands}/ExpGamingCommands/softmod.json (100%) rename old/modules/{ExpGamingCommands => DONE/Commands}/home/control.lua (100%) rename old/modules/{ExpGamingCommands => DONE/Commands}/home/locale/en.cfg (100%) rename old/modules/{ExpGamingCommands => DONE/Commands}/home/softmod.json (100%) diff --git a/old/modules/ExpGamingCommands/softmod.json b/old/modules/DONE/Commands/ExpGamingCommands/softmod.json similarity index 100% rename from old/modules/ExpGamingCommands/softmod.json rename to old/modules/DONE/Commands/ExpGamingCommands/softmod.json diff --git a/old/modules/ExpGamingCommands/home/control.lua b/old/modules/DONE/Commands/home/control.lua similarity index 100% rename from old/modules/ExpGamingCommands/home/control.lua rename to old/modules/DONE/Commands/home/control.lua diff --git a/old/modules/ExpGamingCommands/home/locale/en.cfg b/old/modules/DONE/Commands/home/locale/en.cfg similarity index 100% rename from old/modules/ExpGamingCommands/home/locale/en.cfg rename to old/modules/DONE/Commands/home/locale/en.cfg diff --git a/old/modules/ExpGamingCommands/home/softmod.json b/old/modules/DONE/Commands/home/softmod.json similarity index 100% rename from old/modules/ExpGamingCommands/home/softmod.json rename to old/modules/DONE/Commands/home/softmod.json