Traitor/mods/tasks/smoke_detector.lua

95 lines
3.3 KiB
Lua

local formspec_good =
'size[6,3]'..
'textarea[1,1;5,2;;;Battery voltage is in the acceptable range.]'
local function formspec_bad(pos)
local spos = pos.x ..','.. pos.y ..','.. pos.z
local formspec =
'formspec_version[3]'..
'size[10.5,7]'..
'textarea[.5,.5;5,1;;;Battery is low, please replace.]' ..
'button_exit[3.5,1.5;3,1;gimme;Grab a part request form]'..
'list[nodemeta:'..spos..';part;8,1.5;1,1;]'..
'list[current_player;main;.5,3;8,3;]'..
'listring[current_player;main]'..
'listring[nodemeta:'..spos..';part]'..
'image[8,1.5;1,1;tasks_9v_battery_line.png]'
return formspec
end
local box = {
type = 'fixed',
fixed = {
{-.2, .4, -.2, .2, .5, .2},},}
minetest.register_node('tasks:smoke_detector_on',{
description = 'Smoke Detector',
drawtype = 'mesh',
mesh = 'tasks_smoke_alarm.obj',
tiles = {name = 'tasks_smoke_alarm_on.png'},
light_source = 2,
paramtype = 'light',
selection_box = box,
collision_box = box,
groups = {breakable = 1, tasks=1},
on_construct = function(pos)
tasks.on_construct(pos, 'Smoke Detector', 'Wall Art?')
end,
on_rightclick = function(pos, node, clicker)
tasks.right_click_on(pos, node, clicker, formspec_good)
end,
on_timer = function(pos)
local node = minetest.get_node(pos)
local meta = minetest.get_meta(pos)
local infotext = meta:get_string('info_repair')
meta:set_string('infotext', infotext)
minetest.swap_node(pos, {name = 'tasks:smoke_detector_off', param2 = node.param2})
minetest.sound_play('tasks_smoke_alarm_chirp', {pos = pos, gain = 2, max_hear_distance = 14})
end,
})
minetest.register_node('tasks:smoke_detector_off',{
description = 'Smoke Detector',
drawtype = 'mesh',
mesh = 'tasks_smoke_alarm.obj',
tiles = {name = 'tasks_smoke_alarm_off.png'},
paramtype = 'light',
selection_box = box,
collision_box = box,
groups = {breakable = 1, not_in_creative_inventory=1, tasks=1, plays_sound=1},
_sound = 'tasks_smoke_alarm_chirp',
drop = 'tasks:smoke_detector_on',
req_form = 'tasks:9v_battery_req',
req_count = 4,
on_rightclick = function(pos, node, clicker)
tasks.right_click_off(pos, node, clicker, formspec_bad(pos))
end,
allow_metadata_inventory_put = function(pos, listname, index, stack)
if listname == 'part' then
if stack:get_name() == 'tasks:9v_battery' then
return 1
else
return 0
end
end
end,
on_metadata_inventory_put = function(pos, listname, index, stack, player)
local name = player:get_player_name()
local meta = minetest.get_meta(pos)
local xp = meta:get_int('xp') or 1
local inv = meta:get_inventory()
local node = minetest.get_node(pos)
local timer = minetest.get_node_timer(pos)
local min = meta:get_int('time_min') or 30
local max = meta:get_int('time_max') or 60
local random_number = math.random(min,max)
local infotext = meta:get_string('info_working')
inv:set_stack('part', 1, '')
minetest.swap_node(pos, {name = 'tasks:smoke_detector_on'})
minetest.close_formspec(name, 'tasks:part_req_form')
meta:set_string('infotext', infotext)
tasks.only_add_xp(xp, name)
timer:start(random_number)
end,
})