Small changes

Completed 2 tasks from the TODO list.
See the "README.md" changes commit.
This commit is contained in:
Panquesito7 2019-07-08 20:23:57 -05:00 committed by GitHub
parent e102f4f18a
commit c921f786d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,7 +1,9 @@
-- Originally Teleport Request by Traxie21 and released with the WTFPL license --[[
-- https://forum.minetest.net/viewtopic.php?id=4457 Originally made by Traxie21 and released with the WTFPL license.
-- Updates by Zeno and ChaosWormz https://forum.minetest.net/viewtopic.php?id=4457
-- New release by RobbieF under new mod: tps_teleport - http://blog.minetest.tv/teleport-request/ Updates by Zeno and ChaosWormz
New release by RobbieF under new mod: tps_teleport - http://blog.minetest.tv/teleport-request/
--]]
local timeout_delay = 60 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 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 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", { minetest.register_privilege("tp_admin", {
description = "Admin overrides for tps_teleport.", description = "Admin overrides for tps_teleport.",
give_to_singleplayer=false give_to_singleplayer = false,
give_to_admin = true,
}) })
minetest.register_privilege("tp_tpc", { minetest.register_privilege("tp_tpc", {
description = "Allow player to teleport to coordinates (if permitted by area protection).", 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) local function find_free_position_near(pos)
@ -63,7 +73,21 @@ local function parti2(pos)
end end
-- Teleport Request System -- 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 if receiver == "" then
minetest.chat_send_player(sender, "Usage: /tpr <Player name>") minetest.chat_send_player(sender, "Usage: /tpr <Player name>")
return 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.') 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. -- Write name values to list and clear old values.
if not minetest.check_player_privs(sender, {tp_admin = true}) then
tpr_list[receiver] = sender tpr_list[receiver] = sender
-- Teleport timeout delay -- Teleport timeout delay
minetest.after(timeout_delay, function(name) minetest.after(timeout_delay, function(name)
@ -86,8 +111,22 @@ local function tpr_send(sender, receiver)
end end
end, sender) end, sender)
end 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 if receiver == "" then
minetest.chat_send_player(sender, "Usage: /tphr <Player name>") minetest.chat_send_player(sender, "Usage: /tphr <Player name>")
return 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.') 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. -- Write name values to list and clear old values.
if not minetest.check_player_privs(sender, {tp_admin = true}) then
tphr_list[receiver] = sender tphr_list[receiver] = sender
-- Teleport timeout delay -- Teleport timeout delay
minetest.after(timeout_delay, function(name) minetest.after(timeout_delay, function(name)
@ -110,8 +150,9 @@ local function tphr_send(sender, receiver)
end end
end, sender) end, sender)
end end
end
local function tpc_send(player,coordinates) function tpc_send(player,coordinates)
local posx,posy,posz = string.match(coordinates, "^(-?%d+), (-?%d+), (-?%d+)$") local posx,posy,posz = string.match(coordinates, "^(-?%d+), (-?%d+), (-?%d+)$")
local pname = minetest.get_player_by_name(player) 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 -- Admin user (priv "tp_admin") overrides all protection
if minetest.check_player_privs(pname, {tp_admin=true}) then if minetest.check_player_privs(pname, {tp_admin=true}) then
minetest.chat_send_player(player, 'Teleporting to '..posx..','..posy..','..posz) 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}) minetest.sound_play("whoosh", {pos = target_coords, gain = 0.5, max_hear_distance = 10})
--parti2(target_coords) --parti2(target_coords)
else else
if minetest.check_player_privs(pname, {tp_tpc=true}) then if minetest.check_player_privs(pname, {tp_tpc=true}) then
local protected = minetest.is_protected(target_coords,pname) local protected = minetest.is_protected(target_coords,pname)
if protected then 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) 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, ", "))) minetest.chat_send_player(player,("Error: %s is protected by %s."):format(minetest.pos_to_string(target_coords),table.concat(owners, ", ")))
return return
end end
end end
minetest.chat_send_player(player, 'Teleporting to '..posx..','..posy..','..posz) 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}) minetest.sound_play("whoosh", {pos = target_coords, gain = 0.5, max_hear_distance = 10})
--parti2(target_coords) --parti2(target_coords)
else else
@ -164,6 +205,7 @@ local function tpc_send(player,coordinates)
end end
local function tpr_deny(name) local function tpr_deny(name)
if minetest.check_player_privs(name, {tp_admin = true}) then return end
if tpr_list[name] then if tpr_list[name] then
minetest.chat_send_player(tpr_list[name], 'Teleport request denied.') minetest.chat_send_player(tpr_list[name], 'Teleport request denied.')
tpr_list[name] = nil 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(name2, "Request Accepted!")
minetest.chat_send_player(name, chatmsg) minetest.chat_send_player(name, chatmsg)
local target_coords=source:getpos() local target_coords=source:get_pos()
target:setpos(find_free_position_near(target_coords)) target:set_pos(find_free_position_near(target_coords))
minetest.sound_play("whoosh", {pos = target_coords, gain = 0.5, max_hear_distance = 10}) minetest.sound_play("whoosh", {pos = target_coords, gain = 0.5, max_hear_distance = 10})
--parti2(target_coords) --parti2(target_coords)
end end
@ -252,7 +294,7 @@ local function tpj(player,param)
minetest.chat_send_player(player, "You cannot teleport to a location outside the map!") minetest.chat_send_player(player, "You cannot teleport to a location outside the map!")
return return
end 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}) minetest.sound_play("whoosh", {pos = target_coords, gain = 0.5, max_hear_distance = 10})
--parti2(target_coords) --parti2(target_coords)
end end
@ -287,14 +329,14 @@ end
minetest.register_chatcommand("tpr", { minetest.register_chatcommand("tpr", {
description = "Request teleport to another player", description = "Request teleport to another player",
params = "<playername> | leave playername empty to see help message", params = "<playername> | leave playername empty to see help message",
privs = {interact=true}, privs = {interact = true, tp = true},
func = tpr_send func = tpr_send
}) })
minetest.register_chatcommand("tphr", { minetest.register_chatcommand("tphr", {
description = "Request player to teleport to you", description = "Request player to teleport to you",
params = "<playername> | leave playername empty to see help message", params = "<playername> | leave playername empty to see help message",
privs = {interact=true}, privs = {interact = true, tp = true},
func = tphr_send func = tphr_send
}) })
@ -320,14 +362,15 @@ minetest.register_chatcommand("tpe", {
minetest.register_chatcommand("tpy", { minetest.register_chatcommand("tpy", {
description = "Accept teleport requests from another player", description = "Accept teleport requests from another player",
privs = {interact=true}, privs = {interact = true, tp = true},
func = tpr_accept func = tpr_accept
}) })
minetest.register_chatcommand("tpn", { minetest.register_chatcommand("tpn", {
description = "Deny teleport requests from another player", description = "Deny teleport requests from another player",
privs = {interact=true}, privs = {interact = true, tp = true},
func = tpr_deny func = tpr_deny
}) })
-- Log
minetest.log("info", "[Teleport Request] TPS Teleport v" .. version .. " Loaded.") minetest.log("info", "[Teleport Request] TPS Teleport v" .. version .. " Loaded.")