2012-12-08 22:28:46 +01:00
|
|
|
-- Object detector
|
|
|
|
-- Detects all entities in a certain radius
|
|
|
|
-- The radius can be specified in mesecons/settings.lua
|
|
|
|
|
2012-03-05 19:21:26 +01:00
|
|
|
minetest.register_node("mesecons_detector:object_detector_off", {
|
2012-08-20 10:12:10 +02:00
|
|
|
tiles = {"default_steel_block.png", "default_steel_block.png", "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",
|
|
|
|
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 = {
|
2012-12-09 00:42:30 +01:00
|
|
|
state = mesecon.state.off
|
2012-12-08 22:28:46 +01:00
|
|
|
}}
|
2012-03-05 19:21:26 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_node("mesecons_detector:object_detector_on", {
|
2012-08-20 10:12:10 +02:00
|
|
|
tiles = {"default_steel_block.png", "default_steel_block.png", "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",
|
|
|
|
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 = {
|
2012-12-09 00:42:30 +01:00
|
|
|
state = mesecon.state.on
|
2012-12-08 22:28:46 +01:00
|
|
|
}}
|
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 = {
|
|
|
|
{"default:steelblock", '', "default:steelblock"},
|
2012-08-12 02:53:47 +02:00
|
|
|
{"default:steelblock", "mesecons_microcontroller:microcontroller0000", "default:steelblock"},
|
|
|
|
{"default:steelblock", "group:mesecon_conductor_craftable", "default:steelblock"},
|
2012-03-05 19:21:26 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_abm(
|
|
|
|
{nodenames = {"mesecons_detector:object_detector_off"},
|
|
|
|
interval = 1.0,
|
|
|
|
chance = 1,
|
|
|
|
action = function(pos, node, active_object_count, active_object_count_wider)
|
2012-12-08 22:28:46 +01:00
|
|
|
local objs = minetest.env:get_objects_inside_radius(pos, OBJECT_DETECTOR_RADIUS)
|
2012-03-05 19:21:26 +01:00
|
|
|
for k, obj in pairs(objs) do
|
2012-12-08 22:28:46 +01:00
|
|
|
if obj:get_entity_name()~="mesecons_pistons:piston_pusher_sticky" and obj:get_entity_name()~="mesecons_pistons:piston_pusher_normal" and obj:get_player_name()~=nil then
|
2012-03-05 19:21:26 +01:00
|
|
|
if minetest.env:get_node({x=pos.x, y=pos.y-1, z=pos.z}).name=="default:sign_wall" then
|
2012-06-23 12:39:35 +02:00
|
|
|
if obj:get_player_name()~=minetest.env:get_meta({x=pos.x, y=pos.y-1, z=pos.z}):get_string("text") then
|
2012-03-05 19:21:26 +01:00
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
local objpos=obj:getpos()
|
|
|
|
minetest.env:add_node(pos, {name="mesecons_detector:object_detector_on"})
|
2012-12-09 00:42:30 +01:00
|
|
|
mesecon:receptor_on(pos)
|
2012-03-05 19:21:26 +01:00
|
|
|
end
|
2012-06-05 04:20:04 +02:00
|
|
|
end
|
2012-03-05 19:21:26 +01:00
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_abm(
|
|
|
|
{nodenames = {"mesecons_detector:object_detector_on"},
|
|
|
|
interval = 1.0,
|
|
|
|
chance = 1,
|
|
|
|
action = function(pos, node, active_object_count, active_object_count_wider)
|
2012-12-08 22:28:46 +01:00
|
|
|
local objs = minetest.env:get_objects_inside_radius(pos, OBJECT_DETECTOR_RADIUS)
|
2012-03-05 19:21:26 +01:00
|
|
|
local objectfound=0
|
|
|
|
for k, obj in pairs(objs) do
|
|
|
|
if obj:get_entity_name()~="mesecons_pistons:piston_pusher_sticky" and obj:get_entity_name()~="mesecons_pistons:piston_pusher_normal" and obj~=nil
|
|
|
|
and obj:get_player_name()~=nil then
|
|
|
|
if minetest.env:get_node({x=pos.x, y=pos.y-1, z=pos.z}).name=="default:sign_wall" then
|
2012-06-23 12:39:35 +02:00
|
|
|
if minetest.env:get_meta({x=pos.x, y=pos.y-1, z=pos.z}):get_string("text")== obj:get_player_name() then
|
2012-03-05 19:21:26 +01:00
|
|
|
objectfound=objectfound+1
|
|
|
|
end
|
|
|
|
else
|
|
|
|
-- Detected object is not piston pusher - will be changed if every entity has a type (like entity_type=mob)
|
|
|
|
objectfound=objectfound + 1
|
|
|
|
end
|
|
|
|
end
|
2012-06-05 04:20:04 +02:00
|
|
|
end
|
2012-03-05 19:21:26 +01:00
|
|
|
if objectfound==0 then
|
|
|
|
minetest.env:add_node(pos, {name="mesecons_detector:object_detector_off"})
|
2012-12-09 00:42:30 +01:00
|
|
|
mesecon:receptor_off(pos)
|
2012-03-05 19:21:26 +01:00
|
|
|
end
|
|
|
|
end,
|
|
|
|
})
|