2014-07-26 09:20:32 +03:00
|
|
|
|
2014-07-30 14:06:42 +10:00
|
|
|
local timeout_delay = 60
|
2014-07-26 09:20:32 +03:00
|
|
|
|
2014-07-30 14:01:44 +10:00
|
|
|
-- Set to true to register tpr_admin priv
|
2014-07-30 14:06:42 +10:00
|
|
|
local regnewpriv = false
|
2014-07-26 09:20:32 +03:00
|
|
|
|
2014-07-30 14:01:44 +10:00
|
|
|
local version = "0.2"
|
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
|
|
|
|
2014-07-30 14:01:44 +10:00
|
|
|
--DO NOT CHANGE:------------
|
|
|
|
value_carryover = nil
|
|
|
|
value_carryover2 = nil
|
|
|
|
----------------------------
|
2014-07-26 09:20:32 +03:00
|
|
|
|
2014-07-30 14:01:44 +10:00
|
|
|
-- Reset after configured delay.
|
|
|
|
-- These functions cannot be local (not sure if this can be avoided)
|
|
|
|
function reset_request(name)
|
|
|
|
if tpr_list[value_carryover] ~= nil then
|
|
|
|
tpr_list[value_carryover] = nil
|
|
|
|
end
|
|
|
|
end
|
2014-07-26 09:20:32 +03:00
|
|
|
|
2014-07-30 14:01:44 +10:00
|
|
|
function reset_request2(name)
|
|
|
|
if tphr_list[value_carryover2] ~= nil then
|
|
|
|
tphr_list[value_carryover2] = nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
--Teleport Request System
|
|
|
|
local function tpr_send(name, param)
|
2014-07-26 09:20:32 +03:00
|
|
|
|
2014-07-30 12:32:42 +10:00
|
|
|
local sender = name
|
|
|
|
local receiver = param
|
2014-07-30 14:01:44 +10:00
|
|
|
|
|
|
|
value_carryover = param
|
2014-07-26 09:20:32 +03:00
|
|
|
|
2014-07-30 12:15:08 +10:00
|
|
|
if receiver == "" then
|
|
|
|
minetest.chat_send_player(sender, "Usage: /tpr <Player name>")
|
|
|
|
return
|
|
|
|
end
|
2014-07-26 09:20:32 +03:00
|
|
|
|
|
|
|
--If paremeter is valid, Send teleport message and set the table.
|
2014-07-30 12:15:08 +10: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 09:20:32 +03:00
|
|
|
--Teleport timeout delay
|
|
|
|
minetest.after(timeout_delay, reset_request)
|
2014-07-30 12:15:08 +10:00
|
|
|
end
|
2014-07-26 09:20:32 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
local function tphr_send(name, param)
|
|
|
|
|
2014-07-30 14:05:03 +10:00
|
|
|
local sender = name
|
|
|
|
local receiver = param
|
2014-07-30 14:01:44 +10:00
|
|
|
|
2014-07-30 14:05:03 +10:00
|
|
|
value_carryover = param
|
2014-07-26 09:20:32 +03:00
|
|
|
|
2014-07-30 14:05:03 +10:00
|
|
|
if receiver == "" then
|
|
|
|
minetest.chat_send_player(sender, "Usage: /tphr <Player name>")
|
2014-07-30 12:15:08 +10:00
|
|
|
return
|
|
|
|
end
|
2014-07-26 09:20:32 +03:00
|
|
|
|
|
|
|
--If paremeter is valid, Send teleport message and set the table.
|
2014-07-30 14:05:03 +10: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 12:15:08 +10:00
|
|
|
|
|
|
|
--Write name values to list and clear old values.
|
2014-07-30 14:05:03 +10:00
|
|
|
tphr_list[receiver] = nil
|
|
|
|
tphr_list[receiver] = sender
|
2014-07-26 09:20:32 +03:00
|
|
|
--Teleport timeout delay
|
|
|
|
minetest.after(timeout_delay, reset_request2)
|
2014-07-30 12:15:08 +10:00
|
|
|
end
|
2014-07-26 09:20:32 +03:00
|
|
|
end
|
|
|
|
|
2014-07-30 14:01:44 +10:00
|
|
|
local function tpr_deny(name)
|
2014-07-30 12:15:08 +10:00
|
|
|
sender = tpr_list[value_carryover]
|
2014-07-26 09:20:32 +03:00
|
|
|
if tpr_list[value_carryover] ~= nil then
|
2014-07-30 12:15:08 +10:00
|
|
|
tpr_list[value_carryover] = nil
|
2014-07-30 12:32:42 +10:00
|
|
|
minetest.chat_send_player(sender, 'Teleport request denied.')
|
2014-07-26 09:20:32 +03:00
|
|
|
end
|
2014-07-30 12:15:08 +10:00
|
|
|
sender2 = tphr_list[value_carryover2]
|
2014-07-26 09:20:32 +03:00
|
|
|
if tphr_list[value_carryover2] ~= nil then
|
2014-07-30 12:15:08 +10:00
|
|
|
tphr_list[value_carryover2] = nil
|
2014-07-30 12:32:42 +10:00
|
|
|
minetest.chat_send_player(sender2, 'Teleport request denied.')
|
2014-07-26 09:20:32 +03:00
|
|
|
end
|
|
|
|
end
|
2014-07-30 12:30:37 +10:00
|
|
|
|
2014-07-30 14:01:44 +10: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 09:20:32 +03:00
|
|
|
|
|
|
|
|
2014-07-30 14:01:44 +10:00
|
|
|
--Teleport Accept Systems
|
|
|
|
local function tpr_accept(name, param)
|
2014-07-26 09:20:32 +03:00
|
|
|
|
2014-07-30 12:15:08 +10:00
|
|
|
--Check to prevent constant teleporting.
|
2014-07-26 09:20:32 +03:00
|
|
|
if tpr_list[name] == nil and tphr_list[name] == nil then
|
2014-07-30 12:15:08 +10:00
|
|
|
minetest.chat_send_player(name, "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
|
|
|
|
2014-07-30 14:01:44 +10:00
|
|
|
local chatmsg
|
|
|
|
local source = nil
|
|
|
|
local target = nil
|
|
|
|
local 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]
|
|
|
|
source = minetest.env:get_player_by_name(name2)
|
|
|
|
target = minetest.env:get_player_by_name(name)
|
|
|
|
chatmsg = name2 .. " is teleporting to you."
|
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]
|
|
|
|
source = minetest.env:get_player_by_name(name)
|
|
|
|
target = minetest.env:get_player_by_name(name2)
|
|
|
|
chatmsg = "You are teleporting to " .. name2 .. "."
|
|
|
|
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
|
|
|
|
if source == nil or target == nil then
|
2014-07-26 09:20:32 +03:00
|
|
|
return
|
|
|
|
end
|
2014-07-30 14:01:44 +10: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 09:20:32 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
--Initalize Permissions.
|
|
|
|
|
2014-07-30 14:06:42 +10: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 14:01:44 +10:00
|
|
|
|
2014-07-26 09:20:32 +03:00
|
|
|
--Initalize Commands.
|
|
|
|
|
|
|
|
minetest.register_chatcommand("tpr", {
|
2014-07-30 12:15:08 +10: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 09:20:32 +03:00
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_chatcommand("tphr", {
|
2014-07-30 12:15:08 +10: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 09:20:32 +03:00
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_chatcommand("tpy", {
|
2014-07-30 12:15:08 +10:00
|
|
|
description = "Accept teleport requests from another player",
|
|
|
|
func = tpr_accept
|
2014-07-26 09:20:32 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_chatcommand("tpn", {
|
2014-07-30 12:15:08 +10:00
|
|
|
description = "Deny teleport requests from another player",
|
|
|
|
func = tpr_deny
|
2014-07-26 09:20:32 +03:00
|
|
|
})
|
2014-07-30 12:30:37 +10:00
|
|
|
|
|
|
|
print ("[Teleport Request] Teleport Request v" .. version .. " Loaded.")
|