From 36be279748196f42bdc73189b2cbd2eb4eb80574 Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Sun, 24 Jun 2018 21:26:50 +0100 Subject: [PATCH] Added ExpGamingCommands.home --- modules/ExpGamingCommands/home/control.lua | 35 +++++++++++++++++++ modules/ExpGamingCommands/home/softmod.json | 22 ++++++++++++ to convert/Addons/Commands/home.lua | 37 --------------------- 3 files changed, 57 insertions(+), 37 deletions(-) create mode 100644 modules/ExpGamingCommands/home/control.lua create mode 100644 modules/ExpGamingCommands/home/softmod.json delete mode 100644 to convert/Addons/Commands/home.lua diff --git a/modules/ExpGamingCommands/home/control.lua b/modules/ExpGamingCommands/home/control.lua new file mode 100644 index 00000000..95238d8b --- /dev/null +++ b/modules/ExpGamingCommands/home/control.lua @@ -0,0 +1,35 @@ +--- A full ranking system for factorio. +-- @module ExpGamingCommands.kill +-- @author Cooldude2606 +-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE + +local Game = require('FactorioStdLib.Game') +local global = global{} + +--- Sets the home for a player +-- @command set-home +commands.add_command('set-home', 'Set your home position', {}, function(event,args) + local player = Game.get_player(event) + if not global[player.index] then global[player.index] = {player.force.get_spawn_position(player.surface),player.force.get_spawn_position(player.surface)} end + global[player.index][1] = {math.floor(player.position.x),math.floor(player.position.y)} + player_return('Home set at: ('..math.floor(player.position.x)..','..math.floor(player.position.y)..')') +end) + +--- Teleports a player back to their home +-- @command home +commands.add_command('home', 'Go to you home position', {}, function(event,args) + local player = Game.get_player(event) + if not global[player.index] then global[player.index] = {player.force.get_spawn_position(player.surface),player.force.get_spawn_position(player.surface)} end + global[player.index][2] = {math.floor(player.position.x),math.floor(player.position.y)} + player.teleport(player.surface.find_non_colliding_position('player',global[player.index][1],32,1),player.surface) +end) + +--- Returns a player back to the place before using /home +-- @command return +commands.add_command('return', 'Return to your previous position after using /home', {}, function(event,args) + local player = Game.get_player(event) + if not global[player.index] then global[player.index] = {player.force.get_spawn_position(player.surface),player.force.get_spawn_position(player.surface)} end + local _temp = {math.floor(player.position.x),math.floor(player.position.y)} + player.teleport(player.surface.find_non_colliding_position('player',global[player.index][2],32,1),player.surface) + global[player.index][2] = _temp +end) diff --git a/modules/ExpGamingCommands/home/softmod.json b/modules/ExpGamingCommands/home/softmod.json new file mode 100644 index 00000000..59060372 --- /dev/null +++ b/modules/ExpGamingCommands/home/softmod.json @@ -0,0 +1,22 @@ +{ + "name": "home", + "version": "4.0.0", + "type": "Module", + "description": "Allows players to set homes and then return to them later.", + "location": "", + "keywords": [ + "Teleport", + "ExpGaming", + "Home", + "Return", + "Set Home", + "Commands" + ], + "author": "", + "contact": "", + "license": "", + "dependencies": { + "FactorioStdLib.Game": "^0.8.0", + "ExpGamingCore.Commands": "^4.0.0" + } +} \ No newline at end of file diff --git a/to convert/Addons/Commands/home.lua b/to convert/Addons/Commands/home.lua deleted file mode 100644 index 5f7d92d8..00000000 --- a/to convert/Addons/Commands/home.lua +++ /dev/null @@ -1,37 +0,0 @@ ---[[ -Explosive Gaming - -This file can be used with permission but this and the credit below must remain in the file. -Contact a member of management on our discord to seek permission to use our code. -Any changes that you may make to the code are yours but that does not make the script yours. -Discord: https://discord.gg/r6dC2uK -]] ---Please Only Edit Below This Line----------------------------------------------------------- - -local function _homes(reset) - global.addons = not reset and global.addons or {} - global.addons.homes = not reset and global.addons.homes or {} - return global.addons.homes -end - -commands.add_command('set-home', 'Set your home position', {}, function(event,args) - local player = Game.get_player(event) - if not _homes()[player.index] then _homes()[player.index] = {player.force.get_spawn_position(player.surface),player.force.get_spawn_position(player.surface)} end - _homes()[player.index][1] = {math.floor(player.position.x),math.floor(player.position.y)} - player_return('Home set at: ('..math.floor(player.position.x)..','..math.floor(player.position.y)..')') -end) - -commands.add_command('home', 'Go to you home position', {}, function(event,args) - local player = Game.get_player(event) - if not _homes()[player.index] then _homes()[player.index] = {player.force.get_spawn_position(player.surface),player.force.get_spawn_position(player.surface)} end - _homes()[player.index][2] = {math.floor(player.position.x),math.floor(player.position.y)} - player.teleport(player.surface.find_non_colliding_position('player',_homes()[player.index][1],32,1),player.surface) -end) - -commands.add_command('return', 'Return to your previous position after using /home', {}, function(event,args) - local player = Game.get_player(event) - if not _homes()[player.index] then _homes()[player.index] = {player.force.get_spawn_position(player.surface),player.force.get_spawn_position(player.surface)} end - local _temp = {math.floor(player.position.x),math.floor(player.position.y)} - player.teleport(player.surface.find_non_colliding_position('player',_homes()[player.index][2],32,1),player.surface) - _homes()[player.index][2] = _temp -end)