mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-27 11:35:22 +09:00
* Update admin-chat.lua * Update admin-markers.lua * Update artillery.lua * Update bot-queue.lua * Update cheat-mode.lua * Update clear-inventory.lua * Update connect.lua * Update debug.lua * Update enemy.lua * Update find.lua * Update friendly-fire.lua * Update help.lua * Update home.lua * Update interface.lua * Update jail.lua * Update kill.lua * Update last-location.lua * Update me.lua * Update pollution.lua * Update protection.lua * Update rainbow.lua * Update ratio.lua * Update repair.lua * Update reports.lua * Update research.lua * Update roles.lua * Update roles.lua * Update search.lua * Update spawn.lua * Update spectate.lua * Update speed.lua * Update surface-clearing.lua * Update teleport.lua * Update train.lua * Update vlayer.lua * Update warnings.lua * Update waterfill.lua * Update gui.cfg * Update gui.cfg * Update gui.cfg * Update commands.cfg * Update commands.cfg * Update commands.cfg * Update connect.lua * Update cheat-mode.lua * Update commands.cfg * Update commands.cfg * Update commands.cfg * Update commands.cfg * Update commands.cfg * Update commands.cfg * Update admin-chat.lua * Update admin-markers.lua * Update vlayer.lua * Update artillery.lua * Update bot-queue.lua * Update cheat-mode.lua * Update clear-inventory.lua * Update connect.lua * Update debug.lua * Update enemy.lua * Update find.lua * Update friendly-fire.lua * Update help.lua * Update home.lua * Update interface.lua * Update jail.lua * Update kill.lua * Update last-location.lua * Update me.lua * Update pollution.lua * Update protection.lua * Update rainbow.lua * Update ratio.lua * Update repair.lua * Update reports.lua * Update research.lua * Update roles.lua * Update search.lua * Update spawn.lua * Update spectate.lua * Update speed.lua * Update surface-clearing.lua * Update teleport.lua * Update train.lua * Update warnings.lua * Update waterfill.lua * Update gui.cfg * Update gui.cfg * Update gui.cfg * Update gui.cfg * Update gui.cfg * Update commands.cfg * Update commands.cfg * Update addons.cfg * Update addons.cfg * Update data.cfg * Update data.cfg * Update gui.cfg * Update gui.cfg * Update data.cfg * Update data.cfg * Update gui.cfg * Update gui.cfg * Update gui.cfg * Update gui.cfg * Update gui.cfg * Update gui.cfg * Update commands.lua * Update admin-chat.lua * Update admin-markers.lua * Update artillery.lua * Update bot-queue.lua * Update cheat-mode.lua * Update clear-inventory.lua * Update connect.lua * Update debug.lua * Update enemy.lua * Update find.lua * Update help.lua * Update interface.lua * Update home.lua * Update jail.lua * Update kill.lua * Update last-location.lua * Update me.lua * Update pollution.lua * Update protection.lua * Update rainbow.lua * Update ratio.lua * Update repair.lua * Update reports.lua * Update research.lua * Update roles.lua * Update search.lua * Update spawn.lua * Update spectate.lua * Update speed.lua * Update surface-clearing.lua * Update teleport.lua * Update train.lua * Update vlayer.lua * Update warnings.lua * Update waterfill.lua * Update commands.cfg * Update commands.cfg * Update enemy.lua * Update friendly-fire.lua * Update roles.lua * Update spectate.lua * Update spectate.lua
84 lines
2.6 KiB
Lua
84 lines
2.6 KiB
Lua
--[[-- Commands Module - Home
|
|
- Adds a command that allows setting and teleporting to your home position
|
|
@commands Home
|
|
]]
|
|
|
|
local Commands = require 'expcore.commands' --- @dep expcore.commands
|
|
local Global = require 'utils.global' --- @dep utils.global
|
|
require 'config.expcore.command_general_parse'
|
|
|
|
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
|
|
|
|
--- Teleports you to your home location
|
|
-- @command home
|
|
Commands.new_command('home', {'expcom-home.description-home'}, 'Teleports you to your home location')
|
|
:register(function(player)
|
|
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)
|
|
|
|
--- Sets your home location to your current position
|
|
-- @command home-set
|
|
Commands.new_command('home-set', {'expcom-home.description-home-set'}, 'Sets your home location to your current position')
|
|
:register(function(player)
|
|
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)
|
|
|
|
--- Returns your current home location
|
|
-- @command home-get
|
|
Commands.new_command('home-get', {'expcom-home.description-home-get'}, 'Returns your current home location')
|
|
:register(function(player)
|
|
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)
|
|
|
|
--- Teleports you to previous location
|
|
-- @command return
|
|
Commands.new_command('return', {'expcom-home.description-return'}, 'Teleports you to previous location')
|
|
:register(function(player)
|
|
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)
|