1
0
mirror of https://github.com/D00Med/scifi_nodes.git synced 2024-12-23 00:20:17 +01:00

working palm scanner

This commit is contained in:
Thomas Rudin 2019-09-09 18:59:48 +02:00
parent f007240c21
commit e8fa4ae05d

View File

@ -9,53 +9,38 @@
local has_mesecons = minetest.get_modpath("mesecons")
-- after_place_node
-- placer is a player object
local function set_scanner_owner(pos, placer, itemstack, pointed_thing)
local meta = minetest.get_meta(pos)
meta:set_string("owner", placer:get_player_name())
end
local function toggle_palm_scanner(pos, node, player, itemstack, pointed_thing)
-- Some calling function don't send node param, but everybody sends a pos, so :
if not node then
node = minetest.get_node(pos)
end
function activate_palm_scanner(pos, node, player)
local name = player and player:get_player_name()
name = name or ""
node.name = "scifi_nodes:palm_scanner_checking"
minetest.swap_node(pos, node)
if node.name == "scifi_nodes:palm_scanner_off" then
local meta = minetest.get_meta(pos)
meta:set_string("clicker", player:get_player_name()) -- need to keep it somewhere
minetest.swap_node(pos, {name = "scifi_nodes:palm_scanner_checking", param2 = node.param2})
minetest.sound_play("scifi_nodes_palm_scanner", {max_hear_distance = 8, pos = pos, gain = 1.0})
minetest.chat_send_player(player:get_player_name(), "Checking : please wait.")
minetest.get_node_timer(pos):start(2)
elseif node.name == "scifi_nodes:palm_scanner_checking" then
minetest.swap_node(pos,{name = "scifi_nodes:palm_scanner_on", param2 = node.param2})
mesecon.receptor_on(pos, scifi_nodes.get_switch_rules(node.param2))
minetest.get_node_timer(pos):start(2)
elseif node.name == "scifi_nodes:palm_scanner_on" then
minetest.sound_play("scifi_nodes_switch", {max_hear_distance = 8, pos = pos, gain = 1.0})
minetest.swap_node(pos, {name = "scifi_nodes:palm_scanner_off", param2 = node.param2})
mesecon.receptor_off (pos, scifi_nodes.get_switch_rules(node.param2))
end
end
minetest.chat_send_player(name, "Checking : please wait.")
-- palm_scanner_checking.on_timer
local function check_owner(pos, elapsed)
local meta = minetest.get_meta(pos)
local owner = meta:get_string("owner")
local clicker = meta:get_string("clicker")
local node = minetest.get_node(pos)
if clicker == owner then
minetest.sound_play("scifi_nodes_scanner_granted", {max_hear_distance = 8, pos = pos, gain = 1.0})
minetest.chat_send_player(clicker, "Access granted !")
toggle_palm_scanner(pos)
else
minetest.chat_send_player(clicker, "Access refused !")
-- check protection
minetest.after(2, function()
if minetest.is_protected(pos, name or "") then
-- clicker has no access to area
minetest.chat_send_player(name, "Access denied !")
minetest.sound_play("scifi_nodes_scanner_refused", {max_hear_distance = 8, pos = pos, gain = 1.0})
minetest.swap_node(pos, {name = "scifi_nodes:palm_scanner_off", param2 = node.param2})
mesecon.receptor_off(pos, scifi_nodes.get_switch_rules(node.param2))
else
-- clicker can build here
minetest.chat_send_player(name, "Access granted !")
mesecon.receptor_on(pos, scifi_nodes.get_switch_rules(node.param2))
end
-- reset state
minetest.after(1, function()
node.name = "scifi_nodes:palm_scanner_off"
minetest.swap_node(pos, node)
mesecon.receptor_off(pos, scifi_nodes.get_switch_rules(node.param2))
end)
end)
end
minetest.register_node("scifi_nodes:palm_scanner_off", {
@ -76,8 +61,7 @@ minetest.register_node("scifi_nodes:palm_scanner_off", {
state = (has_mesecons and mesecon.state.off)
}
},
after_place_node = set_scanner_owner,
on_rightclick = (has_mesecons and toggle_palm_scanner),
on_rightclick = (has_mesecons and activate_palm_scanner),
sounds = default.node_sound_glass_defaults(),
})
@ -96,8 +80,7 @@ minetest.register_node("scifi_nodes:palm_scanner_checking", {
paramtype2 = "wallmounted",
groups = {cracky=1, oddly_breakable_by_hand=1, not_in_creative_inventory=1, mesecon_needs_receiver = 1},
drop = "scifi_nodes:palm_scanner_off",
sounds = default.node_sound_glass_defaults(),
on_timer = check_owner,
sounds = default.node_sound_glass_defaults()
})
minetest.register_node("scifi_nodes:palm_scanner_on", {
@ -120,7 +103,6 @@ minetest.register_node("scifi_nodes:palm_scanner_on", {
state = (has_mesecons and mesecon.state.on)
}
},
on_timer = (has_mesecons and toggle_palm_scanner),
sounds = default.node_sound_glass_defaults(),
})