mirror of
https://github.com/minetest-mods/teleport-request.git
synced 2024-08-20 21:34:06 +02:00
Reformatted/indented source
This commit is contained in:
parent
42d4bc82e7
commit
2ae3d6932f
121
init.lua
121
init.lua
@ -16,56 +16,56 @@ local function tpr_send(name, param)
|
||||
|
||||
--Register variables
|
||||
|
||||
sender = name
|
||||
receiver = param
|
||||
sender = name
|
||||
receiver = param
|
||||
value_carryover = param
|
||||
--Check for empty parameter
|
||||
|
||||
if receiver == "" then
|
||||
minetest.chat_send_player(sender, "Usage: /tpr <Player name>")
|
||||
return
|
||||
end
|
||||
--Check for empty parameter
|
||||
if receiver == "" then
|
||||
minetest.chat_send_player(sender, "Usage: /tpr <Player name>")
|
||||
return
|
||||
end
|
||||
|
||||
--If paremeter is valid, Send teleport message and set the table.
|
||||
|
||||
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(sender, 'Teleport request sent! It will time out in '.. timeout_delay ..' seconds.')
|
||||
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(sender, 'Teleport request sent! It will time out in '.. timeout_delay ..' seconds.')
|
||||
|
||||
--Write name values to list and clear old values.
|
||||
tpr_list[receiver] = nil
|
||||
tpr_list[receiver] = sender
|
||||
--Write name values to list and clear old values.
|
||||
tpr_list[receiver] = nil
|
||||
tpr_list[receiver] = sender
|
||||
--Teleport timeout delay
|
||||
minetest.after(timeout_delay, reset_request)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function tphr_send(name, param)
|
||||
|
||||
--Register variables
|
||||
|
||||
sender2 = name
|
||||
receiver2 = param
|
||||
sender2 = name
|
||||
receiver2 = param
|
||||
value_carryover2 = param
|
||||
--Check for empty parameter
|
||||
|
||||
if receiver2 == "" then
|
||||
minetest.chat_send_player(sender2, "Usage: /tphr <Player name>")
|
||||
return
|
||||
end
|
||||
if receiver2 == "" then
|
||||
minetest.chat_send_player(sender2, "Usage: /tphr <Player name>")
|
||||
return
|
||||
end
|
||||
|
||||
--If paremeter is valid, Send teleport message and set the table.
|
||||
|
||||
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(sender2, 'Teleport request sent! It will time out in '.. timeout_delay ..' seconds.')
|
||||
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(sender2, 'Teleport request sent! It will time out in '.. timeout_delay ..' seconds.')
|
||||
|
||||
--Write name values to list and clear old values.
|
||||
tphr_list[receiver2] = nil
|
||||
tphr_list[receiver2] = sender2
|
||||
--Write name values to list and clear old values.
|
||||
tphr_list[receiver2] = nil
|
||||
tphr_list[receiver2] = sender2
|
||||
--Teleport timeout delay
|
||||
minetest.after(timeout_delay, reset_request2)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@ -76,8 +76,7 @@ function reset_request(name)
|
||||
--A check to prevent crashing
|
||||
|
||||
if tpr_list[value_carryover] ~= nil then
|
||||
tpr_list[value_carryover] = nil
|
||||
|
||||
tpr_list[value_carryover] = nil
|
||||
end
|
||||
|
||||
end
|
||||
@ -87,24 +86,21 @@ function reset_request2(name)
|
||||
--A check to prevent crashing
|
||||
|
||||
if tphr_list[value_carryover2] ~= nil then
|
||||
tphr_list[value_carryover2] = nil
|
||||
|
||||
tphr_list[value_carryover2] = nil
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
function tpr_deny(name)
|
||||
sender = tpr_list[value_carryover]
|
||||
sender = tpr_list[value_carryover]
|
||||
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')
|
||||
|
||||
end
|
||||
sender2 = tphr_list[value_carryover2]
|
||||
sender2 = tphr_list[value_carryover2]
|
||||
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')
|
||||
|
||||
end
|
||||
end
|
||||
--Teleport Accept Systems
|
||||
@ -121,8 +117,7 @@ local function tpr_accept(name, param)
|
||||
--Check to prevent constant teleporting.
|
||||
|
||||
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
|
||||
end
|
||||
|
||||
@ -133,7 +128,7 @@ local function tpr_accept(name, param)
|
||||
minetest.chat_send_player(tpr_list[receiver], "Request Accepted!")
|
||||
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 tries = {
|
||||
@ -158,9 +153,9 @@ local function tpr_accept(name, param)
|
||||
local accepter = minetest.env:get_player_by_name(name)
|
||||
|
||||
-- Could happen if either player disconnects; if so just abort
|
||||
if requester == nil or accepter == nil then
|
||||
return
|
||||
end
|
||||
if requester == nil or accepter == nil then
|
||||
return
|
||||
end
|
||||
|
||||
local p = nil
|
||||
p = accepter:getpos()
|
||||
@ -168,8 +163,8 @@ local function tpr_accept(name, param)
|
||||
requester:setpos(p)
|
||||
|
||||
-- Set name values to nil to prevent re-teleporting on the same request.
|
||||
|
||||
tpr_list[name] = nil
|
||||
|
||||
return
|
||||
end
|
||||
|
||||
@ -179,7 +174,7 @@ local function tpr_accept(name, param)
|
||||
minetest.chat_send_player(tphr_list[receiver], "Request Accepted!")
|
||||
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 tries = {
|
||||
@ -203,10 +198,10 @@ local function tpr_accept(name, param)
|
||||
local requester = minetest.env:get_player_by_name(sender2)
|
||||
local accepter = minetest.env:get_player_by_name(name)
|
||||
|
||||
-- Could happen if either player disconnects; if so just abort
|
||||
if requester == nil or accepter == nil then
|
||||
return
|
||||
end
|
||||
-- Could happen if either player disconnects; if so just abort
|
||||
if requester == nil or accepter == nil then
|
||||
return
|
||||
end
|
||||
|
||||
local p = nil
|
||||
p = requester:getpos()
|
||||
@ -229,34 +224,34 @@ tphr_list = {}
|
||||
--Initalize Permissions.
|
||||
|
||||
minetest.register_privilege("tpr_admin", {
|
||||
description = "Permission to override teleport to other players. UNFINISHED",
|
||||
give_to_singleplayer = true
|
||||
description = "Permission to override teleport to other players. UNFINISHED",
|
||||
give_to_singleplayer = true
|
||||
})
|
||||
|
||||
--Initalize Commands.
|
||||
|
||||
minetest.register_chatcommand("tpr", {
|
||||
description = "Request teleport to another player",
|
||||
params = "<playername> | leave playername empty to see help message",
|
||||
privs = {interact=true},
|
||||
func = tpr_send
|
||||
description = "Request teleport to another player",
|
||||
params = "<playername> | leave playername empty to see help message",
|
||||
privs = {interact=true},
|
||||
func = tpr_send
|
||||
|
||||
})
|
||||
|
||||
minetest.register_chatcommand("tphr", {
|
||||
description = "Request teleport to another player",
|
||||
params = "<playername> | leave playername empty to see help message",
|
||||
privs = {interact=true},
|
||||
func = tphr_send
|
||||
description = "Request teleport to another player",
|
||||
params = "<playername> | leave playername empty to see help message",
|
||||
privs = {interact=true},
|
||||
func = tphr_send
|
||||
|
||||
})
|
||||
|
||||
minetest.register_chatcommand("tpy", {
|
||||
description = "Accept teleport requests from another player",
|
||||
func = tpr_accept
|
||||
description = "Accept teleport requests from another player",
|
||||
func = tpr_accept
|
||||
})
|
||||
|
||||
minetest.register_chatcommand("tpn", {
|
||||
description = "Deny teleport requests from another player",
|
||||
func = tpr_deny
|
||||
description = "Deny teleport requests from another player",
|
||||
func = tpr_deny
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user