Compare commits

...

5 Commits

Author SHA1 Message Date
HimbeerserverDE 4487d8b147 Fix global sound 2020-09-21 21:16:35 +02:00
HimbeerserverDE ead95b3b5a Fix turn off callback 2020-09-18 17:38:48 +02:00
HimbeerserverDE 8c9d5bcccc Fix sound play function 2020-09-18 17:36:26 +02:00
HimbeerserverDE db6760cb11
Fix sounds 2020-09-18 17:31:58 +02:00
HimbeerserverDE 2ce1fe6d38 temporary change 2020-09-18 17:23:16 +02:00
1 changed files with 38 additions and 53 deletions

View File

@ -28,6 +28,33 @@ local m_rules = {
{x = 0, y = -2, z = 0},
}
local function a_action_on(pos, node)
for _, obj in ipairs(minetest.get_objects_inside_radius(pos, 20)) do
local sound = minetest.sound_play("alarm_" .. node.name:split(":")[2], {
to_player = obj:get_player_name(),
max_hear_distance = 20,
gain = 10.0,
loop = true,
})
local meta = minetest.get_meta(pos)
local sounds = minetest.parse_json(meta:get_string("sounds"))
if not sounds then sounds = {} end
table.insert(sounds, sound)
meta:set_string("sounds", minetest.write_json(sounds))
end
end
local function a_action_off(pos, node)
local meta = minetest.get_meta(pos)
local sounds = minetest.parse_json(meta:get_string("sounds"))
if not sounds then return end
for _, sound in ipairs(sounds) do
minetest.sound_stop(sound)
end
sounds = {}
meta:set_string("sounds", minetest.write_json(sounds))
end
minetest.register_node("alarms:fire", {
description = "Fire alarm",
groups = {snappy = 1},
@ -38,32 +65,18 @@ minetest.register_node("alarms:fire", {
node_box = {
type = "fixed",
fixed = {
{-0.2, -0.2, -0.5, 0.2, 0.2, -0.4},
{-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,
action_on = a_action_on,
action_off = a_action_off,
},
},
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"))
a_action_off(pos, {name = "alarms:fire"})
end,
})
minetest.register_node("alarms:nuclear", {
@ -82,26 +95,12 @@ minetest.register_node("alarms:nuclear", {
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,
action_on = a_action_on,
action_off = a_action_off,
},
},
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"))
a_action_off(pos, {name = "alarms:nuclear"})
end,
})
minetest.register_node("alarms:intruder", {
@ -114,31 +113,17 @@ minetest.register_node("alarms:intruder", {
node_box = {
type = "fixed",
fixed = {
{-0.2, -0.2, -0.5, 0.2, 0.2, -0.4},
{-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,
action_on = a_action_on,
action_off = a_action_off,
},
},
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"))
a_action_off(pos, {name = "alarms:nuclear"})
end,
})