mirror of
https://github.com/minetest-mods/MoreMesecons.git
synced 2024-12-29 17:07:35 +01:00
slight change in the teleporters file and add luacontroller detection
This commit is contained in:
parent
a2f59a0b6d
commit
d095fecefa
@ -57,11 +57,7 @@ local function get_selection_formspec(pname, selected_template)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function is_luacontroller(pos)
|
local function is_luacontroller(pos)
|
||||||
local node = minetest.get_node(pos)
|
return string.match(minetest.get_node(pos).name, "mesecons_luacontroller:luacontroller%d%d%d%d")
|
||||||
if node.name ~= ":luacontroller" then
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.register_tool("moremesecons_luacontroller_tool:luacontroller_template_tool", {
|
minetest.register_tool("moremesecons_luacontroller_tool:luacontroller_template_tool", {
|
||||||
|
@ -3,8 +3,7 @@ local teleporters_rids = {}
|
|||||||
|
|
||||||
|
|
||||||
local register = function(pos)
|
local register = function(pos)
|
||||||
local RID = vector.get_data_from_pos(teleporters_rids, pos.z,pos.y,pos.x)
|
if not vector.get_data_from_pos(teleporters_rids, pos.z,pos.y,pos.x) then
|
||||||
if not RID then
|
|
||||||
table.insert(teleporters, pos)
|
table.insert(teleporters, pos)
|
||||||
vector.set_data_to_pos(teleporters_rids, pos.z,pos.y,pos.x, #teleporters)
|
vector.set_data_to_pos(teleporters_rids, pos.z,pos.y,pos.x, #teleporters)
|
||||||
end
|
end
|
||||||
@ -13,7 +12,7 @@ end
|
|||||||
local teleport_nearest = function(pos)
|
local teleport_nearest = function(pos)
|
||||||
local MAX_TELEPORTATION_DISTANCE = 50
|
local MAX_TELEPORTATION_DISTANCE = 50
|
||||||
local MAX_PLAYER_DISTANCE = 25
|
local MAX_PLAYER_DISTANCE = 25
|
||||||
|
|
||||||
-- Search the nearest player
|
-- Search the nearest player
|
||||||
local nearest = nil
|
local nearest = nil
|
||||||
local min_distance = MAX_PLAYER_DISTANCE
|
local min_distance = MAX_PLAYER_DISTANCE
|
||||||
@ -25,15 +24,15 @@ local teleport_nearest = function(pos)
|
|||||||
nearest = player
|
nearest = player
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if not nearest then
|
if not nearest then
|
||||||
-- If there is no nearest player (maybe too far...)
|
-- If there is no nearest player (maybe too far...)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
-- 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 = {}
|
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
|
||||||
@ -56,7 +55,7 @@ local teleport_nearest = function(pos)
|
|||||||
newpos = {x=pos.x, y=pos.y+1, z=pos.z} -- If newpos doesn't exist, teleport on the actual teleporter.
|
newpos = {x=pos.x, y=pos.y+1, z=pos.z} -- If newpos doesn't exist, teleport on the actual teleporter.
|
||||||
end
|
end
|
||||||
nearest:moveto(newpos)
|
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.")
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
@ -89,9 +88,10 @@ minetest.register_node("moremesecons_teleporter:teleporter", {
|
|||||||
|
|
||||||
minetest.register_abm({
|
minetest.register_abm({
|
||||||
nodenames = {"moremesecons_teleporter:teleporter"},
|
nodenames = {"moremesecons_teleporter:teleporter"},
|
||||||
interval=1,
|
interval=5,
|
||||||
chance=1,
|
chance=1,
|
||||||
action = function(pos)
|
catch_up = false,
|
||||||
|
action = function(pos)
|
||||||
register(pos)
|
register(pos)
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user