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
|
|
|
|
2014-07-30 06:01:44 +02:00
|
|
|
-- Set to true to register tpr_admin priv
|
2014-07-30 06:06:42 +02:00
|
|
|
local regnewpriv = false
|
2014-07-26 08:20:32 +02:00
|
|
|
|
2014-07-30 06:01:44 +02:00
|
|
|
local version = "0.2"
|
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
|
|
|
|
2014-07-30 06:01:44 +02:00
|
|
|
--Teleport Request System
|
|
|
|
local function tpr_send(name, param)
|
2014-07-26 08:20:32 +02:00
|
|
|
|
2014-07-30 04:32:42 +02:00
|
|
|
local sender = name
|
|
|
|
local receiver = param
|
2014-07-30 06:01:44 +02:00
|
|
|
|
|
|
|
value_carryover = param
|
2014-07-26 08:20:32 +02:00
|
|
|
|
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.
|
2014-07-30 04:15:08 +02:00
|
|
|
if minetest.env:get_player_by_name(receiver) then
|
|
|
|
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.')
|
|
|
|
|
|
|
|
--Write name values to list and clear old values.
|
|
|
|
tpr_list[receiver] = nil
|
|
|
|
tpr_list[receiver] = sender
|
2014-07-26 08:20:32 +02:00
|
|
|
--Teleport timeout delay
|
2014-07-30 08:39:09 +02:00
|
|
|
minetest.after(timeout_delay, function(name)
|
|
|
|
if tpr_list[name] ~= nil then
|
|
|
|
tpr_list[name] = nil
|
|
|
|
end
|
|
|
|
end, name)
|
2014-07-30 04:15:08 +02:00
|
|
|
end
|
2014-07-26 08:20:32 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
local function tphr_send(name, param)
|
|
|
|
|
2014-07-30 06:05:03 +02:00
|
|
|
local sender = name
|
|
|
|
local receiver = param
|
2014-07-30 06:01:44 +02:00
|
|
|
|
2014-07-30 06:05:03 +02:00
|
|
|
value_carryover = param
|
2014-07-26 08:20:32 +02:00
|
|
|
|
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.
|
2014-07-30 06:05:03 +02:00
|
|
|
if minetest.env:get_player_by_name(receiver) then
|
|
|
|
minetest.chat_send_player(receiver, sender ..' is requesting that you teleport to them. /tpy to accept.')
|
|
|
|
minetest.chat_send_player(sender, 'Teleport request sent! It will time out in '.. timeout_delay ..' seconds.')
|
2014-07-30 04:15:08 +02:00
|
|
|
|
|
|
|
--Write name values to list and clear old values.
|
2014-07-30 06:05:03 +02:00
|
|
|
tphr_list[receiver] = nil
|
|
|
|
tphr_list[receiver] = sender
|
2014-07-26 08:20:32 +02:00
|
|
|
--Teleport timeout delay
|
2014-07-30 08:39:09 +02:00
|
|
|
minetest.after(timeout_delay, function(name)
|
|
|
|
if tphr_list[name] ~= nil then
|
|
|
|
tphr_list[name] = nil
|
|
|
|
end
|
|
|
|
end, name)
|
2014-07-30 04:15:08 +02:00
|
|
|
end
|
2014-07-26 08:20:32 +02:00
|
|
|
end
|
|
|
|
|
2014-07-30 08:56:20 +02:00
|
|
|
local function tpr_deny(name, param)
|
|
|
|
if tpr_list[name] ~= nil then
|
|
|
|
minetest.chat_send_player(tpr_list[name], 'Teleport request denied.')
|
|
|
|
tpr_list[name] = nil
|
2014-07-26 08:20:32 +02:00
|
|
|
end
|
2014-07-30 08:56:20 +02:00
|
|
|
if tphr_list[name] ~= nil then
|
|
|
|
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},
|
|
|
|
}
|
|
|
|
for _, d in ipairs(tries) do
|
|
|
|
local p = {x = pos.x+d.x, y = pos.y+d.y, z = pos.z+d.z}
|
|
|
|
local n = minetest.env:get_node(p)
|
|
|
|
if not minetest.registered_nodes[n.name].walkable then
|
|
|
|
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.
|
2014-07-26 08:20:32 +02:00
|
|
|
if tpr_list[name] == nil and tphr_list[name] == nil then
|
2014-07-30 04:15:08 +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
|
|
|
|
2014-07-30 06:01:44 +02:00
|
|
|
local chatmsg
|
|
|
|
local source = nil
|
|
|
|
local target = nil
|
|
|
|
local 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-07-30 06:46:45 +02:00
|
|
|
source = minetest.env:get_player_by_name(name)
|
|
|
|
target = minetest.env: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-07-30 06:46:45 +02:00
|
|
|
source = minetest.env:get_player_by_name(name2)
|
|
|
|
target = minetest.env: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
|
|
|
|
if source == nil or target == nil 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)
|
|
|
|
|
|
|
|
p = source:getpos()
|
|
|
|
p = find_free_position_near(p)
|
|
|
|
target:setpos(p)
|
2014-07-26 08:20:32 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
--Initalize Permissions.
|
|
|
|
|
2014-07-30 06:06:42 +02:00
|
|
|
if regnewpriv then
|
|
|
|
minetest.register_privilege("tpr_admin", {
|
|
|
|
description = "Permission to override teleport to other players. UNFINISHED",
|
|
|
|
give_to_singleplayer = true
|
|
|
|
})
|
|
|
|
end
|
2014-07-30 06:01:44 +02:00
|
|
|
|
2014-07-26 08:20:32 +02:00
|
|
|
--Initalize Commands.
|
|
|
|
|
|
|
|
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", {
|
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 = tphr_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
|
|
|
|
|
|
|
print ("[Teleport Request] Teleport Request v" .. version .. " Loaded.")
|