mirror of
https://github.com/minetest-mods/teleport-request.git
synced 2025-01-08 14:07:28 +01:00
Reformatted/indented source
This commit is contained in:
parent
42d4bc82e7
commit
2ae3d6932f
143
init.lua
143
init.lua
@ -16,56 +16,56 @@ local function tpr_send(name, param)
|
|||||||
|
|
||||||
--Register variables
|
--Register variables
|
||||||
|
|
||||||
sender = name
|
sender = name
|
||||||
receiver = param
|
receiver = param
|
||||||
value_carryover = param
|
value_carryover = param
|
||||||
--Check for empty parameter
|
|
||||||
|
|
||||||
if receiver == "" then
|
--Check for empty parameter
|
||||||
minetest.chat_send_player(sender, "Usage: /tpr <Player name>")
|
if receiver == "" then
|
||||||
return
|
minetest.chat_send_player(sender, "Usage: /tpr <Player name>")
|
||||||
end
|
return
|
||||||
|
end
|
||||||
|
|
||||||
--If paremeter is valid, Send teleport message and set the table.
|
--If paremeter is valid, Send teleport message and set the table.
|
||||||
|
|
||||||
if minetest.env:get_player_by_name(receiver) then
|
if minetest.env:get_player_by_name(receiver) then
|
||||||
minetest.chat_send_player(receiver, sender ..' is requesting to teleport to you. /tpy to accept.')
|
minetest.chat_send_player(receiver, sender ..' is requesting to teleport to you. /tpy to accept.')
|
||||||
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.
|
||||||
tpr_list[receiver] = nil
|
tpr_list[receiver] = nil
|
||||||
tpr_list[receiver] = sender
|
tpr_list[receiver] = sender
|
||||||
--Teleport timeout delay
|
--Teleport timeout delay
|
||||||
minetest.after(timeout_delay, reset_request)
|
minetest.after(timeout_delay, reset_request)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function tphr_send(name, param)
|
local function tphr_send(name, param)
|
||||||
|
|
||||||
--Register variables
|
--Register variables
|
||||||
|
|
||||||
sender2 = name
|
sender2 = name
|
||||||
receiver2 = param
|
receiver2 = param
|
||||||
value_carryover2 = param
|
value_carryover2 = param
|
||||||
--Check for empty parameter
|
--Check for empty parameter
|
||||||
|
|
||||||
if receiver2 == "" then
|
if receiver2 == "" then
|
||||||
minetest.chat_send_player(sender2, "Usage: /tphr <Player name>")
|
minetest.chat_send_player(sender2, "Usage: /tphr <Player name>")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
--If paremeter is valid, Send teleport message and set the table.
|
--If paremeter is valid, Send teleport message and set the table.
|
||||||
|
|
||||||
if minetest.env:get_player_by_name(receiver2) then
|
if minetest.env:get_player_by_name(receiver2) then
|
||||||
minetest.chat_send_player(receiver2, sender2 ..' is requesting that you teleport to them. /tpy to accept.')
|
minetest.chat_send_player(receiver2, sender2 ..' is requesting that you teleport to them. /tpy to accept.')
|
||||||
minetest.chat_send_player(sender2, 'Teleport request sent! It will time out in '.. timeout_delay ..' seconds.')
|
minetest.chat_send_player(sender2, '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.
|
||||||
tphr_list[receiver2] = nil
|
tphr_list[receiver2] = nil
|
||||||
tphr_list[receiver2] = sender2
|
tphr_list[receiver2] = sender2
|
||||||
--Teleport timeout delay
|
--Teleport timeout delay
|
||||||
minetest.after(timeout_delay, reset_request2)
|
minetest.after(timeout_delay, reset_request2)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -76,8 +76,7 @@ function reset_request(name)
|
|||||||
--A check to prevent crashing
|
--A check to prevent crashing
|
||||||
|
|
||||||
if tpr_list[value_carryover] ~= nil then
|
if tpr_list[value_carryover] ~= nil then
|
||||||
tpr_list[value_carryover] = nil
|
tpr_list[value_carryover] = nil
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
@ -87,24 +86,21 @@ function reset_request2(name)
|
|||||||
--A check to prevent crashing
|
--A check to prevent crashing
|
||||||
|
|
||||||
if tphr_list[value_carryover2] ~= nil then
|
if tphr_list[value_carryover2] ~= nil then
|
||||||
tphr_list[value_carryover2] = nil
|
tphr_list[value_carryover2] = nil
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function tpr_deny(name)
|
function tpr_deny(name)
|
||||||
sender = tpr_list[value_carryover]
|
sender = tpr_list[value_carryover]
|
||||||
if tpr_list[value_carryover] ~= nil then
|
if tpr_list[value_carryover] ~= nil then
|
||||||
tpr_list[value_carryover] = nil
|
tpr_list[value_carryover] = nil
|
||||||
minetest.chat_send_player(sender, 'Teleport request denied :C')
|
minetest.chat_send_player(sender, 'Teleport request denied :C')
|
||||||
|
|
||||||
end
|
end
|
||||||
sender2 = tphr_list[value_carryover2]
|
sender2 = tphr_list[value_carryover2]
|
||||||
if tphr_list[value_carryover2] ~= nil then
|
if tphr_list[value_carryover2] ~= nil then
|
||||||
tphr_list[value_carryover2] = nil
|
tphr_list[value_carryover2] = nil
|
||||||
minetest.chat_send_player(sender2, 'Teleport request denied :C')
|
minetest.chat_send_player(sender2, 'Teleport request denied :C')
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
--Teleport Accept Systems
|
--Teleport Accept Systems
|
||||||
@ -115,25 +111,24 @@ local function tpr_accept(name, param)
|
|||||||
|
|
||||||
receiver = name
|
receiver = name
|
||||||
sender = tpr_list[name]
|
sender = tpr_list[name]
|
||||||
|
|
||||||
receiver = name
|
receiver = name
|
||||||
sender2 = tphr_list[name]
|
sender2 = tphr_list[name]
|
||||||
--Check to prevent constant teleporting.
|
--Check to prevent constant teleporting.
|
||||||
|
|
||||||
if tpr_list[name] == nil and tphr_list[name] == nil then
|
if tpr_list[name] == nil and tphr_list[name] == nil then
|
||||||
minetest.chat_send_player(name, "Usage: /tpy allows you to accept teleport requests sent to you by other players")
|
minetest.chat_send_player(name, "Usage: /tpy allows you to accept teleport requests sent to you by other players")
|
||||||
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
--Teleport Accept system
|
--Teleport Accept system
|
||||||
--Check to ensure name is valid, then send appropriate chat messages
|
--Check to ensure name is valid, then send appropriate chat messages
|
||||||
|
|
||||||
if tpr_list[name] then
|
if tpr_list[name] then
|
||||||
minetest.chat_send_player(tpr_list[receiver], "Request Accepted!")
|
minetest.chat_send_player(tpr_list[receiver], "Request Accepted!")
|
||||||
minetest.chat_send_player(receiver, sender..' is teleporting to you.')
|
minetest.chat_send_player(receiver, sender..' is teleporting to you.')
|
||||||
|
|
||||||
--Code here copied from Celeron-55's /teleport command. Thanks Celeron!
|
--Code here copied from Celeron-55's /teleport command. Thanks Celeron!
|
||||||
|
|
||||||
local function find_free_position_near(pos)
|
local function find_free_position_near(pos)
|
||||||
local tries = {
|
local tries = {
|
||||||
@ -156,30 +151,30 @@ local function tpr_accept(name, param)
|
|||||||
|
|
||||||
local requester = minetest.env:get_player_by_name(sender)
|
local requester = minetest.env:get_player_by_name(sender)
|
||||||
local accepter = minetest.env:get_player_by_name(name)
|
local accepter = minetest.env:get_player_by_name(name)
|
||||||
|
|
||||||
-- Could happen if either player disconnects; if so just abort
|
-- Could happen if either player disconnects; if so just abort
|
||||||
if requester == nil or accepter == nil then
|
if requester == nil or accepter == nil then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local p = nil
|
local p = nil
|
||||||
p = accepter:getpos()
|
p = accepter:getpos()
|
||||||
p = find_free_position_near(p)
|
p = find_free_position_near(p)
|
||||||
requester:setpos(p)
|
requester:setpos(p)
|
||||||
|
|
||||||
-- Set name values to nil to prevent re-teleporting on the same request.
|
-- Set name values to nil to prevent re-teleporting on the same request.
|
||||||
|
|
||||||
tpr_list[name] = nil
|
tpr_list[name] = nil
|
||||||
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
--Teleport Here accepting system
|
--Teleport Here accepting system
|
||||||
|
|
||||||
if tphr_list[name] then
|
if tphr_list[name] then
|
||||||
minetest.chat_send_player(tphr_list[receiver], "Request Accepted!")
|
minetest.chat_send_player(tphr_list[receiver], "Request Accepted!")
|
||||||
minetest.chat_send_player(receiver, 'you are teleporting to '..sender2..'.')
|
minetest.chat_send_player(receiver, 'you are teleporting to '..sender2..'.')
|
||||||
|
|
||||||
--Code here copied from Celeron-55's /teleport command. Thanks Celeron!
|
--Code here copied from Celeron-55's /teleport command. Thanks Celeron!
|
||||||
|
|
||||||
local function find_free_position_near(pos)
|
local function find_free_position_near(pos)
|
||||||
local tries = {
|
local tries = {
|
||||||
@ -202,11 +197,11 @@ local function tpr_accept(name, param)
|
|||||||
|
|
||||||
local requester = minetest.env:get_player_by_name(sender2)
|
local requester = minetest.env:get_player_by_name(sender2)
|
||||||
local accepter = minetest.env:get_player_by_name(name)
|
local accepter = minetest.env:get_player_by_name(name)
|
||||||
|
|
||||||
-- Could happen if either player disconnects; if so just abort
|
-- Could happen if either player disconnects; if so just abort
|
||||||
if requester == nil or accepter == nil then
|
if requester == nil or accepter == nil then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local p = nil
|
local p = nil
|
||||||
p = requester:getpos()
|
p = requester:getpos()
|
||||||
@ -229,34 +224,34 @@ tphr_list = {}
|
|||||||
--Initalize Permissions.
|
--Initalize Permissions.
|
||||||
|
|
||||||
minetest.register_privilege("tpr_admin", {
|
minetest.register_privilege("tpr_admin", {
|
||||||
description = "Permission to override teleport to other players. UNFINISHED",
|
description = "Permission to override teleport to other players. UNFINISHED",
|
||||||
give_to_singleplayer = true
|
give_to_singleplayer = true
|
||||||
})
|
})
|
||||||
|
|
||||||
--Initalize Commands.
|
--Initalize Commands.
|
||||||
|
|
||||||
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},
|
||||||
func = tpr_send
|
func = tpr_send
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_chatcommand("tphr", {
|
minetest.register_chatcommand("tphr", {
|
||||||
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},
|
||||||
func = tphr_send
|
func = tphr_send
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_chatcommand("tpy", {
|
minetest.register_chatcommand("tpy", {
|
||||||
description = "Accept teleport requests from another player",
|
description = "Accept teleport requests from another player",
|
||||||
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",
|
||||||
func = tpr_deny
|
func = tpr_deny
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user