2019-07-08 20:23:57 -05:00
|
|
|
--[[
|
2019-07-17 18:04:52 -05:00
|
|
|
Copyright (C) 2015-2019 Michael Tomaino (PlatinumArts@gmail.com)
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with this library; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
|
|
|
USA
|
|
|
|
|
|
|
|
----------------------------------------------------------------------------
|
|
|
|
|
2019-07-08 20:23:57 -05:00
|
|
|
Originally made by Traxie21 and released with the WTFPL license.
|
2019-07-17 18:04:52 -05:00
|
|
|
Forum link: https://forum.minetest.net/viewtopic.php?id=4457
|
|
|
|
|
|
|
|
Updates by Zeno, Panquesito7 and ChaosWormz.
|
|
|
|
License: LGPL-2.1
|
|
|
|
|
|
|
|
Optional dependencies: areas, intllib
|
2019-07-08 20:23:57 -05:00
|
|
|
New release by RobbieF under new mod: tps_teleport - http://blog.minetest.tv/teleport-request/
|
|
|
|
--]]
|
2014-07-26 09:20:32 +03:00
|
|
|
|
2019-07-17 18:04:52 -05:00
|
|
|
-- Enable configuration
|
|
|
|
enable_configuration = false
|
|
|
|
|
2019-07-15 13:52:31 -05:00
|
|
|
-- Load support for intllib.
|
|
|
|
local MP = minetest.get_modpath(minetest.get_current_modname())
|
|
|
|
local S, NS = dofile(MP.."/intllib.lua")
|
|
|
|
|
2019-07-17 18:04:52 -05:00
|
|
|
-- Load configuration.
|
|
|
|
if enable_configuration then
|
|
|
|
dofile(MP.."/config.lua")
|
|
|
|
end
|
|
|
|
|
2014-07-30 16:40:10 +10:00
|
|
|
local timeout_delay = 60
|
2014-07-26 09:20:32 +03:00
|
|
|
|
2016-05-18 18:47:49 -04:00
|
|
|
local version = "1.5"
|
2014-07-26 09:20:32 +03:00
|
|
|
|
2014-07-30 12:30:37 +10:00
|
|
|
local tpr_list = {}
|
|
|
|
local tphr_list = {}
|
2014-07-26 09:20:32 +03:00
|
|
|
|
2019-03-24 15:38:32 +00:00
|
|
|
local map_size = 30912
|
|
|
|
local function can_teleport(to)
|
|
|
|
return to.x < map_size and to.x > -map_size and to.y < map_size and to.y > -map_size and to.z < map_size and to.z > -map_size
|
|
|
|
end
|
|
|
|
|
2019-07-08 20:23:57 -05:00
|
|
|
minetest.register_privilege("tp", {
|
2019-07-15 13:52:31 -05:00
|
|
|
description = S("Let players teleport to other players (request will be sent)"),
|
2019-07-08 20:23:57 -05:00
|
|
|
give_to_singleplayer = false,
|
|
|
|
give_to_admin = true,
|
|
|
|
})
|
|
|
|
|
2016-05-17 13:15:48 -04:00
|
|
|
minetest.register_privilege("tp_admin", {
|
2019-07-15 13:52:31 -05:00
|
|
|
description = S("Gives full admin-access to a player."),
|
2019-07-08 20:23:57 -05:00
|
|
|
give_to_singleplayer = false,
|
|
|
|
give_to_admin = true,
|
2016-05-17 13:15:48 -04:00
|
|
|
})
|
|
|
|
minetest.register_privilege("tp_tpc", {
|
2019-07-15 13:52:31 -05:00
|
|
|
description = S("Allow player to teleport to coordinates (if allowed by area protection)"),
|
2019-07-08 20:23:57 -05:00
|
|
|
give_to_singleplayer = true,
|
|
|
|
give_to_admin = true,
|
2016-05-17 13:15:48 -04:00
|
|
|
})
|
2016-05-13 08:35:20 -04:00
|
|
|
|
2016-05-13 13:41:44 -04:00
|
|
|
local function find_free_position_near(pos)
|
|
|
|
local tries = {
|
|
|
|
{x=1,y=0,z=0},
|
|
|
|
{x=-1,y=0,z=0},
|
|
|
|
{x=0,y=0,z=1},
|
|
|
|
{x=0,y=0,z=-1},
|
|
|
|
}
|
|
|
|
for _,d in pairs(tries) do
|
|
|
|
local p = vector.add(pos, d)
|
|
|
|
if not minetest.registered_nodes[minetest.get_node(p).name].walkable then
|
|
|
|
return p, true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return pos, false
|
|
|
|
end
|
|
|
|
|
2016-05-13 14:59:32 -04:00
|
|
|
local function parti(pos)
|
|
|
|
minetest.add_particlespawner(50, 0.4,
|
|
|
|
{x=pos.x + 0.5, y=pos.y, z=pos.z + 0.5}, {x=pos.x - 0.5, y=pos.y, z=pos.z - 0.5},
|
|
|
|
{x=0, y=5, z=0}, {x=0, y=0, z=0},
|
|
|
|
{x=0, y=5, z=0}, {x=0, y=0, z=0},
|
|
|
|
3, 5,
|
|
|
|
3, 5,
|
|
|
|
false,
|
|
|
|
"tps_portal_parti.png")
|
|
|
|
end
|
|
|
|
|
|
|
|
local function parti2(pos)
|
|
|
|
minetest.add_particlespawner(50, 0.4,
|
|
|
|
{x=pos.x + 0.5, y=pos.y + 10, z=pos.z + 0.5}, {x=pos.x - 0.5, y=pos.y, z=pos.z - 0.5},
|
|
|
|
{x=0, y=-5, z=0}, {x=0, y=0, z=0},
|
|
|
|
{x=0, y=-5, z=0}, {x=0, y=0, z=0},
|
|
|
|
3, 5,
|
|
|
|
3, 5,
|
|
|
|
false,
|
|
|
|
"tps_portal_parti.png")
|
|
|
|
end
|
|
|
|
|
2019-07-08 20:23:57 -05:00
|
|
|
-- Teleport Request System
|
|
|
|
function tpr_send(sender, receiver)
|
|
|
|
if minetest.check_player_privs(sender, {tp_admin = true}) then
|
|
|
|
-- Write name values to list and clear old values.
|
|
|
|
tpr_list[receiver] = sender
|
|
|
|
-- Teleport timeout delay
|
|
|
|
minetest.after(timeout_delay, function(name)
|
|
|
|
if tpr_list[name] then
|
|
|
|
tpr_list[name] = nil
|
|
|
|
end
|
|
|
|
end, sender)
|
2019-07-14 20:04:30 -05:00
|
|
|
if receiver == "" then
|
2019-07-15 13:52:31 -05:00
|
|
|
minetest.chat_send_player(sender, S("Usage: /tpr <Player name>"))
|
2019-07-14 20:04:30 -05:00
|
|
|
return
|
|
|
|
end
|
|
|
|
if not minetest.get_player_by_name(receiver) then
|
2019-07-15 13:52:31 -05:00
|
|
|
minetest.chat_send_player(sender, S("There is no player by that name. Keep in mind this is case-sensitive, and the player must be online"))
|
2019-07-14 20:04:30 -05:00
|
|
|
return
|
|
|
|
end
|
2019-07-08 20:23:57 -05:00
|
|
|
tpr_accept(receiver)
|
2019-07-15 13:52:31 -05:00
|
|
|
minetest.chat_send_player(sender, S("You are teleporting to @1.", receiver))
|
2019-07-08 20:23:57 -05:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2014-07-30 12:15:08 +10:00
|
|
|
if receiver == "" then
|
2019-07-15 13:52:31 -05:00
|
|
|
minetest.chat_send_player(sender, S("Usage: /tpr <Player name>"))
|
2014-07-30 12:15:08 +10:00
|
|
|
return
|
|
|
|
end
|
2014-07-26 09:20:32 +03:00
|
|
|
|
2015-08-28 22:08:16 +02:00
|
|
|
if not minetest.get_player_by_name(receiver) then
|
2019-07-15 13:52:31 -05:00
|
|
|
minetest.chat_send_player(sender, S("There is no player by that name. Keep in mind this is case-sensitive, and the player must be online."))
|
2015-08-28 22:08:16 +02:00
|
|
|
return
|
2014-07-30 12:15:08 +10:00
|
|
|
end
|
2014-07-26 09:20:32 +03:00
|
|
|
|
2019-07-15 13:52:31 -05:00
|
|
|
minetest.chat_send_player(receiver, S("@1 is requesting to teleport to you. /tpy to accept", sender))
|
|
|
|
minetest.chat_send_player(sender, S("Teleport request sent! It will timeout in @1 seconds", timeout_delay))
|
2014-07-26 09:20:32 +03:00
|
|
|
|
2019-07-08 20:23:57 -05:00
|
|
|
-- Write name values to list and clear old values.
|
|
|
|
if not minetest.check_player_privs(sender, {tp_admin = true}) then
|
2015-08-28 22:08:16 +02:00
|
|
|
tpr_list[receiver] = sender
|
2019-07-08 20:23:57 -05:00
|
|
|
-- Teleport timeout delay
|
2015-08-28 22:08:16 +02:00
|
|
|
minetest.after(timeout_delay, function(name)
|
|
|
|
if tpr_list[name] then
|
|
|
|
tpr_list[name] = nil
|
|
|
|
end
|
|
|
|
end, sender)
|
2019-07-08 20:23:57 -05:00
|
|
|
end
|
2015-08-28 22:08:16 +02:00
|
|
|
end
|
2014-07-30 14:01:44 +10:00
|
|
|
|
2019-07-08 20:23:57 -05:00
|
|
|
function tphr_send(sender, receiver)
|
|
|
|
if minetest.check_player_privs(sender, {tp_admin = true}) then
|
|
|
|
-- Write name values to list and clear old values.
|
|
|
|
tphr_list[receiver] = sender
|
|
|
|
-- Teleport timeout delay
|
|
|
|
minetest.after(timeout_delay, function(name)
|
|
|
|
if tphr_list[name] then
|
|
|
|
tphr_list[name] = nil
|
|
|
|
end
|
|
|
|
end, sender)
|
2019-07-14 20:04:30 -05:00
|
|
|
if receiver == "" then
|
2019-07-15 13:52:31 -05:00
|
|
|
minetest.chat_send_player(sender, S("Usage: /tphr <Player name>"))
|
2019-07-14 20:04:30 -05:00
|
|
|
return
|
|
|
|
end
|
|
|
|
if not minetest.get_player_by_name(receiver) then
|
2019-07-15 13:52:31 -05:00
|
|
|
minetest.chat_send_player(sender, S("There is no player by that name. Keep in mind this is case-sensitive, and the player must be online"))
|
2019-07-14 20:04:30 -05:00
|
|
|
return
|
|
|
|
end
|
2019-07-08 20:23:57 -05:00
|
|
|
tpr_accept(receiver)
|
2019-07-15 13:52:31 -05:00
|
|
|
minetest.chat_send_player(sender, S("@1 is teleporting to you.", receiver))
|
2019-07-08 20:23:57 -05:00
|
|
|
return
|
|
|
|
end
|
2014-07-30 14:05:03 +10:00
|
|
|
if receiver == "" then
|
2019-07-15 13:52:31 -05:00
|
|
|
minetest.chat_send_player(sender, S("Usage: /tphr <Player name>"))
|
2014-07-30 12:15:08 +10:00
|
|
|
return
|
|
|
|
end
|
2014-07-26 09:20:32 +03:00
|
|
|
|
2015-08-28 22:08:16 +02:00
|
|
|
if not minetest.get_player_by_name(receiver) then
|
2019-07-15 13:52:31 -05:00
|
|
|
minetest.chat_send_player(sender, S("There is no player by that name. Keep in mind this is case-sensitive, and the player must be online."))
|
2015-08-28 22:08:16 +02:00
|
|
|
return
|
2014-07-30 12:15:08 +10:00
|
|
|
end
|
2015-08-28 22:08:16 +02:00
|
|
|
|
2019-07-15 13:52:31 -05:00
|
|
|
minetest.chat_send_player(receiver, S("@1 is requesting that you teleport to them. /tpy to accept; /tpn to deny", sender))
|
|
|
|
minetest.chat_send_player(sender, S("Teleport request sent! It will timeout in @1 seconds ", timeout_delay))
|
2015-08-28 22:08:16 +02:00
|
|
|
|
2019-07-08 20:23:57 -05:00
|
|
|
-- Write name values to list and clear old values.
|
|
|
|
if not minetest.check_player_privs(sender, {tp_admin = true}) then
|
2015-08-28 22:08:16 +02:00
|
|
|
tphr_list[receiver] = sender
|
2019-07-08 20:23:57 -05:00
|
|
|
-- Teleport timeout delay
|
2015-08-28 22:08:16 +02:00
|
|
|
minetest.after(timeout_delay, function(name)
|
|
|
|
if tphr_list[name] then
|
|
|
|
tphr_list[name] = nil
|
|
|
|
end
|
|
|
|
end, sender)
|
2019-07-08 20:23:57 -05:00
|
|
|
end
|
2014-07-26 09:20:32 +03:00
|
|
|
end
|
|
|
|
|
2019-07-11 20:50:48 -05:00
|
|
|
function tpc_send(player, coordinates)
|
2016-05-10 11:11:31 -04:00
|
|
|
|
2019-07-08 20:23:57 -05:00
|
|
|
local posx,posy,posz = string.match(coordinates, "^(-?%d+), (-?%d+), (-?%d+)$")
|
2016-05-10 13:42:17 -04:00
|
|
|
local pname = minetest.get_player_by_name(player)
|
|
|
|
|
2016-05-10 13:58:24 -04:00
|
|
|
if posx ~= nil or posy ~= nil or posz ~= nil then
|
|
|
|
posx = tonumber(posx) + 0.0
|
|
|
|
posy = tonumber(posy) + 0.0
|
|
|
|
posz = tonumber(posz) + 0.0
|
|
|
|
end
|
2016-05-10 11:11:31 -04:00
|
|
|
|
2016-05-10 14:20:28 -04:00
|
|
|
if posx==nil or posy==nil or posz==nil or string.len(posx) > 6 or string.len(posy) > 6 or string.len(posz) > 6 then
|
2019-07-15 13:52:31 -05:00
|
|
|
minetest.chat_send_player(player, S("Usage: /tpc <x, y, z>"))
|
2016-05-10 14:20:28 -04:00
|
|
|
return nil
|
|
|
|
end
|
2016-05-10 13:42:17 -04:00
|
|
|
|
2019-07-11 20:59:46 -05:00
|
|
|
local target_coords = {x=posx, y=posy, z=posz}
|
2016-05-10 13:42:17 -04:00
|
|
|
|
2019-03-24 15:38:32 +00:00
|
|
|
if can_teleport(target_coords) == false then
|
2019-07-15 13:52:31 -05:00
|
|
|
minetest.chat_send_player(player, S("You cannot teleport to a location outside the map!"))
|
2019-03-24 15:38:32 +00:00
|
|
|
return nil
|
|
|
|
end
|
|
|
|
|
2016-05-10 11:11:31 -04:00
|
|
|
-- If the area is protected, reject the user's request to teleport to these coordinates
|
|
|
|
-- In future release we'll actually query the player who owns the area, if they're online, and ask for their permission.
|
2016-05-13 13:12:11 -04:00
|
|
|
-- Admin user (priv "tp_admin") overrides all protection
|
|
|
|
if minetest.check_player_privs(pname, {tp_admin=true}) then
|
2019-07-15 13:52:31 -05:00
|
|
|
minetest.chat_send_player(player, S("Teleporting to: @1, @2, @3", posx, posy, posz))
|
2019-07-08 20:23:57 -05:00
|
|
|
pname:set_pos(find_free_position_near(target_coords))
|
2016-05-13 17:52:39 -04:00
|
|
|
minetest.sound_play("whoosh", {pos = target_coords, gain = 0.5, max_hear_distance = 10})
|
2017-01-24 10:12:42 +02:00
|
|
|
--parti2(target_coords)
|
2016-05-13 13:12:11 -04:00
|
|
|
else
|
2019-07-11 20:59:46 -05:00
|
|
|
if minetest.check_player_privs(pname, {tp_tpc = true}) then
|
2016-05-17 13:15:48 -04:00
|
|
|
local protected = minetest.is_protected(target_coords,pname)
|
2019-07-11 20:59:46 -05:00
|
|
|
if protected and minetest.get_modpath("areas") then
|
|
|
|
if not areas:canInteract(target_coords, player) then
|
|
|
|
local owners = areas:getNodeOwners(target_coords)
|
2019-07-15 13:52:31 -05:00
|
|
|
minetest.chat_send_player(player, S("Error: @1 is protected by @2.", minetest.pos_to_string(target_coords), table.concat(owners, ", ")))
|
2019-07-11 20:59:46 -05:00
|
|
|
return
|
|
|
|
end
|
2016-05-13 13:12:11 -04:00
|
|
|
end
|
2019-07-15 13:52:31 -05:00
|
|
|
minetest.chat_send_player(player, S("Teleporting to: @1, @2, @3", posx, posy, posz))
|
2019-07-08 20:23:57 -05:00
|
|
|
pname:set_pos(find_free_position_near(target_coords))
|
2016-05-17 13:15:48 -04:00
|
|
|
minetest.sound_play("whoosh", {pos = target_coords, gain = 0.5, max_hear_distance = 10})
|
2017-01-24 10:12:42 +02:00
|
|
|
--parti2(target_coords)
|
2016-05-17 13:15:48 -04:00
|
|
|
else
|
2019-07-15 13:52:31 -05:00
|
|
|
minetest.chat_send_player(player, S("Error: You do not have permission to teleport to coordinates."))
|
2016-05-17 13:15:48 -04:00
|
|
|
return
|
2016-05-13 13:12:11 -04:00
|
|
|
end
|
|
|
|
end
|
2016-05-10 11:11:31 -04:00
|
|
|
end
|
|
|
|
|
2019-07-11 20:43:42 -05:00
|
|
|
function tpr_deny(name)
|
2015-08-28 22:08:16 +02:00
|
|
|
if tpr_list[name] then
|
2019-07-15 13:52:31 -05:00
|
|
|
minetest.chat_send_player(tpr_list[name], S("Teleport request denied."))
|
2014-07-30 16:56:20 +10:00
|
|
|
tpr_list[name] = nil
|
2014-07-26 09:20:32 +03:00
|
|
|
end
|
2015-08-28 22:08:16 +02:00
|
|
|
if tphr_list[name] then
|
2019-07-15 13:52:31 -05:00
|
|
|
minetest.chat_send_player(tphr_list[name], S("Teleport request denied."))
|
2014-07-30 16:56:20 +10:00
|
|
|
tphr_list[name] = nil
|
2014-07-26 09:20:32 +03:00
|
|
|
end
|
|
|
|
end
|
2014-07-30 12:30:37 +10:00
|
|
|
|
2019-07-11 20:43:42 -05:00
|
|
|
-- Teleport Accept Systems
|
|
|
|
function tpr_accept(name, param)
|
2019-07-08 20:23:57 -05:00
|
|
|
-- Check to prevent constant teleporting.
|
2015-08-28 22:08:16 +02:00
|
|
|
if not tpr_list[name]
|
|
|
|
and not tphr_list[name] then
|
2019-07-15 13:52:31 -05:00
|
|
|
minetest.chat_send_player(name, S("Usage: /tpy allows you to accept teleport requests sent to you by other players"))
|
2014-07-26 09:20:32 +03:00
|
|
|
return
|
|
|
|
end
|
2014-07-30 12:15:08 +10:00
|
|
|
|
2015-08-28 22:08:16 +02:00
|
|
|
local chatmsg, source, target, name2
|
2014-07-30 12:15:08 +10:00
|
|
|
|
2014-07-26 09:20:32 +03:00
|
|
|
if tpr_list[name] then
|
2014-07-30 14:01:44 +10:00
|
|
|
name2 = tpr_list[name]
|
2014-12-09 13:03:30 +10:00
|
|
|
source = minetest.get_player_by_name(name)
|
|
|
|
target = minetest.get_player_by_name(name2)
|
2019-07-15 13:52:31 -05:00
|
|
|
chatmsg = S("@1 is teleporting to you.", name2)
|
2014-07-26 09:20:32 +03:00
|
|
|
tpr_list[name] = nil
|
2014-07-30 14:01:44 +10:00
|
|
|
elseif tphr_list[name] then
|
|
|
|
name2 = tphr_list[name]
|
2014-12-09 13:03:30 +10:00
|
|
|
source = minetest.get_player_by_name(name2)
|
|
|
|
target = minetest.get_player_by_name(name)
|
2019-07-15 13:52:31 -05:00
|
|
|
chatmsg = S("You are teleporting to @1.", name2)
|
2014-07-30 14:01:44 +10:00
|
|
|
tphr_list[name] = nil
|
|
|
|
else
|
2014-07-26 09:20:32 +03:00
|
|
|
return
|
|
|
|
end
|
2014-07-30 12:15:08 +10:00
|
|
|
|
2014-07-30 14:01:44 +10:00
|
|
|
-- Could happen if either player disconnects (or timeout); if so just abort
|
2015-08-28 22:08:16 +02:00
|
|
|
if not source
|
|
|
|
or not target then
|
2014-07-26 09:20:32 +03:00
|
|
|
return
|
|
|
|
end
|
2014-07-30 14:01:44 +10:00
|
|
|
|
2019-07-15 13:52:31 -05:00
|
|
|
minetest.chat_send_player(name2, S("Request Accepted!"))
|
2014-07-30 14:01:44 +10:00
|
|
|
minetest.chat_send_player(name, chatmsg)
|
2016-05-13 18:08:55 -04:00
|
|
|
|
2019-07-11 20:50:48 -05:00
|
|
|
local target_coords = source:get_pos()
|
2019-07-08 20:23:57 -05:00
|
|
|
target:set_pos(find_free_position_near(target_coords))
|
2016-05-13 18:08:55 -04:00
|
|
|
minetest.sound_play("whoosh", {pos = target_coords, gain = 0.5, max_hear_distance = 10})
|
2017-01-24 10:12:42 +02:00
|
|
|
--parti2(target_coords)
|
2014-07-26 09:20:32 +03:00
|
|
|
end
|
|
|
|
|
2016-05-18 07:40:42 -04:00
|
|
|
-- Teleport Jump - Relative Position Teleportation by number of nodes
|
2019-07-11 20:50:48 -05:00
|
|
|
function tpj(player, param)
|
2016-05-18 07:40:42 -04:00
|
|
|
local pname = minetest.get_player_by_name(player)
|
2016-05-18 18:47:49 -04:00
|
|
|
|
2016-05-18 07:40:42 -04:00
|
|
|
if param == "" then
|
2019-07-15 13:52:31 -05:00
|
|
|
minetest.chat_send_player(player, S("Usage: <x|y|z> <Number>"))
|
2016-05-18 07:40:42 -04:00
|
|
|
return false
|
|
|
|
end
|
2016-05-18 18:47:49 -04:00
|
|
|
|
2016-05-18 17:17:05 -04:00
|
|
|
local args = param:split(" ") -- look into this. Can it crash if the player does not have two parameters?
|
2016-05-18 07:40:42 -04:00
|
|
|
if #args < 2 then
|
2019-07-15 13:52:31 -05:00
|
|
|
minetest.chat_send_player(player, S("Usage: <x|y|z> <Number>"))
|
2016-05-18 07:40:42 -04:00
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
|
|
|
if not tonumber(args[2]) then
|
|
|
|
return false, "Not a Number!"
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Initially generate the target coords from the player's current position (since it's relative) and then perform the math.
|
2019-07-12 19:30:51 -05:00
|
|
|
local target_coords = minetest.get_player_by_name(player):get_pos()
|
2016-05-18 07:40:42 -04:00
|
|
|
if args[1] == "x" then
|
|
|
|
target_coords["x"] = target_coords["x"] + tonumber(args[2])
|
|
|
|
elseif args[1] == "y" then
|
|
|
|
target_coords["y"] = target_coords["y"] + tonumber(args[2])
|
|
|
|
elseif args[1] == "z" then
|
|
|
|
target_coords["z"] = target_coords["z"] + tonumber(args[2])
|
|
|
|
else
|
2019-07-15 13:52:31 -05:00
|
|
|
minetest.chat_send_player(player, S("Not a valid axis. Valid options are X, Y or Z."))
|
2019-03-24 15:38:32 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
if can_teleport(target_coords) == false then
|
2019-07-15 13:52:31 -05:00
|
|
|
minetest.chat_send_player(player, S("You cannot teleport to a location outside the map!"))
|
2019-03-24 15:38:32 +00:00
|
|
|
return
|
2016-05-18 07:40:42 -04:00
|
|
|
end
|
2019-07-08 20:23:57 -05:00
|
|
|
pname:set_pos(find_free_position_near(target_coords))
|
2019-03-24 15:38:32 +00:00
|
|
|
minetest.sound_play("whoosh", {pos = target_coords, gain = 0.5, max_hear_distance = 10})
|
|
|
|
--parti2(target_coords)
|
2016-05-18 07:40:42 -04:00
|
|
|
end
|
2016-05-18 07:16:48 -04:00
|
|
|
|
2016-05-18 15:10:23 -04:00
|
|
|
-- Evade
|
2019-07-11 20:43:42 -05:00
|
|
|
function tpe(player)
|
2019-07-15 13:52:31 -05:00
|
|
|
minetest.chat_send_player(player, S("EVADE!"))
|
2016-05-18 18:59:28 -04:00
|
|
|
local mindistance = 15
|
|
|
|
local maxdistance = 50
|
2016-05-18 18:47:49 -04:00
|
|
|
local times = math.random(6,20) -- how many times to jump - minimum,maximum
|
2016-05-18 17:10:58 -04:00
|
|
|
local negatives = { '-','' } -- either it's this way or that way: the difference between -10 and 10
|
2016-05-18 16:48:43 -04:00
|
|
|
local options = { 'x', 'y', 'z' }
|
2016-05-18 16:31:08 -04:00
|
|
|
local isnegative = ''
|
|
|
|
local distance = 0
|
|
|
|
local axis = ''
|
2016-05-18 18:52:26 -04:00
|
|
|
local iteration = 0
|
2016-05-18 15:10:23 -04:00
|
|
|
for i = 1,times do
|
2016-05-18 16:31:08 -04:00
|
|
|
-- do this every 1 second
|
2016-05-18 18:47:49 -04:00
|
|
|
minetest.after(iteration,
|
2016-05-18 16:31:08 -04:00
|
|
|
function()
|
2016-05-18 16:48:43 -04:00
|
|
|
isnegative = negatives[math.random(2)] -- choose randomly whether this is this way or that
|
2016-05-18 16:31:08 -04:00
|
|
|
distance = isnegative .. math.random(mindistance,maxdistance) -- the distance to jump
|
|
|
|
axis = options[math.random(3)]
|
2016-05-18 18:47:49 -04:00
|
|
|
local command = axis .. " " .. distance
|
|
|
|
tpj(player,command)
|
2016-05-18 16:31:08 -04:00
|
|
|
end
|
|
|
|
)
|
2016-05-18 18:47:49 -04:00
|
|
|
iteration = iteration + 0.5
|
2016-05-18 15:10:23 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-07-11 20:59:46 -05:00
|
|
|
-- Register chatcommands
|
2019-07-17 18:04:52 -05:00
|
|
|
if enable_configuration then
|
|
|
|
minetest.register_chatcommand("tpp", {
|
|
|
|
description = S("Teleport to a place (i.e., spawn, shop)."),
|
|
|
|
params = S("<place> | leave empty to see available places"),
|
|
|
|
privs = {},
|
|
|
|
func = function(player, param)
|
|
|
|
local pname = minetest.get_player_by_name(player)
|
|
|
|
param = param:lower()
|
|
|
|
|
|
|
|
-- Show the available places to the player.
|
|
|
|
if param == "" then
|
|
|
|
-- shivajiva101's function (thanks!).
|
|
|
|
local places = {}
|
|
|
|
for key, value in pairs(available_places) do
|
|
|
|
table.insert(places, key)
|
|
|
|
end
|
|
|
|
if #places == 0 then
|
|
|
|
return true, S("There are no places yet.")
|
|
|
|
end
|
|
|
|
table.insert(places, S("Usage: /tpp <place>"))
|
|
|
|
return true, table.concat(places, "\n")
|
|
|
|
-- End shivajiva101's function.
|
|
|
|
|
|
|
|
-- Teleport player to the specified place.
|
|
|
|
elseif available_places[param] then
|
|
|
|
local pos = {x = available_places[param].x, y = available_places[param].y, z = available_places[param].z}
|
|
|
|
pname:set_pos(pos)
|
|
|
|
minetest.chat_send_player(player, S("Teleporting to @1.", param))
|
|
|
|
-- Check if the place exists.
|
|
|
|
elseif not available_places[param] then
|
|
|
|
minetest.chat_send_player(player, S("There is no place by that name. Keep in mind this is case-sensitive."))
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
2014-07-26 09:20:32 +03:00
|
|
|
minetest.register_chatcommand("tpr", {
|
2019-07-15 13:52:31 -05:00
|
|
|
description = S("Request teleport to another player"),
|
2019-07-16 14:26:28 -05:00
|
|
|
params = S("<playername> | leave playername empty to see help message"),
|
2019-07-08 20:23:57 -05:00
|
|
|
privs = {interact = true, tp = true},
|
2014-07-30 12:15:08 +10:00
|
|
|
func = tpr_send
|
2014-07-26 09:20:32 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_chatcommand("tphr", {
|
2019-07-15 13:52:31 -05:00
|
|
|
description = S("Request player to teleport to you"),
|
2019-07-16 14:26:28 -05:00
|
|
|
params = S("<playername> | leave playername empty to see help message"),
|
2019-07-08 20:23:57 -05:00
|
|
|
privs = {interact = true, tp = true},
|
2014-07-30 12:15:08 +10:00
|
|
|
func = tphr_send
|
2014-07-26 09:20:32 +03:00
|
|
|
})
|
|
|
|
|
2016-05-10 11:11:31 -04:00
|
|
|
minetest.register_chatcommand("tpc", {
|
2019-07-15 13:52:31 -05:00
|
|
|
description = S("Teleport to coordinates"),
|
2019-07-16 14:26:28 -05:00
|
|
|
params = S("<coordinates> | leave coordinates empty to see help message"),
|
2019-07-08 20:30:16 -05:00
|
|
|
privs = {interact = true, tp_tpc = true, tp = true},
|
2016-05-10 11:11:31 -04:00
|
|
|
func = tpc_send
|
|
|
|
})
|
|
|
|
|
2016-05-18 07:40:42 -04:00
|
|
|
minetest.register_chatcommand("tpj", {
|
2019-07-15 13:52:31 -05:00
|
|
|
description = S("Teleport to relative position"),
|
2019-07-16 14:26:28 -05:00
|
|
|
params = S("<axis> <distance> | leave empty to see help message"),
|
2019-07-08 20:30:16 -05:00
|
|
|
privs = {interact = true, tp_tpc = true, tp = true},
|
2016-05-18 07:40:42 -04:00
|
|
|
func = tpj
|
|
|
|
})
|
|
|
|
|
2016-05-18 15:10:23 -04:00
|
|
|
minetest.register_chatcommand("tpe", {
|
2019-07-15 13:52:31 -05:00
|
|
|
description = S("Evade Enemy"),
|
2019-07-08 20:30:16 -05:00
|
|
|
privs = {interact = true, tp_tpc = true, tp = true},
|
2016-05-18 15:10:23 -04:00
|
|
|
func = tpe
|
|
|
|
})
|
|
|
|
|
2014-07-26 09:20:32 +03:00
|
|
|
minetest.register_chatcommand("tpy", {
|
2019-07-15 13:52:31 -05:00
|
|
|
description = S("Accept teleport requests from another player"),
|
2019-07-08 20:23:57 -05:00
|
|
|
privs = {interact = true, tp = true},
|
2014-07-30 12:15:08 +10:00
|
|
|
func = tpr_accept
|
2014-07-26 09:20:32 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_chatcommand("tpn", {
|
2019-07-15 13:52:31 -05:00
|
|
|
description = S("Deny teleport requests from another player"),
|
2019-07-08 20:23:57 -05:00
|
|
|
privs = {interact = true, tp = true},
|
2014-07-30 12:15:08 +10:00
|
|
|
func = tpr_deny
|
2014-07-26 09:20:32 +03:00
|
|
|
})
|
2014-07-30 12:30:37 +10:00
|
|
|
|
2019-07-08 20:23:57 -05:00
|
|
|
-- Log
|
2019-07-15 13:52:31 -05:00
|
|
|
if minetest.settings:get_bool("log_mods") then
|
2019-07-16 14:48:29 -05:00
|
|
|
minetest.log("action", S("[Teleport Request] TPS Teleport v@1 Loaded!", version))
|
2019-07-15 13:52:31 -05:00
|
|
|
end
|