196 lines
4.9 KiB
Lua
196 lines
4.9 KiB
Lua
|
|
||
|
local tpask = {
|
||
|
requests = {},
|
||
|
muted = {},
|
||
|
timeout = 120,
|
||
|
}
|
||
|
|
||
|
local function cmd_top(name)
|
||
|
local curr_pos = minetest.get_player_by_name(name):getpos()
|
||
|
curr_pos.y = math.ceil(curr_pos.y) + 0.5
|
||
|
|
||
|
while minetest.get_node(curr_pos).name ~= "ignore" do
|
||
|
curr_pos.y = curr_pos.y + 1
|
||
|
end
|
||
|
|
||
|
curr_pos.y = curr_pos.y - 0.5
|
||
|
|
||
|
while minetest.get_node(curr_pos).name == "air" do
|
||
|
curr_pos.y = curr_pos.y - 1
|
||
|
end
|
||
|
curr_pos.y = curr_pos.y + 0.5
|
||
|
|
||
|
minetest.get_player_by_name(name):set_pos(curr_pos)
|
||
|
return true, "Teleported to top."
|
||
|
end
|
||
|
|
||
|
local function cmd_back(name)
|
||
|
local pos = minetest.string_to_pos(ess.get_player_meta(name, "position"))
|
||
|
if not pos then
|
||
|
return false, "Could not return to previous position."
|
||
|
end
|
||
|
minetest.get_player_by_name(name):set_pos(pos)
|
||
|
return true, "Teleported back."
|
||
|
end
|
||
|
|
||
|
local function cmd_tpcommon(name,tname,direction)
|
||
|
if name == tname then
|
||
|
return false, "Cannot teleport to self."
|
||
|
end
|
||
|
|
||
|
local target = minetest.get_player_by_name(tname)
|
||
|
if not target then
|
||
|
return false, "Could not find player."
|
||
|
end
|
||
|
|
||
|
if tpask.requests[tname] and tpask.requests[tname].when > minetest.get_us_time() - tpask.timeout * 100000 then
|
||
|
return false, "There are currently pending requests regarding this player. Please wait."
|
||
|
end
|
||
|
|
||
|
if not tpask.muted[tname] then
|
||
|
local message = "to teleport to you"
|
||
|
|
||
|
if direction == 2 then
|
||
|
message = "you to teleport to them"
|
||
|
end
|
||
|
|
||
|
minetest.chat_send_player(tname, name .. " has requested "..message..".")
|
||
|
minetest.chat_send_player(tname, "Run /tpaccept to accept or /tpadeny to deny.")
|
||
|
if tpask.timeout > 0 then
|
||
|
minetest.chat_send_player(tname, "You have "..tpask.timeout.." seconds to respond.")
|
||
|
end
|
||
|
tpask.requests[tname] = {when = minetest.get_us_time()}
|
||
|
if direction == 1 then
|
||
|
tpask.requests[tname].who = name
|
||
|
else
|
||
|
tpask.requests[tname].to = name
|
||
|
end
|
||
|
end
|
||
|
|
||
|
return true, "Teleport request sent to " .. tname .. ".."
|
||
|
end
|
||
|
|
||
|
local function cmd_tpask(name,tname)
|
||
|
return cmd_tpcommon(name,tname,1)
|
||
|
end
|
||
|
|
||
|
local function cmd_tpaskhere(name,tname)
|
||
|
return cmd_tpcommon(name,tname,2)
|
||
|
end
|
||
|
|
||
|
local function cmd_tpaconfirm(name)
|
||
|
local reqs = tpask.requests[name]
|
||
|
local me = minetest.get_player_by_name(name)
|
||
|
if not reqs or (tpask.timeout > 0 and tpask.requests[name].when < minetest.get_us_time() - tpask.timeout * 100000) then
|
||
|
return false, "You have no pending teleport requests."
|
||
|
end
|
||
|
|
||
|
local who = reqs.to or reqs.who
|
||
|
local whoplayer = minetest.get_player_by_name(who)
|
||
|
if not whoplayer then
|
||
|
tpask.requests[name] = nil
|
||
|
return false, "You have no pending teleport requests."
|
||
|
end
|
||
|
|
||
|
if reqs.to then
|
||
|
minetest.chat_send_player(name, "Teleporting..")
|
||
|
me:set_pos(whoplayer:get_pos())
|
||
|
else
|
||
|
minetest.chat_send_player(who, "Teleporting..")
|
||
|
whoplayer:set_pos(me:get_pos())
|
||
|
end
|
||
|
|
||
|
tpask.requests[name] = nil
|
||
|
|
||
|
return true
|
||
|
end
|
||
|
|
||
|
local function cmd_tpadeny(name)
|
||
|
local reqs = tpask.requests[name]
|
||
|
if not reqs or tpask.requests[name].when < minetest.get_us_time() - tpask.timeout * 1000 then
|
||
|
return false, "You have no pending teleport requests."
|
||
|
end
|
||
|
|
||
|
tpask.requests[name] = nil
|
||
|
|
||
|
return true, "Declined teleport request successfully. Use /tpmute to silence teleport requests."
|
||
|
end
|
||
|
|
||
|
local function cmd_tpamute(name)
|
||
|
if tpask.muted[name] then
|
||
|
tpask.muted[name] = nil
|
||
|
return true, "Unmuted teleport requests successfully."
|
||
|
end
|
||
|
|
||
|
tpask.muted[name] = "*"
|
||
|
return true, "Muted teleport requests successfully."
|
||
|
end
|
||
|
|
||
|
-- Use builtin tele
|
||
|
local cmd_teleport = minetest.registered_chatcommands["teleport"].func
|
||
|
|
||
|
local commands = {
|
||
|
["tpask"] = {
|
||
|
description = "Request to teleport to the specified player.",
|
||
|
params = "<player>",
|
||
|
aliases = {"tpa"},
|
||
|
privs = {
|
||
|
["ess.teleport.tpa"] = true,
|
||
|
},
|
||
|
save_player_pos = true,
|
||
|
func = cmd_tpask,
|
||
|
},
|
||
|
["tpaskhere"] = {
|
||
|
description = "Request to teleport the specified player to you.",
|
||
|
params = "<player>",
|
||
|
aliases = {"tpahere"},
|
||
|
privs = {
|
||
|
["ess.teleport.tpahere"] = true,
|
||
|
},
|
||
|
save_player_pos = true,
|
||
|
func = cmd_tpaskhere,
|
||
|
},
|
||
|
["tpaccept"] = {
|
||
|
description = "Accept a teleport request.",
|
||
|
aliases = {"tpayes"},
|
||
|
func = cmd_tpaconfirm,
|
||
|
save_player_pos = true,
|
||
|
},
|
||
|
["tpdeny"] = {
|
||
|
description = "Reject a teleport request.",
|
||
|
aliases = {"tpno"},
|
||
|
func = cmd_tpadeny,
|
||
|
},
|
||
|
["tpmute"] = {
|
||
|
description = "Silence/unsilence teleport requests.",
|
||
|
func = cmd_tpamute,
|
||
|
},
|
||
|
["back"] = {
|
||
|
description = "Teleports you to your location prior to tp/spawn/warp.",
|
||
|
aliases = {"return"},
|
||
|
privs = true,
|
||
|
save_player_pos = true,
|
||
|
func = cmd_back,
|
||
|
},
|
||
|
["top"] = {
|
||
|
description = "Teleport to the highest node at your current position.",
|
||
|
privs = true,
|
||
|
save_player_pos = true,
|
||
|
func = cmd_top,
|
||
|
},
|
||
|
["teleport"] = {
|
||
|
description = "Teleport to position or player",
|
||
|
aliases = {"tp", "tele", "tp2p"},
|
||
|
params = "<X>,<Y>,<Z> | <to_name> | (<name> <X>,<Y>,<Z>) | (<name> <to_name>)",
|
||
|
privs = {
|
||
|
["teleport"] = true,
|
||
|
["ess.teleport"] = true,
|
||
|
},
|
||
|
override = true,
|
||
|
save_player_pos = true,
|
||
|
func = cmd_teleport,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
ess.autoregister(commands, "teleport")
|