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:
parent
f007240c21
commit
e8fa4ae05d
@ -9,53 +9,38 @@
|
|||||||
|
|
||||||
local has_mesecons = minetest.get_modpath("mesecons")
|
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)
|
function activate_palm_scanner(pos, node, player)
|
||||||
-- Some calling function don't send node param, but everybody sends a pos, so :
|
local name = player and player:get_player_name()
|
||||||
if not node then
|
name = name or ""
|
||||||
node = minetest.get_node(pos)
|
|
||||||
end
|
|
||||||
|
|
||||||
if node.name == "scifi_nodes:palm_scanner_off" then
|
node.name = "scifi_nodes:palm_scanner_checking"
|
||||||
local meta = minetest.get_meta(pos)
|
minetest.swap_node(pos, node)
|
||||||
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
|
|
||||||
|
|
||||||
-- palm_scanner_checking.on_timer
|
minetest.sound_play("scifi_nodes_palm_scanner", {max_hear_distance = 8, pos = pos, gain = 1.0})
|
||||||
local function check_owner(pos, elapsed)
|
minetest.chat_send_player(name, "Checking : please wait.")
|
||||||
local meta = minetest.get_meta(pos)
|
|
||||||
local owner = meta:get_string("owner")
|
-- check protection
|
||||||
local clicker = meta:get_string("clicker")
|
minetest.after(2, function()
|
||||||
local node = minetest.get_node(pos)
|
if minetest.is_protected(pos, name or "") then
|
||||||
if clicker == owner then
|
-- clicker has no access to area
|
||||||
minetest.sound_play("scifi_nodes_scanner_granted", {max_hear_distance = 8, pos = pos, gain = 1.0})
|
minetest.chat_send_player(name, "Access denied !")
|
||||||
minetest.chat_send_player(clicker, "Access granted !")
|
minetest.sound_play("scifi_nodes_scanner_refused", {max_hear_distance = 8, pos = pos, gain = 1.0})
|
||||||
toggle_palm_scanner(pos)
|
|
||||||
else
|
else
|
||||||
minetest.chat_send_player(clicker, "Access refused !")
|
-- clicker can build here
|
||||||
minetest.sound_play("scifi_nodes_scanner_refused", {max_hear_distance = 8, pos = pos, gain = 1.0})
|
minetest.chat_send_player(name, "Access granted !")
|
||||||
minetest.swap_node(pos, {name = "scifi_nodes:palm_scanner_off", param2 = node.param2})
|
mesecon.receptor_on(pos, scifi_nodes.get_switch_rules(node.param2))
|
||||||
mesecon.receptor_off(pos, scifi_nodes.get_switch_rules(node.param2))
|
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
minetest.register_node("scifi_nodes:palm_scanner_off", {
|
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)
|
state = (has_mesecons and mesecon.state.off)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
after_place_node = set_scanner_owner,
|
on_rightclick = (has_mesecons and activate_palm_scanner),
|
||||||
on_rightclick = (has_mesecons and toggle_palm_scanner),
|
|
||||||
sounds = default.node_sound_glass_defaults(),
|
sounds = default.node_sound_glass_defaults(),
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -96,8 +80,7 @@ minetest.register_node("scifi_nodes:palm_scanner_checking", {
|
|||||||
paramtype2 = "wallmounted",
|
paramtype2 = "wallmounted",
|
||||||
groups = {cracky=1, oddly_breakable_by_hand=1, not_in_creative_inventory=1, mesecon_needs_receiver = 1},
|
groups = {cracky=1, oddly_breakable_by_hand=1, not_in_creative_inventory=1, mesecon_needs_receiver = 1},
|
||||||
drop = "scifi_nodes:palm_scanner_off",
|
drop = "scifi_nodes:palm_scanner_off",
|
||||||
sounds = default.node_sound_glass_defaults(),
|
sounds = default.node_sound_glass_defaults()
|
||||||
on_timer = check_owner,
|
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_node("scifi_nodes:palm_scanner_on", {
|
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)
|
state = (has_mesecons and mesecon.state.on)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
on_timer = (has_mesecons and toggle_palm_scanner),
|
|
||||||
sounds = default.node_sound_glass_defaults(),
|
sounds = default.node_sound_glass_defaults(),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user