SHARE
TWEET

Untitled

a guest May 4th, 2019 118 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ------------------
  2. -- Palm scanner --
  3. ------------------
  4.  
  5.  
  6. -----------------------------------------------
  7. -- /!\ When "overriding" a callback function --
  8. -- re-use all the parameters in same order ! --
  9. -----------------------------------------------
  10.  
  11. local function toggle_palm_scanner(pos)
  12.     local node = minetest.get_node(pos)
  13.     local name = node.name
  14.     if name == "scifi_nodes:palm_scanner_off" then
  15.         minetest.swap_node(pos, {name = "scifi_nodes:palm_scanner_on", param2 = node.param2})
  16.         mesecon.receptor_on(pos, get_switch_rules(node.param2))
  17.         minetest.get_node_timer(pos):start(3)
  18.     elseif name == "scifi_nodes:palm_scanner_on" then
  19.         minetest.swap_node(pos, {name="scifi_nodes:palm_scanner_off", param2=node.param2})
  20.         mesecon.receptor_off(pos, get_switch_rules(node.param2))
  21.     end
  22. end
  23.  
  24. -- after_place_node
  25. -- placer is a player object
  26. local function set_owner(pos, placer, itemstack, pointed_thing)
  27.     local meta = minetest.get_meta(pos)
  28.     meta:set_string("owner", placer:get_player_name())
  29. end
  30.  
  31. -- on_rightclick
  32. -- player is a player object
  33. local function check_owner(pos, node, player, itemstack, pointed_thing)
  34.     local meta = minetest.get_meta(pos)
  35.     local owner = meta:get_string("owner")
  36.     local player = player:get_player_name()
  37.     minetest.swap_node(pos, {name = "scifi_nodes:palm_scanner_checking", param2 = node.param2})
  38.     minetest.sound_play("scifi_nodes_palm_scanner", {max_hear_distance = 8, pos = pos, gain = 1.0})
  39.     -- wait a minute please !
  40.     local clock = os.clock
  41.     local t0 = clock()
  42.     while clock() - t0 <= 1.5 do end
  43.     minetest.swap_node(pos, {name = "scifi_nodes:palm_scanner_off", param2 = node.param2})
  44.     if owner == player then
  45.         minetest.sound_play("scifi_nodes_access_granted", {max_hear_distance = 8, pos = pos, gain = 1.0})
  46.         minetest.chat_send_player(player, "Access granted !")
  47.         toggle_palm_scanner(pos)
  48.     else
  49.         minetest.chat_send_player(player, "Access refused !")
  50.         minetest.sound_play("scifi_nodes_access_refused", {max_hear_distance = 8, pos = pos, gain = 1.0})
  51.     end
  52. end
  53.  
  54. minetest.register_node("scifi_nodes:palm_scanner_on", {
  55.     description = "Palm scanner",
  56.     sunlight_propagates = true,
  57.     buildable_to = false,
  58.     tiles = {"scifi_nodes_palm_scanner_on.png",},
  59.     inventory_image = "scifi_nodes_palm_scanner_on.png",
  60.     wield_image = "scifi_nodes_palm_scanner_on.png",
  61.     drawtype = "signlike",
  62.     node_box = {type = "wallmounted",},
  63.     selection_box = {type = "wallmounted",},
  64.     paramtype = "light",
  65.     paramtype2 = "wallmounted",
  66.     light_source = 5,
  67.     groups = {cracky=1, oddly_breakable_by_hand=1, not_in_creative_inventory=1, mesecon_needs_receiver = 1},
  68.     mesecons = {receptor = {state = mesecon.state.on,}},
  69.     on_timer = toggle_palm_scanner,
  70.     sounds = default.node_sound_glass_defaults(),
  71. })
  72.  
  73. minetest.register_node("scifi_nodes:palm_scanner_off", {
  74.     description = "Palm scanner",
  75.     tiles = {"scifi_nodes_palm_scanner_off.png",},
  76.     inventory_image = "scifi_nodes_palm_scanner_on.png",
  77.     wield_image = "scifi_nodes_palm_scanner_on.png",
  78.     drawtype = "signlike",
  79.     sunlight_propagates = true,
  80.     buildable_to = false,
  81.     node_box = {type = "wallmounted",},
  82.     selection_box = {type = "wallmounted",},
  83.     paramtype = "light",
  84.     paramtype2 = "wallmounted",
  85.     groups = {cracky=1, oddly_breakable_by_hand=1, mesecon_needs_receiver = 1},
  86.     mesecons = {receptor = {state = mesecon.state.off,}},
  87.     after_place_node = set_owner,
  88.     on_rightclick = check_owner,
  89.     sounds = default.node_sound_glass_defaults(),
  90. })
  91.  
  92. minetest.register_node("scifi_nodes:palm_scanner_checking", {
  93.     description = "Palm scanner",
  94.     tiles = {{name = "scifi_nodes_palm_scanner_checking.png", animation = {type = "vertical_frames",aspect_w = 16,aspect_h = 16,length = 1.5}}},
  95.     wield_image = "scifi_nodes_palm_scanner_on.png",
  96.     inventory_image = "scifi_nodes_palm_scanner_on.png",
  97.     drawtype = "signlike",
  98.     sunlight_propagates = true,
  99.     buildable_to = false,
  100.     node_box = {type = "wallmounted",},
  101.     selection_box = {type = "wallmounted",},
  102.     paramtype = "light",
  103.     paramtype2 = "wallmounted",
  104.     groups = {cracky=1, oddly_breakable_by_hand=1, not_in_creative_inventory=1, mesecon_needs_receiver = 1},
  105. })
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top