local function schedule(time,pos,channel,message) minetest.after(time,function() digilines.receptor_send(pos,digilines.rules.default,channel,message) end) end local emit_signals = function(pos) local meta = minetest.get_meta(pos) if meta:get_string("locked") ~= "true" then meta:set_string("locked","true") schedule(0,pos,"main","YELLOW") schedule(3,pos,"main","RED") schedule(4,pos,"side","GREEN") schedule(14,pos,"side","YELLOW") schedule(17,pos,"side","RED") schedule(18,pos,"main","GREEN") minetest.after(30,function() if minetest.get_node(pos).name == "lightcontroller:trafficnext" then meta:set_string("locked","") end end) end end local lc_scan = function(pos) local objs = minetest.get_objects_inside_radius(pos, 6) if objs then for _,obj in ipairs(objs) do if obj:is_player() then emit_signals(pos) return end end end end local lc_slave_scan = function(pos) local objs = minetest.get_objects_inside_radius(pos, 6) if objs then for _,obj in ipairs(objs) do if obj:is_player() then digilines.receptor_send(pos, digilines.rules.default, "detector", "car") return end end end end local on_digiline_receive = function(pos,_,channel) if channel == "detector" then emit_signals(pos) end end minetest.register_node("lightcontroller:trafficnext", { description = "TrafficNeXt SoC - Master", tiles = { "streets_tl_bg.png", "streets_tl_bg.png", "streets_tl_bg.png^streets_tl_green.png", "streets_tl_bg.png^streets_tl_green.png", "streets_tl_bg.png^streets_tl_green.png", "streets_tl_bg.png^streets_tl_green.png" }, groups = {cracky=3, stone=1}, sounds = default.node_sound_stone_defaults(), digiline = { receptor = {}, effector = { action = on_digiline_receive }, }, on_punch = emit_signals, }) minetest.register_abm({ nodenames = {"lightcontroller:trafficnext"}, interval = 1.0, chance = 1, action = lc_scan, }) minetest.register_node("lightcontroller:trafficnext_slave", { description = "TrafficNeXt SoC - Slave", tiles = { "streets_tl_bg.png", "streets_tl_bg.png", "streets_tl_bg.png^streets_tl_red.png", "streets_tl_bg.png^streets_tl_red.png", "streets_tl_bg.png^streets_tl_red.png", "streets_tl_bg.png^streets_tl_red.png" }, groups = {cracky=3, stone=1}, sounds = default.node_sound_stone_defaults(), digiline = { receptor = {}, }, }) minetest.register_abm({ nodenames = {"lightcontroller:trafficnext_slave"}, interval = 1.0, chance = 1, action = lc_slave_scan, }) minetest.register_lbm({ name = "lightcontroller:reset", label = "Reset TrafficNeXt SoCs", nodenames = {"lightcontroller:trafficnext"}, run_at_every_load = true, action = function(pos) minetest.get_meta(pos):set_string("locked","") digilines.receptor_send(pos,digilines.rules.default,"main","GREEN") digilines.receptor_send(pos,digilines.rules.default,"side","RED") end, })