forked from minetest-mods/MoreMesecons
Add a distance restriction for the teleporter
This commit is contained in:
parent
65abb2a65b
commit
7458da8f62
|
@ -10,7 +10,7 @@ local register = function(pos)
|
||||||
end
|
end
|
||||||
|
|
||||||
local teleport_nearest = function(pos)
|
local teleport_nearest = function(pos)
|
||||||
local MAX_DISTANCE = 8
|
local MAX_DISTANCE = 50
|
||||||
|
|
||||||
-- Search the nearest player
|
-- Search the nearest player
|
||||||
local nearest = nil
|
local nearest = nil
|
||||||
|
@ -27,22 +27,22 @@ local teleport_nearest = function(pos)
|
||||||
-- Search other teleporter and teleport
|
-- Search other teleporter and teleport
|
||||||
if not minetest.registered_nodes["moremesecons_teleporter:teleporter"] then return end
|
if not minetest.registered_nodes["moremesecons_teleporter:teleporter"] then return end
|
||||||
|
|
||||||
|
local newpos = {}
|
||||||
for i = 1, #teleporters do
|
for i = 1, #teleporters do
|
||||||
if minetest.get_node(teleporters[i]).name == "moremesecons_teleporter:teleporter" then
|
if minetest.get_node(teleporters[i]).name == "moremesecons_teleporter:teleporter" then
|
||||||
if teleporters[i].y == pos.y and teleporters[i].x == pos.x and teleporters[i].z ~= pos.z then
|
if teleporters[i].y == pos.y and teleporters[i].x == pos.x and teleporters[i].z ~= pos.z then
|
||||||
nearest:setpos({x=teleporters[i].x, y=teleporters[i].y+1, z=teleporters[i].z})
|
newpos = {x=teleporters[i].x, y=teleporters[i].y+1, z=teleporters[i].z}
|
||||||
minetest.log("action", "Player "..nearest:get_player_name().." was teleport with a MoreMesecons Teleporter.")
|
|
||||||
return
|
|
||||||
elseif teleporters[i].z == pos.z and teleporters[i].x == pos.x and teleporters[i].y ~= pos.y then
|
elseif teleporters[i].z == pos.z and teleporters[i].x == pos.x and teleporters[i].y ~= pos.y then
|
||||||
nearest:setpos({x=teleporters[i].x, y=teleporters[i].y+1, z=teleporters[i].z})
|
newpos = {x=teleporters[i].x, y=teleporters[i].y+1, z=teleporters[i].z}
|
||||||
minetest.log("action", "Player "..nearest:get_player_name().." was teleport with a MoreMesecons Teleporter.")
|
|
||||||
return
|
|
||||||
elseif teleporters[i].z == pos.z and teleporters[i].y == pos.y and teleporters[i].x ~= pos.x then
|
elseif teleporters[i].z == pos.z and teleporters[i].y == pos.y and teleporters[i].x ~= pos.x then
|
||||||
nearest:setpos({x=teleporters[i].x, y=teleporters[i].y+1, z=teleporters[i].z})
|
newpos = {x=teleporters[i].x, y=teleporters[i].y+1, z=teleporters[i].z}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if newpos.x then
|
||||||
|
if vector.distance(pos, nearest:getpos()) > MAX_DISTANCE then return end
|
||||||
|
nearest:moveto(newpos)
|
||||||
minetest.log("action", "Player "..nearest:get_player_name().." was teleport with a MoreMesecons Teleporter.")
|
minetest.log("action", "Player "..nearest:get_player_name().." was teleport with a MoreMesecons Teleporter.")
|
||||||
return
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user