diff options
author | cheapie <no-email-for-you@example.com> | 2023-08-04 16:46:03 -0500 |
---|---|---|
committer | cheapie <no-email-for-you@example.com> | 2023-08-04 16:46:03 -0500 |
commit | 12d9182bd5c50013dd76885cf8395b9a1a4f84a6 (patch) | |
tree | 7e988aeaf7fec82f490efafab699156a8ac35854 /pairingtool.lua | |
parent | 6e3377a70d9bfc8311cfbec69f498b8140068eb8 (diff) | |
download | celevator-12d9182bd5c50013dd76885cf8395b9a1a4f84a6.tar celevator-12d9182bd5c50013dd76885cf8395b9a1a4f84a6.tar.gz celevator-12d9182bd5c50013dd76885cf8395b9a1a4f84a6.tar.bz2 celevator-12d9182bd5c50013dd76885cf8395b9a1a4f84a6.tar.xz celevator-12d9182bd5c50013dd76885cf8395b9a1a4f84a6.zip |
Add lanterns
Diffstat (limited to 'pairingtool.lua')
-rw-r--r-- | pairingtool.lua | 68 |
1 files changed, 46 insertions, 22 deletions
diff --git a/pairingtool.lua b/pairingtool.lua index 0b00a38..9bea461 100644 --- a/pairingtool.lua +++ b/pairingtool.lua @@ -3,21 +3,36 @@ celevator.pairing = { } minetest.register_on_player_receive_fields(function (player,formname,fields) - if formname ~= "celevator:pairing_floornum" then return end if not celevator.pairing.playerstate[player:get_player_name()] then return end if not tonumber(fields.floornum) then return end - local targetpos = celevator.pairing.playerstate[player:get_player_name()].pos - local controllerpos = celevator.pairing.playerstate[player:get_player_name()].controllerpos - if minetest.get_item_group(minetest.get_node(targetpos).name,"_celevator_callbutton") == 1 then - local nodemeta = minetest.get_meta(targetpos) - nodemeta:set_string("controllerpos",minetest.pos_to_string(controllerpos)) - local controllermeta = minetest.get_meta(controllerpos) - local pairings = minetest.deserialize(controllermeta:get_string("callbuttons")) or {} - local hash = minetest.hash_node_position(targetpos) - pairings[hash] = math.floor(tonumber(fields.floornum)) - controllermeta:set_string("callbuttons",minetest.serialize(pairings)) - minetest.chat_send_player(player:get_player_name(),"Paired to "..minetest.pos_to_string(controllerpos).." as landing "..pairings[hash]) - celevator.pairing.playerstate[player:get_player_name()] = nil + if formname == "celevator:pairing_callbutton_floornum" then + local targetpos = celevator.pairing.playerstate[player:get_player_name()].pos + local controllerpos = celevator.pairing.playerstate[player:get_player_name()].controllerpos + if minetest.get_item_group(minetest.get_node(targetpos).name,"_celevator_callbutton") == 1 then + local nodemeta = minetest.get_meta(targetpos) + nodemeta:set_string("controllerpos",minetest.pos_to_string(controllerpos)) + local controllermeta = minetest.get_meta(controllerpos) + local pairings = minetest.deserialize(controllermeta:get_string("callbuttons")) or {} + local hash = minetest.hash_node_position(targetpos) + pairings[hash] = math.floor(tonumber(fields.floornum)) + controllermeta:set_string("callbuttons",minetest.serialize(pairings)) + minetest.chat_send_player(player:get_player_name(),"Call button paired to "..minetest.pos_to_string(controllerpos).." as landing "..pairings[hash]) + celevator.pairing.playerstate[player:get_player_name()] = nil + end + elseif formname == "celevator:pairing_lantern_floornum" then + local targetpos = celevator.pairing.playerstate[player:get_player_name()].pos + local controllerpos = celevator.pairing.playerstate[player:get_player_name()].controllerpos + if minetest.get_item_group(minetest.get_node(targetpos).name,"_celevator_lantern") == 1 then + local nodemeta = minetest.get_meta(targetpos) + nodemeta:set_string("controllerpos",minetest.pos_to_string(controllerpos)) + local controllermeta = minetest.get_meta(controllerpos) + local pairings = minetest.deserialize(controllermeta:get_string("lanterns")) or {} + local hash = minetest.hash_node_position(targetpos) + pairings[hash] = math.floor(tonumber(fields.floornum)) + controllermeta:set_string("lanterns",minetest.serialize(pairings)) + minetest.chat_send_player(player:get_player_name(),"Lantern paired to "..minetest.pos_to_string(controllerpos).." as landing "..pairings[hash]) + celevator.pairing.playerstate[player:get_player_name()] = nil + end end end) @@ -64,12 +79,12 @@ minetest.register_tool("celevator:pairingtool",{ pos = pos, controllerpos = controllerpos, } - minetest.show_formspec(name,"celevator:pairing_floornum","field[floornum;Landing Number;1]") + minetest.show_formspec(name,"celevator:pairing_callbutton_floornum","field[floornum;Landing Number;1]") end else minetest.chat_send_player(name,"Controller or dispatcher has been removed. Punch a new controller or dispatcher to pair to that one.") end - elseif minetest.get_item_group(node.name,"_celevator_pi") then + elseif minetest.get_item_group(node.name,"_celevator_pi") or minetest.get_item_group(node.name,"_celevator_lantern") == 1 then local stackmeta = itemstack:get_meta() local nodemeta = minetest.get_meta(pos) local oldpairing = minetest.string_to_pos(nodemeta:get_string("controllerpos")) @@ -100,13 +115,22 @@ minetest.register_tool("celevator:pairingtool",{ minetest.chat_send_player(name,"Unable to pair - item to be paired is protected!") minetest.record_protection_violation(pos,name) else - local controllermeta = minetest.get_meta(controllerpos) - nodemeta:set_string("controllerpos",minetest.pos_to_string(controllerpos)) - local pairings = minetest.deserialize(controllermeta:get_string("pis")) or {} - local hash = minetest.hash_node_position(pos) - pairings[hash] = true - controllermeta:set_string("pis",minetest.serialize(pairings)) - minetest.chat_send_player(player:get_player_name(),"Paired to "..minetest.pos_to_string(controllerpos)) + if minetest.get_item_group(node.name,"_celevator_pi") == 1 then + local controllermeta = minetest.get_meta(controllerpos) + nodemeta:set_string("controllerpos",minetest.pos_to_string(controllerpos)) + local pairings = minetest.deserialize(controllermeta:get_string("pis")) or {} + local hash = minetest.hash_node_position(pos) + pairings[hash] = true + controllermeta:set_string("pis",minetest.serialize(pairings)) + minetest.chat_send_player(player:get_player_name(),"PI paired to "..minetest.pos_to_string(controllerpos)) + end + if minetest.get_item_group(node.name,"_celevator_lantern") == 1 then + celevator.pairing.playerstate[name] = { + pos = pos, + controllerpos = controllerpos, + } + minetest.show_formspec(name,"celevator:pairing_lantern_floornum","field[floornum;Landing Number;1]") + end end else minetest.chat_send_player(name,"Controller or dispatcher has been removed. Punch a new controller or dispatcher to pair to that one.") |