diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..f78ba0a --- /dev/null +++ b/init.lua @@ -0,0 +1,144 @@ +local m_rules = { + {x = 0, y = 0, z = -1}, + {x = 1, y = 0, z = 0}, + {x = -1, y = 0, z = 0}, + {x = 0, y = 0, z = 1}, + {x = 1, y = 1, z = 0}, + {x = 1, y = -1, z = 0}, + {x = -1, y = 1, z = 0}, + {x = -1, y = -1, z = 0}, + {x = 0, y = 1, z = 1}, + {x = 0, y = -1, z = 1}, + {x = 0, y = 1, z = -1}, + {x = 0, y = -1, z = -1}, + {x = 0, y = -1, z = 0}, + + {x = 0, y = 0, z = -2}, + {x = 2, y = 0, z = 0}, + {x = -2, y = 0, z = 0}, + {x = 0, y = 0, z = 2}, + {x = 2, y = 2, z = 0}, + {x = 2, y = -2, z = 0}, + {x = -2, y = 2, z = 0}, + {x = -2, y = -2, z = 0}, + {x = 0, y = 2, z = 2}, + {x = 0, y = -2, z = 2}, + {x = 0, y = 2, z = -2}, + {x = 0, y = -2, z = -2}, + {x = 0, y = -2, z = 0}, +} + +minetest.register_node("alarms:fire", { + description = "Fire alarm", + groups = {snappy = 1}, + tiles = {"red.png", "red.png", "red.png", "red.png", "red.png", "gray.png"}, + paramtype = "light", + paramtype2 = "facedir", + drawtype = "nodebox", + node_box = { + type = "fixed", + fixed = { + {-0.2, -0.2, -0.5, 0.2, 0.2, -0.4}, + }, + }, + mesecons = { + effector = { + rules = m_rules, + action_on = function(pos, node) + for _, obj in ipairs(minetest.get_objects_inside_radius(pos, 20)) do + if not obj:is_player() then return end + local sound = minetest.sound_play("alarm_fire", { + to_player = obj:get_player_name(), + max_hear_distance = 20, + gain = 10.0, + }) + end + minetest.get_meta(pos):set_int("sound", sound) + end, + action_off = function(pos, node) + if not minetest.get_meta(pos):get_int("sound") then return end + minetest.sound_stop(minetest.get_meta(pos):get_int("sound")) + end, + }, + }, + on_destruct = function(pos) + if not minetest.get_meta(pos):get_int("sound") then return end + minetest.sound_stop(minetest.get_meta(pos):get_int("sound")) + end, +}) +minetest.register_node("alarms:nuclear", { + description = "Nuclear alarm", + groups = {choppy = 1}, + tiles = {"gray.png"}, + paramtype = "light", + paramtype2 = "facedir", + drawtype = "nodebox", + node_box = { + type = "fixed", + fixed = { + {-0.2, -0.2, -0.8, 0.2, 0.2, 0.8}, + }, + }, + mesecons = { + effector = { + rules = m_rules, + action_on = function(pos, node) + for _, obj in ipairs(minetest.get_objects_inside_radius(pos, 20)) do + if not obj:is_player() then return end + local sound = minetest.sound_play("alarm_nuclear", { + to_player = obj:get_player_name(), + max_hear_distance = 20, + gain = 10.0, + }) + end + minetest.get_meta(pos):set_int("sound", sound) + end, + action_off = function(pos, node) + if not minetest.get_meta(pos):get_int("sound") then return end + minetest.sound_stop(minetest.get_meta(pos):get_int("sound")) + end, + }, + }, + on_destruct = function(pos) + if not minetest.get_meta(pos):get_int("sound") then return end + minetest.sound_stop(minetest.get_meta(pos):get_int("sound")) + end, +}) +minetest.register_node("alarms:intruder", { + description = "Intruder alarm", + groups = {snappy = 1}, + tiles = {"gray.png", "gray.png", "gray.png", "gray.png", "gray.png", "red.png"}, + paramtype = "light", + paramtype2 = "facedir", + drawtype = "nodebox", + node_box = { + type = "fixed", + fixed = { + {-0.2, -0.2, -0.5, 0.2, 0.2, -0.4}, + }, + }, + mesecons = { + effector = { + rules = m_rules, + action_on = function(pos, node) + for _, obj in ipairs(minetest.get_objects_inside_radius(pos, 20)) do + if not obj:is_player() then return end + local sound = minetest.sound_play("alarm_intruder", { + to_player = obj:get_player_name(), + max_hear_distance = 20, + gain = 10.0, + }) + end + minetest.get_meta(pos):set_int("sound", sound) + end, + action_off = function(pos, node) + if not minetest.get_meta(pos):get_int("sound") then return end + minetest.sound_stop(minetest.get_meta(pos):get_int("sound")) + end, + }, + }, + on_destruct = function(pos) + if not minetest.get_meta(pos):get_int("sound") then return end + minetest.sound_stop(minetest.get_meta(pos):get_int("sound")) + end, +}) diff --git a/mod.conf b/mod.conf new file mode 100644 index 0000000..cfdc564 --- /dev/null +++ b/mod.conf @@ -0,0 +1,3 @@ +name = alarms +description = "Adds alarm nodes for minetest" +depends = mesecons diff --git a/sounds/alarm_fire.ogg b/sounds/alarm_fire.ogg new file mode 100644 index 0000000..2a9b22e Binary files /dev/null and b/sounds/alarm_fire.ogg differ diff --git a/sounds/alarm_intruder.ogg b/sounds/alarm_intruder.ogg new file mode 100644 index 0000000..20cfe9b Binary files /dev/null and b/sounds/alarm_intruder.ogg differ diff --git a/sounds/alarm_nuclear.ogg b/sounds/alarm_nuclear.ogg new file mode 100644 index 0000000..7bfe87c Binary files /dev/null and b/sounds/alarm_nuclear.ogg differ diff --git a/textures/gray.png b/textures/gray.png new file mode 100644 index 0000000..930fa26 Binary files /dev/null and b/textures/gray.png differ diff --git a/textures/red.png b/textures/red.png new file mode 100644 index 0000000..b6118bd Binary files /dev/null and b/textures/red.png differ