2016-05-10 17:11:31 +02:00
|
|
|
-- Originally Teleport Request by Traxie21 and released with the WTFPL license
|
2014-07-31 06:41:44 +02:00
|
|
|
-- https://forum.minetest.net/viewtopic.php?id=4457
|
|
|
|
-- Updates by Zeno and ChaosWormz
|
2016-05-10 17:11:31 +02:00
|
|
|
-- New release by RobbieF under new mod: tps_teleport - http://blog.minetest.tv/teleport-request/
|
2014-07-26 08:20:32 +02:00
|
|
|
|
2014-07-30 08:40:10 +02:00
|
|
|
local timeout_delay = 60
|
2014-07-26 08:20:32 +02:00
|
|
|
|
2016-05-13 14:42:58 +02:00
|
|
|
local version = "1.3"
|
2014-07-26 08:20:32 +02:00
|
|
|
|
2014-07-30 04:30:37 +02:00
|
|
|
local tpr_list = {}
|
|
|
|
local tphr_list = {}
|
2014-07-26 08:20:32 +02:00
|
|
|
|
2016-05-13 14:42:58 +02:00
|
|
|
minetest.register_privilege("tp_admin", {description = "Admin overrides for tps_teleport.", give_to_singleplayer=false,})
|
2016-05-13 14:35:20 +02:00
|
|
|
|
2014-07-30 06:01:44 +02:00
|
|
|
--Teleport Request System
|
2015-08-28 22:08:16 +02:00
|
|
|
local function tpr_send(sender, receiver)
|
2014-07-30 04:15:08 +02:00
|
|
|
if receiver == "" then
|
|
|
|
minetest.chat_send_player(sender, "Usage: /tpr <Player name>")
|
|
|
|
return
|
|
|
|
end
|
2014-07-26 08:20:32 +02:00
|
|
|
|
|
|
|
--If paremeter is valid, Send teleport message and set the table.
|
2015-08-28 22:08:16 +02:00
|
|
|
if not minetest.get_player_by_name(receiver) then
|
|
|
|
return
|
2014-07-30 04:15:08 +02:00
|
|
|
end
|
2014-07-26 08:20:32 +02:00
|
|
|
|
2015-08-28 22:08:16 +02:00
|
|
|
minetest.chat_send_player(receiver, sender ..' is requesting to teleport to you. /tpy to accept.')
|
|
|
|
minetest.chat_send_player(sender, 'Teleport request sent! It will time out in '.. timeout_delay ..' seconds.')
|
2014-07-26 08:20:32 +02:00
|
|
|
|
2015-08-28 22:08:16 +02:00
|
|
|
--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)
|
|
|
|
end
|
2014-07-30 06:01:44 +02:00
|
|
|
|
2015-08-28 22:08:16 +02:00
|
|
|
local function tphr_send(sender, receiver)
|
2014-07-30 06:05:03 +02:00
|
|
|
if receiver == "" then
|
|
|
|
minetest.chat_send_player(sender, "Usage: /tphr <Player name>")
|
2014-07-30 04:15:08 +02:00
|
|
|
return
|
|
|
|
end
|
2014-07-26 08:20:32 +02:00
|
|
|
|
|
|
|
--If paremeter is valid, Send teleport message and set the table.
|
2015-08-28 22:08:16 +02:00
|
|
|
if not minetest.get_player_by_name(receiver) then
|
|
|
|
return
|
2014-07-30 04:15:08 +02:00
|
|
|
end
|
2015-08-28 22:08:16 +02:00
|
|
|
|
|
|
|
minetest.chat_send_player(receiver, sender ..' is requesting that you teleport to them. /tpy to accept; /tpn to deny')
|
|
|
|
minetest.chat_send_player(sender, 'Teleport request sent! It will time out in '.. timeout_delay ..' seconds.')
|
|
|
|
|
|
|
|
--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)
|
2014-07-26 08:20:32 +02:00
|
|
|
end
|
|
|
|
|
2016-05-10 17:11:31 +02:00
|
|
|
local function tpc_send(player,coordinates)
|
|
|
|
|
2016-05-10 19:53:26 +02:00
|
|
|
local posx,posy,posz = string.match(coordinates, "^(-?%d+),(-?%d+),(-?%d+)$")
|
2016-05-10 19:42:17 +02:00
|
|
|
local pname = minetest.get_player_by_name(player)
|
|
|
|
|
2016-05-10 19:58:24 +02: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 17:11:31 +02:00
|
|
|
|
2016-05-10 20:20:28 +02: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
|
|
|
|
minetest.chat_send_player(player, "Usage: /tpc <x,y,z>")
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
|
2016-05-10 19:53:26 +02:00
|
|
|
if posx > 32765 or posx < -32765 or posy > 32765 or posy < -32765 or posz > 32765 or posz < -32765 then
|
2016-05-10 20:11:20 +02:00
|
|
|
minetest.chat_send_player(player, "Error: Invalid coordinates.")
|
2016-05-10 17:11:31 +02:00
|
|
|
return nil
|
|
|
|
end
|
2016-05-10 19:42:17 +02:00
|
|
|
|
2016-05-10 19:53:26 +02:00
|
|
|
local target_coords={x=posx, y=posy, z=posz}
|
2016-05-10 19:42:17 +02:00
|
|
|
|
2016-05-13 14:35:20 +02:00
|
|
|
|
2016-05-10 17:11:31 +02: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 14:42:58 +02:00
|
|
|
-- Admin user (priv "tp_admin") overrides all protection
|
|
|
|
if minetest.check_player_privs(user.get_player_name(user), {tp_admin=true}) then
|
2016-05-13 14:35:20 +02:00
|
|
|
minetest.chat_send_player(player, 'Teleporting to '..posx..','..posy..','..posz)
|
|
|
|
minetest.sound_play("tps_portal", {pos = target_coords, gain = 1.0, max_hear_distance = 10})
|
|
|
|
pname:setpos(target_coords)
|
|
|
|
else
|
|
|
|
local protected = minetest.is_protected(target_coords,pname)
|
|
|
|
if protected then
|
|
|
|
local owner_string = areas:getNodeOwners(target_coords)
|
|
|
|
if pname ~= owner_string then
|
|
|
|
minetest.chat_send_player(player, "Error: These coordinates are within a protected area.")
|
|
|
|
return
|
|
|
|
end
|
|
|
|
else
|
|
|
|
end
|
|
|
|
minetest.chat_send_player(player, 'Teleporting to '..posx..','..posy..','..posz)
|
|
|
|
minetest.sound_play("tps_portal", {pos = target_coords, gain = 1.0, max_hear_distance = 10})
|
|
|
|
pname:setpos(target_coords)
|
|
|
|
end
|
2016-05-10 17:11:31 +02:00
|
|
|
end
|
|
|
|
|
2015-08-28 22:08:16 +02:00
|
|
|
local function tpr_deny(name)
|
|
|
|
if tpr_list[name] then
|
2014-07-30 08:56:20 +02:00
|
|
|
minetest.chat_send_player(tpr_list[name], 'Teleport request denied.')
|
|
|
|
tpr_list[name] = nil
|
2014-07-26 08:20:32 +02:00
|
|
|
end
|
2015-08-28 22:08:16 +02:00
|
|
|
if tphr_list[name] then
|
2014-07-30 08:56:20 +02:00
|
|
|
minetest.chat_send_player(tphr_list[name], 'Teleport request denied.')
|
|
|
|
tphr_list[name] = nil
|
2014-07-26 08:20:32 +02:00
|
|
|
end
|
|
|
|
end
|
2014-07-30 04:30:37 +02:00
|
|
|
|
2014-07-30 06:01:44 +02:00
|
|
|
-- Copied from Celeron-55's /teleport command. Thanks Celeron!
|
|
|
|
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},
|
|
|
|
}
|
2015-08-28 22:08:16 +02:00
|
|
|
for _,d in pairs(tries) do
|
|
|
|
local p = vector.add(pos, d)
|
|
|
|
if not minetest.registered_nodes[minetest.get_node(p).name].walkable then
|
2014-07-30 06:01:44 +02:00
|
|
|
return p, true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return pos, false
|
|
|
|
end
|
2014-07-26 08:20:32 +02:00
|
|
|
|
|
|
|
|
2014-07-30 06:01:44 +02:00
|
|
|
--Teleport Accept Systems
|
|
|
|
local function tpr_accept(name, param)
|
2014-07-26 08:20:32 +02:00
|
|
|
|
2014-07-30 04:15:08 +02: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
|
2016-05-10 17:11:31 +02:00
|
|
|
minetest.chat_send_player(name, "Usage: /tpy allows you to accept teleport requests sent to you by other players.")
|
2014-07-26 08:20:32 +02:00
|
|
|
return
|
|
|
|
end
|
2014-07-30 04:15:08 +02:00
|
|
|
|
2015-08-28 22:08:16 +02:00
|
|
|
local chatmsg, source, target, name2
|
2014-07-30 04:15:08 +02:00
|
|
|
|
2014-07-26 08:20:32 +02:00
|
|
|
if tpr_list[name] then
|
2014-07-30 06:01:44 +02:00
|
|
|
name2 = tpr_list[name]
|
2014-12-09 04:03:30 +01:00
|
|
|
source = minetest.get_player_by_name(name)
|
|
|
|
target = minetest.get_player_by_name(name2)
|
2014-07-30 06:01:44 +02:00
|
|
|
chatmsg = name2 .. " is teleporting to you."
|
2014-07-26 08:20:32 +02:00
|
|
|
tpr_list[name] = nil
|
2014-07-30 06:01:44 +02:00
|
|
|
elseif tphr_list[name] then
|
|
|
|
name2 = tphr_list[name]
|
2014-12-09 04:03:30 +01:00
|
|
|
source = minetest.get_player_by_name(name2)
|
|
|
|
target = minetest.get_player_by_name(name)
|
2014-07-30 06:01:44 +02:00
|
|
|
chatmsg = "You are teleporting to " .. name2 .. "."
|
|
|
|
tphr_list[name] = nil
|
|
|
|
else
|
2014-07-26 08:20:32 +02:00
|
|
|
return
|
|
|
|
end
|
2014-07-30 04:15:08 +02:00
|
|
|
|
2014-07-30 06:01:44 +02: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 08:20:32 +02:00
|
|
|
return
|
|
|
|
end
|
2014-07-30 06:01:44 +02:00
|
|
|
|
|
|
|
minetest.chat_send_player(name2, "Request Accepted!")
|
|
|
|
minetest.chat_send_player(name, chatmsg)
|
|
|
|
|
2015-08-28 22:08:16 +02:00
|
|
|
target:setpos(find_free_position_near(source:getpos()))
|
2014-07-26 08:20:32 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
minetest.register_chatcommand("tpr", {
|
2014-07-30 04:15:08 +02:00
|
|
|
description = "Request teleport to another player",
|
|
|
|
params = "<playername> | leave playername empty to see help message",
|
|
|
|
privs = {interact=true},
|
|
|
|
func = tpr_send
|
2014-07-26 08:20:32 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_chatcommand("tphr", {
|
2015-02-28 19:23:32 +01:00
|
|
|
description = "Request player to teleport to you",
|
2014-07-30 04:15:08 +02:00
|
|
|
params = "<playername> | leave playername empty to see help message",
|
|
|
|
privs = {interact=true},
|
|
|
|
func = tphr_send
|
2014-07-26 08:20:32 +02:00
|
|
|
})
|
|
|
|
|
2016-05-10 17:11:31 +02:00
|
|
|
minetest.register_chatcommand("tpc", {
|
|
|
|
description = "Teleport to coordinates",
|
|
|
|
params = "<coordinates> | leave coordinates empty to see help message",
|
|
|
|
privs = {interact=true},
|
|
|
|
func = tpc_send
|
|
|
|
})
|
|
|
|
|
2014-07-26 08:20:32 +02:00
|
|
|
minetest.register_chatcommand("tpy", {
|
2014-07-30 04:15:08 +02:00
|
|
|
description = "Accept teleport requests from another player",
|
|
|
|
func = tpr_accept
|
2014-07-26 08:20:32 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_chatcommand("tpn", {
|
2014-07-30 04:15:08 +02:00
|
|
|
description = "Deny teleport requests from another player",
|
|
|
|
func = tpr_deny
|
2014-07-26 08:20:32 +02:00
|
|
|
})
|
2014-07-30 04:30:37 +02:00
|
|
|
|
2016-05-10 17:11:31 +02:00
|
|
|
minetest.log("info", "[Teleport Request] TPS Teleport v" .. version .. " Loaded.")
|