Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tp snipe simple #48

Merged
merged 7 commits into from
Aug 9, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 78 additions & 14 deletions functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ local function send_message(player, message)
end
end

local function pending_request(name)
return tp.tpr_list[name] or tp.tphr_list[name] or tp.tpc_list[name]
end

local map_size = 30912
function tp.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
Expand Down Expand Up @@ -262,6 +266,26 @@ function tp.tpr_send(sender, receiver)
end
end

local receiver_request = pending_request(receiver)
if receiver_request or tp.tpn_list[receiver] then
if receiver_request == sender then
send_message(sender, S("You have already sent a request to @1, wait for them to respond before sending another.", receiver))
else
send_message(sender, S("@1 is dealing with another request right now, try again later.", receiver))
end
return
end

local sender_request = pending_request(sender)
if sender_request or tp.tpn_list[sender] then
if sender_request == receiver then
send_message(sender, S("@1 has already sent a request to you, cancel it with /tpn before sending a request to them.", receiver))
else
send_message(sender, S("You are dealing with another request right now, cancel it with /tpn before sending another request.", receiver))
end
return
end

send_message(receiver, S("@1 is requesting to teleport to you. /tpy to accept.", sender))
send_message(sender, S("Teleport request sent! It will timeout in @1 seconds.", tp.timeout_delay))

Expand Down Expand Up @@ -369,6 +393,26 @@ function tp.tphr_send(sender, receiver)
end
end

local receiver_request = pending_request(receiver)
if receiver_request or tp.tpn_list[receiver] then
if receiver_request == sender then
send_message(sender, S("You have already sent a request to @1, wait for them to respond before sending another.", receiver))
else
send_message(sender, S("@1 is dealing with another request right now, try again later.", receiver))
end
return
end

local sender_request = pending_request(sender)
if sender_request or tp.tpn_list[sender] then
if sender_request == receiver then
send_message(sender, S("@1 has already sent a request to you, cancel it with /tpn before sending a request to them.", receiver))
else
send_message(sender, S("You are dealing with another request right now, cancel it with /tpn before sending another request.", receiver))
end
return
end

send_message(receiver, S("@1 is requesting that you teleport to them. /tpy to accept; /tpn to deny.", sender))
send_message(sender, S("Teleport request sent! It will timeout in @1 seconds.", tp.timeout_delay))

Expand Down Expand Up @@ -425,25 +469,47 @@ function tp.tpc_send(sender, coordinates)
if protected then
if minetest.get_modpath("areas") then
for _, area in pairs(areas:getAreasAtPos(target_coords)) do
if minetest.get_player_by_name(area.owner) then -- Check if area owners are online
local receiver = area.owner

if minetest.get_player_by_name(receiver) then -- Check if area owners are online

local receiver_request = pending_request(receiver)
if receiver_request or tp.tpn_list[receiver] then
if receiver_request == sender then
send_message(sender, S("You have already sent a request to @1, wait for them to respond before sending another.", receiver))
else
send_message(sender, S("@1 is dealing with another request right now, try again later.", receiver))
end
return
end

local sender_request = pending_request(sender)
if sender_request or tp.tpn_list[sender] then
if sender_request == receiver then
send_message(sender, S("@1 has already sent a request to you, cancel it with /tpn before sending a request to them.", receiver))
else
send_message(sender, S("You are dealing with another request right now, cancel it with /tpn before sending another request.", receiver))
end
return
end

if tpc_target_coords then
old_tpc_target_coords = tpc_target_coords
old_tpc_target_coords[area.owner] = tpc_target_coords[area.owner]
old_tpc_target_coords[receiver] = tpc_target_coords[receiver]

tpc_target_coords[area.owner] = {x=posx, y=posy, z=posz}
tpc_target_coords[receiver] = {x=posx, y=posy, z=posz}
else
tpc_target_coords = {x=posx, y=posy, z=posz}
tpc_target_coords[area.owner] = {x=posx, y=posy, z=posz}
tpc_target_coords[receiver] = {x=posx, y=posy, z=posz}
end

send_message(sender, S("Area request sent! Waiting for @1 to accept your request." ..
" It will timeout in @2 seconds.", table.concat(areas:getNodeOwners(tpc_target_coords[area.owner]), S(", or ")), tp.timeout_delay))
send_message(area.owner, S("@1 is requesting to teleport to a protected area" ..
" of yours @2.", sender, minetest.pos_to_string(tpc_target_coords[area.owner])))
" It will timeout in @2 seconds.", table.concat(areas:getNodeOwners(tpc_target_coords[receiver]), S(", or ")), tp.timeout_delay))
send_message(receiver, S("@1 is requesting to teleport to a protected area" ..
" of yours @2.", sender, minetest.pos_to_string(tpc_target_coords[receiver])))

tp.tpc_list[area.owner] = sender
tp.tpn_list[sender] = area.owner
tp.tpc_list[receiver] = sender
tp.tpn_list[sender] = receiver

minetest.after(tp.timeout_delay, function(sender_name, receiver_name)
if tp.tpc_list[receiver_name] and tp.tpn_list[sender_name] then
Expand All @@ -454,7 +520,7 @@ function tp.tpc_send(sender, coordinates)
send_message(receiver_name, S("Request timed-out."))
return
end
end, sender, area.owner)
end, sender, receiver)
else
minetest.record_protection_violation(target_coords, sender)
end
Expand All @@ -476,8 +542,7 @@ function tp.tpc_send(sender, coordinates)
end

function tp.tpr_deny(name)
if not tp.tpr_list[name] and not tp.tphr_list[name]
and not tp.tpc_list[name] and not tp.tpn_list[name] then
if not pending_request(name) and not tp.tpn_list[name] then
send_message(name, S("Usage: /tpn allows you to deny teleport/area requests sent to you by other players."))
return
end
Expand Down Expand Up @@ -540,8 +605,7 @@ end
-- Teleport Accept Systems
function tp.tpr_accept(name)
-- Check to prevent constant teleporting
if not tp.tpr_list[name] and not tp.tphr_list[name]
and not tp.tpc_list[name] then
if not pending_request(name) then
send_message(name, S("Usage: /tpy allows you to accept teleport/area requests sent to you by other players."))
return
end
Expand Down