mirror of
https://github.com/minetest-mods/teleport-request.git
synced 2025-01-07 21:47:30 +01:00
Small changes
Completed 2 tasks from the TODO list. See the "README.md" changes commit.
This commit is contained in:
parent
e102f4f18a
commit
c921f786d7
81
init.lua
81
init.lua
@ -1,7 +1,9 @@
|
||||
-- Originally Teleport Request by Traxie21 and released with the WTFPL license
|
||||
-- https://forum.minetest.net/viewtopic.php?id=4457
|
||||
-- Updates by Zeno and ChaosWormz
|
||||
-- New release by RobbieF under new mod: tps_teleport - http://blog.minetest.tv/teleport-request/
|
||||
--[[
|
||||
Originally made by Traxie21 and released with the WTFPL license.
|
||||
https://forum.minetest.net/viewtopic.php?id=4457
|
||||
Updates by Zeno and ChaosWormz
|
||||
New release by RobbieF under new mod: tps_teleport - http://blog.minetest.tv/teleport-request/
|
||||
--]]
|
||||
|
||||
local timeout_delay = 60
|
||||
|
||||
@ -15,13 +17,21 @@ 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
|
||||
|
||||
minetest.register_privilege("tp", {
|
||||
description = "Let players teleport to other players (request will be sent)",
|
||||
give_to_singleplayer = false,
|
||||
give_to_admin = true,
|
||||
})
|
||||
|
||||
minetest.register_privilege("tp_admin", {
|
||||
description = "Admin overrides for tps_teleport.",
|
||||
give_to_singleplayer=false
|
||||
give_to_singleplayer = false,
|
||||
give_to_admin = true,
|
||||
})
|
||||
minetest.register_privilege("tp_tpc", {
|
||||
description = "Allow player to teleport to coordinates (if permitted by area protection).",
|
||||
give_to_singleplayer=true
|
||||
give_to_singleplayer = true,
|
||||
give_to_admin = true,
|
||||
})
|
||||
|
||||
local function find_free_position_near(pos)
|
||||
@ -63,7 +73,21 @@ local function parti2(pos)
|
||||
end
|
||||
|
||||
-- Teleport Request System
|
||||
local function tpr_send(sender, receiver)
|
||||
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)
|
||||
tpr_accept(receiver)
|
||||
minetest.chat_send_player(sender, "You are teleporting to " .. receiver .. ".")
|
||||
return
|
||||
end
|
||||
|
||||
if receiver == "" then
|
||||
minetest.chat_send_player(sender, "Usage: /tpr <Player name>")
|
||||
return
|
||||
@ -78,6 +102,7 @@ local function tpr_send(sender, receiver)
|
||||
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.
|
||||
if not minetest.check_player_privs(sender, {tp_admin = true}) then
|
||||
tpr_list[receiver] = sender
|
||||
-- Teleport timeout delay
|
||||
minetest.after(timeout_delay, function(name)
|
||||
@ -86,8 +111,22 @@ local function tpr_send(sender, receiver)
|
||||
end
|
||||
end, sender)
|
||||
end
|
||||
end
|
||||
|
||||
local function tphr_send(sender, receiver)
|
||||
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)
|
||||
tpr_accept(receiver)
|
||||
minetest.chat_send_player(sender, receiver .. " is teleporting to you.")
|
||||
return
|
||||
end
|
||||
if receiver == "" then
|
||||
minetest.chat_send_player(sender, "Usage: /tphr <Player name>")
|
||||
return
|
||||
@ -102,6 +141,7 @@ local function tphr_send(sender, receiver)
|
||||
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.
|
||||
if not minetest.check_player_privs(sender, {tp_admin = true}) then
|
||||
tphr_list[receiver] = sender
|
||||
-- Teleport timeout delay
|
||||
minetest.after(timeout_delay, function(name)
|
||||
@ -110,8 +150,9 @@ local function tphr_send(sender, receiver)
|
||||
end
|
||||
end, sender)
|
||||
end
|
||||
end
|
||||
|
||||
local function tpc_send(player,coordinates)
|
||||
function tpc_send(player,coordinates)
|
||||
|
||||
local posx,posy,posz = string.match(coordinates, "^(-?%d+), (-?%d+), (-?%d+)$")
|
||||
local pname = minetest.get_player_by_name(player)
|
||||
@ -139,21 +180,21 @@ local function tpc_send(player,coordinates)
|
||||
-- Admin user (priv "tp_admin") overrides all protection
|
||||
if minetest.check_player_privs(pname, {tp_admin=true}) then
|
||||
minetest.chat_send_player(player, 'Teleporting to '..posx..','..posy..','..posz)
|
||||
pname:setpos(find_free_position_near(target_coords))
|
||||
pname:set_pos(find_free_position_near(target_coords))
|
||||
minetest.sound_play("whoosh", {pos = target_coords, gain = 0.5, max_hear_distance = 10})
|
||||
--parti2(target_coords)
|
||||
else
|
||||
if minetest.check_player_privs(pname, {tp_tpc=true}) then
|
||||
local protected = minetest.is_protected(target_coords,pname)
|
||||
if protected then
|
||||
if not areas:canInteract(target_coords, player) then
|
||||
if not areas:canInteract(target_coords, player) or not minetest.check_player_privs(pname, {areas = true}) then
|
||||
local owners = areas:getNodeOwners(target_coords)
|
||||
minetest.chat_send_player(player,("Error: %s is protected by %s."):format(minetest.pos_to_string(target_coords),table.concat(owners, ", ")))
|
||||
return
|
||||
end
|
||||
end
|
||||
minetest.chat_send_player(player, 'Teleporting to '..posx..','..posy..','..posz)
|
||||
pname:setpos(find_free_position_near(target_coords))
|
||||
pname:set_pos(find_free_position_near(target_coords))
|
||||
minetest.sound_play("whoosh", {pos = target_coords, gain = 0.5, max_hear_distance = 10})
|
||||
--parti2(target_coords)
|
||||
else
|
||||
@ -164,6 +205,7 @@ local function tpc_send(player,coordinates)
|
||||
end
|
||||
|
||||
local function tpr_deny(name)
|
||||
if minetest.check_player_privs(name, {tp_admin = true}) then return end
|
||||
if tpr_list[name] then
|
||||
minetest.chat_send_player(tpr_list[name], 'Teleport request denied.')
|
||||
tpr_list[name] = nil
|
||||
@ -211,8 +253,8 @@ local function tpr_accept(name, param)
|
||||
minetest.chat_send_player(name2, "Request Accepted!")
|
||||
minetest.chat_send_player(name, chatmsg)
|
||||
|
||||
local target_coords=source:getpos()
|
||||
target:setpos(find_free_position_near(target_coords))
|
||||
local target_coords=source:get_pos()
|
||||
target:set_pos(find_free_position_near(target_coords))
|
||||
minetest.sound_play("whoosh", {pos = target_coords, gain = 0.5, max_hear_distance = 10})
|
||||
--parti2(target_coords)
|
||||
end
|
||||
@ -252,7 +294,7 @@ local function tpj(player,param)
|
||||
minetest.chat_send_player(player, "You cannot teleport to a location outside the map!")
|
||||
return
|
||||
end
|
||||
pname:setpos(find_free_position_near(target_coords))
|
||||
pname:set_pos(find_free_position_near(target_coords))
|
||||
minetest.sound_play("whoosh", {pos = target_coords, gain = 0.5, max_hear_distance = 10})
|
||||
--parti2(target_coords)
|
||||
end
|
||||
@ -287,14 +329,14 @@ end
|
||||
minetest.register_chatcommand("tpr", {
|
||||
description = "Request teleport to another player",
|
||||
params = "<playername> | leave playername empty to see help message",
|
||||
privs = {interact=true},
|
||||
privs = {interact = true, tp = true},
|
||||
func = tpr_send
|
||||
})
|
||||
|
||||
minetest.register_chatcommand("tphr", {
|
||||
description = "Request player to teleport to you",
|
||||
params = "<playername> | leave playername empty to see help message",
|
||||
privs = {interact=true},
|
||||
privs = {interact = true, tp = true},
|
||||
func = tphr_send
|
||||
})
|
||||
|
||||
@ -320,14 +362,15 @@ minetest.register_chatcommand("tpe", {
|
||||
|
||||
minetest.register_chatcommand("tpy", {
|
||||
description = "Accept teleport requests from another player",
|
||||
privs = {interact=true},
|
||||
privs = {interact = true, tp = true},
|
||||
func = tpr_accept
|
||||
})
|
||||
|
||||
minetest.register_chatcommand("tpn", {
|
||||
description = "Deny teleport requests from another player",
|
||||
privs = {interact=true},
|
||||
privs = {interact = true, tp = true},
|
||||
func = tpr_deny
|
||||
})
|
||||
|
||||
-- Log
|
||||
minetest.log("info", "[Teleport Request] TPS Teleport v" .. version .. " Loaded.")
|
||||
|
Loading…
Reference in New Issue
Block a user