-
Notifications
You must be signed in to change notification settings - Fork 18
/
palm_scanner.lua
118 lines (102 loc) · 3.78 KB
/
palm_scanner.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
-----------------------------------------------
-- Palm scanner --
-----------------------------------------------
-- /!\ When "overriding" a callback function --
-- re-use all the parameters in same order ! --
-----------------------------------------------
local has_mesecons = minetest.get_modpath("mesecons")
local 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)
minetest.sound_play("scifi_nodes_palm_scanner", {max_hear_distance = 8, pos = pos, gain = 1.0})
minetest.chat_send_player(name, "Checking : please wait.")
-- check protection
minetest.after(2, function()
if minetest.get_node(pos).name ~= node.name then return end
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})
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()
if minetest.get_node(pos).name ~= node.name then return end
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", {
description = "Palm scanner",
tiles = {"scifi_nodes_palm_scanner_off.png",},
inventory_image = "scifi_nodes_palm_scanner_off.png",
wield_image = "scifi_nodes_palm_scanner_on.png",
drawtype = "signlike",
sunlight_propagates = true,
buildable_to = false,
node_box = {type = "wallmounted",},
selection_box = {type = "wallmounted",},
paramtype = "light",
paramtype2 = "wallmounted",
groups = {cracky=1, oddly_breakable_by_hand=1, mesecon_needs_receiver = 1},
is_ground_content = false,
mesecons = {
receptor = {
state = (has_mesecons and mesecon.state.off)
}
},
on_rightclick = (has_mesecons and activate_palm_scanner),
sounds = scifi_nodes.node_sound_metal_defaults(),
})
minetest.register_node("scifi_nodes:palm_scanner_checking", {
description = "Palm scanner",
tiles = {{
name = "scifi_nodes_palm_scanner_checking.png",
animation = {type = "vertical_frames",aspect_w = 16,aspect_h = 16,length = 1.5}
}},
drawtype = "signlike",
sunlight_propagates = true,
buildable_to = false,
node_box = {type = "wallmounted",},
selection_box = {type = "wallmounted",},
paramtype = "light",
paramtype2 = "wallmounted",
groups = {cracky=1, oddly_breakable_by_hand=1, not_in_creative_inventory=1, mesecon_needs_receiver = 1},
is_ground_content = false,
drop = "scifi_nodes:palm_scanner_off",
sounds = scifi_nodes.node_sound_metal_defaults()
})
minetest.register_node("scifi_nodes:palm_scanner_on", {
description = "Palm scanner",
sunlight_propagates = true,
buildable_to = false,
tiles = {"scifi_nodes_palm_scanner_on.png",},
inventory_image = "scifi_nodes_palm_scanner_on.png",
wield_image = "scifi_nodes_palm_scanner_on.png",
drawtype = "signlike",
node_box = {type = "wallmounted",},
selection_box = {type = "wallmounted",},
paramtype = "light",
paramtype2 = "wallmounted",
light_source = 5,
groups = {cracky=1, oddly_breakable_by_hand=1, not_in_creative_inventory=1, mesecon_needs_receiver = 1},
is_ground_content = false,
drop = "scifi_nodes:palm_scanner_off",
mesecons = {
receptor = {
state = (has_mesecons and mesecon.state.on)
}
},
sounds = scifi_nodes.node_sound_metal_defaults(),
})
minetest.register_craft({
output = "scifi_nodes:palm_scanner_off 2",
recipe = {{"mesecons_powerplant:power_plant", "scifi_nodes:grey", ""}}
})