2022-05-05 16:57:53 +02:00
|
|
|
local side_texture = mesecon.texture.steel_block or "mesecons_detector_side.png"
|
|
|
|
|
2014-06-08 19:02:15 +02:00
|
|
|
local GET_COMMAND = "GET"
|
|
|
|
|
2012-12-08 22:28:46 +01:00
|
|
|
-- Object detector
|
2013-02-22 19:20:23 +01:00
|
|
|
-- Detects players in a certain radius
|
2012-12-08 22:28:46 +01:00
|
|
|
-- The radius can be specified in mesecons/settings.lua
|
|
|
|
|
2016-01-03 14:37:52 +01:00
|
|
|
local function object_detector_make_formspec(pos)
|
2017-03-13 21:13:57 +01:00
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
meta:set_string("formspec", "size[9,2.5]" ..
|
2013-02-22 19:20:23 +01:00
|
|
|
"field[0.3, 0;9,2;scanname;Name of player to scan for (empty for any):;${scanname}]"..
|
2014-01-19 14:12:34 +01:00
|
|
|
"field[0.3,1.5;4,2;digiline_channel;Digiline Channel (optional):;${digiline_channel}]"..
|
|
|
|
"button_exit[7,0.75;2,3;;Save]")
|
2013-02-22 19:20:23 +01:00
|
|
|
end
|
|
|
|
|
2022-02-12 20:12:12 +01:00
|
|
|
local function object_detector_on_receive_fields(pos, _, fields, sender)
|
2016-02-14 12:58:02 +01:00
|
|
|
if not fields.scanname or not fields.digiline_channel then return end
|
2014-04-30 14:44:47 +02:00
|
|
|
|
2017-03-13 21:13:57 +01:00
|
|
|
if minetest.is_protected(pos, sender:get_player_name()) then return end
|
|
|
|
|
2013-12-01 04:13:00 +01:00
|
|
|
local meta = minetest.get_meta(pos)
|
2013-02-22 19:20:23 +01:00
|
|
|
meta:set_string("scanname", fields.scanname)
|
|
|
|
meta:set_string("digiline_channel", fields.digiline_channel)
|
|
|
|
object_detector_make_formspec(pos)
|
|
|
|
end
|
|
|
|
|
|
|
|
-- returns true if player was found, false if not
|
2016-01-03 14:37:52 +01:00
|
|
|
local function object_detector_scan(pos)
|
2014-11-22 22:09:26 +01:00
|
|
|
local objs = minetest.get_objects_inside_radius(pos, mesecon.setting("detector_radius", 6))
|
2016-02-14 12:58:02 +01:00
|
|
|
|
|
|
|
-- abort if no scan results were found
|
|
|
|
if next(objs) == nil then return false end
|
2016-01-03 14:37:52 +01:00
|
|
|
|
|
|
|
local scanname = minetest.get_meta(pos):get_string("scanname")
|
2017-03-13 21:13:57 +01:00
|
|
|
local scan_for = {}
|
|
|
|
for _, str in pairs(string.split(scanname:gsub(" ", ""), ",")) do
|
|
|
|
scan_for[str] = true
|
|
|
|
end
|
2017-10-07 00:44:49 +02:00
|
|
|
|
2016-01-03 14:37:52 +01:00
|
|
|
local every_player = scanname == ""
|
2016-02-14 12:58:02 +01:00
|
|
|
for _, obj in pairs(objs) do
|
|
|
|
-- "" is returned if it is not a player; "" ~= nil; so only handle objects with foundname ~= ""
|
|
|
|
local foundname = obj:get_player_name()
|
|
|
|
if foundname ~= "" then
|
2017-03-13 21:13:57 +01:00
|
|
|
if every_player or scan_for[foundname] then
|
2016-02-14 12:58:02 +01:00
|
|
|
return true
|
|
|
|
end
|
2013-02-22 19:20:23 +01:00
|
|
|
end
|
|
|
|
end
|
2016-02-14 12:58:02 +01:00
|
|
|
|
2013-02-22 19:20:23 +01:00
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
|
|
|
-- set player name when receiving a digiline signal on a specific channel
|
2014-06-08 19:02:15 +02:00
|
|
|
local object_detector_digiline = {
|
2013-02-22 19:20:23 +01:00
|
|
|
effector = {
|
2022-02-12 20:12:12 +01:00
|
|
|
action = function(pos, _, channel, msg)
|
2013-12-01 04:13:00 +01:00
|
|
|
local meta = minetest.get_meta(pos)
|
2016-01-03 14:37:52 +01:00
|
|
|
if channel == meta:get_string("digiline_channel") then
|
2013-02-22 19:20:23 +01:00
|
|
|
meta:set_string("scanname", msg)
|
|
|
|
object_detector_make_formspec(pos)
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-05 19:21:26 +01:00
|
|
|
minetest.register_node("mesecons_detector:object_detector_off", {
|
2022-05-05 16:57:53 +02:00
|
|
|
tiles = {side_texture, side_texture, "jeija_object_detector_off.png", "jeija_object_detector_off.png", "jeija_object_detector_off.png", "jeija_object_detector_off.png"},
|
2012-03-05 19:21:26 +01:00
|
|
|
paramtype = "light",
|
2017-10-31 22:50:39 +01:00
|
|
|
is_ground_content = false,
|
2012-03-05 19:21:26 +01:00
|
|
|
walkable = true,
|
2012-12-08 22:28:46 +01:00
|
|
|
groups = {cracky=3},
|
2012-03-05 19:21:26 +01:00
|
|
|
description="Player Detector",
|
2012-12-08 22:28:46 +01:00
|
|
|
mesecons = {receptor = {
|
2014-11-22 12:28:45 +01:00
|
|
|
state = mesecon.state.off,
|
|
|
|
rules = mesecon.rules.pplate
|
2013-02-22 19:20:23 +01:00
|
|
|
}},
|
|
|
|
on_construct = object_detector_make_formspec,
|
|
|
|
on_receive_fields = object_detector_on_receive_fields,
|
2022-05-05 16:57:53 +02:00
|
|
|
sounds = mesecon.node_sound.stone,
|
2017-10-07 00:44:49 +02:00
|
|
|
digiline = object_detector_digiline,
|
|
|
|
on_blast = mesecon.on_blastnode,
|
2012-03-05 19:21:26 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_node("mesecons_detector:object_detector_on", {
|
2022-05-05 16:57:53 +02:00
|
|
|
tiles = {side_texture, side_texture, "jeija_object_detector_on.png", "jeija_object_detector_on.png", "jeija_object_detector_on.png", "jeija_object_detector_on.png"},
|
2012-03-05 19:21:26 +01:00
|
|
|
paramtype = "light",
|
2017-10-31 22:50:39 +01:00
|
|
|
is_ground_content = false,
|
2012-03-05 19:21:26 +01:00
|
|
|
walkable = true,
|
2012-12-08 22:28:46 +01:00
|
|
|
groups = {cracky=3,not_in_creative_inventory=1},
|
2012-06-05 04:20:04 +02:00
|
|
|
drop = 'mesecons_detector:object_detector_off',
|
2012-12-08 22:28:46 +01:00
|
|
|
mesecons = {receptor = {
|
2014-11-22 12:28:45 +01:00
|
|
|
state = mesecon.state.on,
|
|
|
|
rules = mesecon.rules.pplate
|
2013-02-22 19:20:23 +01:00
|
|
|
}},
|
|
|
|
on_construct = object_detector_make_formspec,
|
|
|
|
on_receive_fields = object_detector_on_receive_fields,
|
2022-05-05 16:57:53 +02:00
|
|
|
sounds = mesecon.node_sound.stone,
|
2017-10-07 00:44:49 +02:00
|
|
|
digiline = object_detector_digiline,
|
|
|
|
on_blast = mesecon.on_blastnode,
|
2012-03-05 19:21:26 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_craft({
|
2012-06-05 04:20:04 +02:00
|
|
|
output = 'mesecons_detector:object_detector_off',
|
2012-03-05 19:21:26 +01:00
|
|
|
recipe = {
|
2022-05-05 16:57:53 +02:00
|
|
|
{"mesecons_gamecompat:steel_ingot", "mesecons_gamecompat:steel_ingot", "mesecons_gamecompat:steel_ingot"},
|
|
|
|
{"mesecons_gamecompat:steel_ingot", "mesecons_luacontroller:luacontroller0000", "mesecons_gamecompat:steel_ingot"},
|
|
|
|
{"mesecons_gamecompat:steel_ingot", "group:mesecon_conductor_craftable", "mesecons_gamecompat:steel_ingot"},
|
2012-03-05 19:21:26 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2018-01-14 21:21:43 +01:00
|
|
|
minetest.register_craft({
|
|
|
|
output = 'mesecons_detector:object_detector_off',
|
|
|
|
recipe = {
|
2022-05-05 16:57:53 +02:00
|
|
|
{"mesecons_gamecompat:steel_ingot", "mesecons_gamecompat:steel_ingot", "mesecons_gamecompat:steel_ingot"},
|
|
|
|
{"mesecons_gamecompat:steel_ingot", "mesecons_microcontroller:microcontroller0000", "mesecons_gamecompat:steel_ingot"},
|
|
|
|
{"mesecons_gamecompat:steel_ingot", "group:mesecon_conductor_craftable", "mesecons_gamecompat:steel_ingot"},
|
2018-01-14 21:21:43 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2016-01-03 14:37:52 +01:00
|
|
|
minetest.register_abm({
|
|
|
|
nodenames = {"mesecons_detector:object_detector_off"},
|
|
|
|
interval = 1,
|
2012-03-05 19:21:26 +01:00
|
|
|
chance = 1,
|
2016-01-03 14:37:52 +01:00
|
|
|
action = function(pos, node)
|
2016-02-14 12:58:02 +01:00
|
|
|
if not object_detector_scan(pos) then return end
|
|
|
|
|
2016-01-03 14:37:52 +01:00
|
|
|
node.name = "mesecons_detector:object_detector_on"
|
|
|
|
minetest.swap_node(pos, node)
|
|
|
|
mesecon.receptor_on(pos, mesecon.rules.pplate)
|
2012-03-05 19:21:26 +01:00
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
2016-01-03 14:37:52 +01:00
|
|
|
minetest.register_abm({
|
|
|
|
nodenames = {"mesecons_detector:object_detector_on"},
|
|
|
|
interval = 1,
|
2012-03-05 19:21:26 +01:00
|
|
|
chance = 1,
|
2016-01-03 14:37:52 +01:00
|
|
|
action = function(pos, node)
|
2016-02-14 12:58:02 +01:00
|
|
|
if object_detector_scan(pos) then return end
|
|
|
|
|
2016-01-03 14:37:52 +01:00
|
|
|
node.name = "mesecons_detector:object_detector_off"
|
|
|
|
minetest.swap_node(pos, node)
|
|
|
|
mesecon.receptor_off(pos, mesecon.rules.pplate)
|
2012-03-05 19:21:26 +01:00
|
|
|
end,
|
|
|
|
})
|
2014-06-08 08:29:17 +02:00
|
|
|
|
|
|
|
-- Node detector
|
|
|
|
-- Detects the node in front of it
|
|
|
|
|
2016-01-03 14:37:52 +01:00
|
|
|
local function node_detector_make_formspec(pos)
|
2017-03-13 21:13:57 +01:00
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
if meta:get_string("distance") == "" then meta:set_string("distance", "0") end
|
|
|
|
meta:set_string("formspec", "size[9,2.5]" ..
|
2014-06-08 08:29:17 +02:00
|
|
|
"field[0.3, 0;9,2;scanname;Name of node to scan for (empty for any):;${scanname}]"..
|
2017-03-13 21:13:57 +01:00
|
|
|
"field[0.3,1.5;2.5,2;distance;Distance (0-"..mesecon.setting("node_detector_distance_max", 10).."):;${distance}]"..
|
|
|
|
"field[3,1.5;4,2;digiline_channel;Digiline Channel (optional):;${digiline_channel}]"..
|
2014-06-08 08:29:17 +02:00
|
|
|
"button_exit[7,0.75;2,3;;Save]")
|
|
|
|
end
|
|
|
|
|
2022-02-12 20:12:12 +01:00
|
|
|
local function node_detector_on_receive_fields(pos, _, fields, sender)
|
2016-02-14 12:58:02 +01:00
|
|
|
if not fields.scanname or not fields.digiline_channel then return end
|
2014-06-08 08:29:17 +02:00
|
|
|
|
2017-03-13 21:13:57 +01:00
|
|
|
if minetest.is_protected(pos, sender:get_player_name()) then return end
|
|
|
|
|
2014-06-08 08:29:17 +02:00
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
meta:set_string("scanname", fields.scanname)
|
2017-03-13 21:13:57 +01:00
|
|
|
meta:set_string("distance", fields.distance or "0")
|
2014-06-08 08:29:17 +02:00
|
|
|
meta:set_string("digiline_channel", fields.digiline_channel)
|
|
|
|
node_detector_make_formspec(pos)
|
|
|
|
end
|
|
|
|
|
2016-02-14 12:58:02 +01:00
|
|
|
-- returns true if node was found, false if not
|
2016-01-03 14:37:52 +01:00
|
|
|
local function node_detector_scan(pos)
|
2015-03-26 07:29:34 +01:00
|
|
|
local node = minetest.get_node_or_nil(pos)
|
|
|
|
if not node then return end
|
2016-02-14 12:58:02 +01:00
|
|
|
|
2017-03-13 21:13:57 +01:00
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
|
|
|
|
local distance = meta:get_int("distance")
|
|
|
|
local distance_max = mesecon.setting("node_detector_distance_max", 10)
|
|
|
|
if distance < 0 then distance = 0 end
|
|
|
|
if distance > distance_max then distance = distance_max end
|
|
|
|
|
2016-01-03 14:37:52 +01:00
|
|
|
local frontname = minetest.get_node(
|
2017-03-13 21:13:57 +01:00
|
|
|
vector.subtract(pos, vector.multiply(minetest.facedir_to_dir(node.param2), distance + 1))
|
2016-01-03 14:37:52 +01:00
|
|
|
).name
|
2017-03-13 21:13:57 +01:00
|
|
|
local scanname = meta:get_string("scanname")
|
2016-02-14 12:58:02 +01:00
|
|
|
|
|
|
|
return (frontname == scanname) or
|
|
|
|
(frontname ~= "air" and frontname ~= "ignore" and scanname == "")
|
2014-06-08 08:29:17 +02:00
|
|
|
end
|
|
|
|
|
2019-08-21 22:52:33 +02:00
|
|
|
local function node_detector_send_node_name(pos, node, channel, meta)
|
|
|
|
local distance = meta:get_int("distance")
|
|
|
|
local distance_max = mesecon.setting("node_detector_distance_max", 10)
|
|
|
|
if distance < 0 then distance = 0 end
|
|
|
|
if distance > distance_max then distance = distance_max end
|
|
|
|
local nodename = minetest.get_node(
|
|
|
|
vector.subtract(pos, vector.multiply(minetest.facedir_to_dir(node.param2), distance + 1))
|
|
|
|
).name
|
|
|
|
|
|
|
|
digiline:receptor_send(pos, digiline.rules.default, channel, nodename)
|
|
|
|
end
|
|
|
|
|
2014-06-08 08:29:17 +02:00
|
|
|
-- set player name when receiving a digiline signal on a specific channel
|
2014-06-08 19:02:15 +02:00
|
|
|
local node_detector_digiline = {
|
2014-06-08 08:29:17 +02:00
|
|
|
effector = {
|
2016-01-03 14:37:52 +01:00
|
|
|
action = function(pos, node, channel, msg)
|
2014-06-08 08:29:17 +02:00
|
|
|
local meta = minetest.get_meta(pos)
|
2017-10-07 00:44:49 +02:00
|
|
|
|
2016-02-14 12:58:02 +01:00
|
|
|
if channel ~= meta:get_string("digiline_channel") then return end
|
|
|
|
|
2019-08-21 22:52:33 +02:00
|
|
|
if type(msg) == "table" then
|
|
|
|
if msg.distance or msg.scanname then
|
|
|
|
if msg.distance then
|
|
|
|
meta:set_string("distance", msg.distance)
|
|
|
|
end
|
|
|
|
if msg.scanname then
|
|
|
|
meta:set_string("scanname", msg.scanname)
|
|
|
|
end
|
|
|
|
node_detector_make_formspec(pos)
|
|
|
|
end
|
|
|
|
if msg.command == "get" then
|
|
|
|
node_detector_send_node_name(pos, node, channel, meta)
|
|
|
|
elseif msg.command == "scan" then
|
|
|
|
local result = node_detector_scan(pos)
|
|
|
|
digiline:receptor_send(pos, digiline.rules.default, channel, result)
|
|
|
|
end
|
2016-01-03 14:37:52 +01:00
|
|
|
else
|
2019-08-21 22:52:33 +02:00
|
|
|
if msg == GET_COMMAND then
|
|
|
|
node_detector_send_node_name(pos, node, channel, meta)
|
|
|
|
else
|
|
|
|
meta:set_string("scanname", msg)
|
|
|
|
node_detector_make_formspec(pos)
|
|
|
|
end
|
2014-06-08 08:29:17 +02:00
|
|
|
end
|
|
|
|
end,
|
2014-06-08 19:02:15 +02:00
|
|
|
},
|
|
|
|
receptor = {}
|
2014-06-08 08:29:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
minetest.register_node("mesecons_detector:node_detector_off", {
|
2022-05-05 16:57:53 +02:00
|
|
|
tiles = {side_texture, side_texture, side_texture, side_texture, side_texture, "jeija_node_detector_off.png"},
|
2014-06-08 08:29:17 +02:00
|
|
|
paramtype = "light",
|
|
|
|
paramtype2 = "facedir",
|
2017-10-31 22:50:39 +01:00
|
|
|
is_ground_content = false,
|
2014-06-08 08:29:17 +02:00
|
|
|
walkable = true,
|
|
|
|
groups = {cracky=3},
|
|
|
|
description="Node Detector",
|
|
|
|
mesecons = {receptor = {
|
|
|
|
state = mesecon.state.off
|
|
|
|
}},
|
|
|
|
on_construct = node_detector_make_formspec,
|
|
|
|
on_receive_fields = node_detector_on_receive_fields,
|
2022-05-05 16:57:53 +02:00
|
|
|
sounds = mesecon.node_sound.stone,
|
2017-10-07 00:44:49 +02:00
|
|
|
digiline = node_detector_digiline,
|
|
|
|
on_blast = mesecon.on_blastnode,
|
2014-06-08 08:29:17 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_node("mesecons_detector:node_detector_on", {
|
2022-05-05 16:57:53 +02:00
|
|
|
tiles = {side_texture, side_texture, side_texture, side_texture, side_texture, "jeija_node_detector_on.png"},
|
2014-06-08 08:29:17 +02:00
|
|
|
paramtype = "light",
|
|
|
|
paramtype2 = "facedir",
|
2017-10-31 22:50:39 +01:00
|
|
|
is_ground_content = false,
|
2014-06-08 08:29:17 +02:00
|
|
|
walkable = true,
|
|
|
|
groups = {cracky=3,not_in_creative_inventory=1},
|
|
|
|
drop = 'mesecons_detector:node_detector_off',
|
|
|
|
mesecons = {receptor = {
|
|
|
|
state = mesecon.state.on
|
|
|
|
}},
|
|
|
|
on_construct = node_detector_make_formspec,
|
|
|
|
on_receive_fields = node_detector_on_receive_fields,
|
2022-05-05 16:57:53 +02:00
|
|
|
sounds = mesecon.node_sound.stone,
|
2017-10-07 00:44:49 +02:00
|
|
|
digiline = node_detector_digiline,
|
|
|
|
on_blast = mesecon.on_blastnode,
|
2014-06-08 08:29:17 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_craft({
|
|
|
|
output = 'mesecons_detector:node_detector_off',
|
|
|
|
recipe = {
|
2022-05-05 16:57:53 +02:00
|
|
|
{"mesecons_gamecompat:steel_ingot", "group:mesecon_conductor_craftable", "mesecons_gamecompat:steel_ingot"},
|
|
|
|
{"mesecons_gamecompat:steel_ingot", "mesecons_luacontroller:luacontroller0000", "mesecons_gamecompat:steel_ingot"},
|
|
|
|
{"mesecons_gamecompat:steel_ingot", "mesecons_gamecompat:steel_ingot", "mesecons_gamecompat:steel_ingot"},
|
2014-06-08 08:29:17 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2018-01-14 21:21:43 +01:00
|
|
|
minetest.register_craft({
|
|
|
|
output = 'mesecons_detector:node_detector_off',
|
|
|
|
recipe = {
|
2022-05-05 16:57:53 +02:00
|
|
|
{"mesecons_gamecompat:steel_ingot", "group:mesecon_conductor_craftable", "mesecons_gamecompat:steel_ingot"},
|
|
|
|
{"mesecons_gamecompat:steel_ingot", "mesecons_microcontroller:microcontroller0000", "mesecons_gamecompat:steel_ingot"},
|
|
|
|
{"mesecons_gamecompat:steel_ingot", "mesecons_gamecompat:steel_ingot", "mesecons_gamecompat:steel_ingot"},
|
2018-01-14 21:21:43 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2016-01-03 14:37:52 +01:00
|
|
|
minetest.register_abm({
|
|
|
|
nodenames = {"mesecons_detector:node_detector_off"},
|
|
|
|
interval = 1,
|
2014-06-08 08:29:17 +02:00
|
|
|
chance = 1,
|
|
|
|
action = function(pos, node)
|
2016-02-14 12:58:02 +01:00
|
|
|
if not node_detector_scan(pos) then return end
|
|
|
|
|
|
|
|
node.name = "mesecons_detector:node_detector_on"
|
|
|
|
minetest.swap_node(pos, node)
|
|
|
|
mesecon.receptor_on(pos)
|
2014-06-08 08:29:17 +02:00
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
2016-01-03 14:37:52 +01:00
|
|
|
minetest.register_abm({
|
|
|
|
nodenames = {"mesecons_detector:node_detector_on"},
|
|
|
|
interval = 1,
|
2014-06-08 08:29:17 +02:00
|
|
|
chance = 1,
|
|
|
|
action = function(pos, node)
|
2016-02-14 12:58:02 +01:00
|
|
|
if node_detector_scan(pos) then return end
|
|
|
|
|
|
|
|
node.name = "mesecons_detector:node_detector_off"
|
|
|
|
minetest.swap_node(pos, node)
|
|
|
|
mesecon.receptor_off(pos)
|
2014-06-08 08:29:17 +02:00
|
|
|
end,
|
|
|
|
})
|