Add a new function

This commit improves "/tpy" command:
When a player receives more than 1 teleport request and types /tpy, a message will be sent to the receiver telling him the list of the requests sent to him. He must use the player name as a param, so, he will teleport to the specified player (e.g.: /tpy foo).

THIS IS AN UNTESTED FUNCTION. IT MAY RESULT IN A CRASH OR MAY CAUSE ANOTHER BUGS. CHECK IT AT YOUR OWN RISK.
This commit is contained in:
Panquesito7 2019-07-31 19:43:40 -05:00 committed by GitHub
parent 9aa68848c8
commit 2f31f0c317
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -165,7 +165,6 @@ function tpr_send(sender, receiver)
minetest.chat_send_player(receiver, S("@1 is requesting to teleport to you. /tpy to accept", sender))
minetest.chat_send_player(sender, S("Teleport request sent! It will timeout in @1 seconds", timeout_delay))
-- Write name values to list and clear old values.
tpr_list[receiver] = sender
-- Teleport timeout delay
@ -206,7 +205,6 @@ function tphr_send(sender, receiver)
minetest.chat_send_player(receiver, S("@1 is requesting that you teleport to them. /tpy to accept; /tpn to deny", sender))
minetest.chat_send_player(sender, S("Teleport request sent! It will timeout in @1 seconds", timeout_delay))
-- Write name values to list and clear old values.
tphr_list[receiver] = sender
-- Teleport timeout delay
@ -306,6 +304,25 @@ function tpr_accept(name, param)
target = minetest.get_player_by_name(name)
chatmsg = S("You are teleporting to @1.", name2)
tphr_list[name] = nil
-- Let the player choose which player to teleport to when there are multiple requests.
-- THIS IS AN UNTESTED FUNCTION. CHECK IT AT YOUR OWN RISK.
elseif tpr_list[name] > 1 then
param = param:lower()
minetest.chat_send_player(name, S("Use /tpy <player> and choose a player to teleport to:"))
local tp = {}
for key, value in pairs(tpr_list) do
table.insert(tp, key)
end
if param == "" then
minetest.chat_send_player(name, S("Use /tpy <player> and choose a player to teleport to:"))
for key, value in pairs(tpr_list) do
table.insert(tp, key)
end
end
-- Teleport player to the specified player
if tpr_list[param] then
tpr_teleport_player(param)
end
else
return
end