From 9aca0379b7fa80dafd542b50028893b3d8cfdf4b Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Thu, 17 May 2018 15:18:19 +0200 Subject: [PATCH] Update select_item handling --- easyvend.lua | 46 ++++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/easyvend.lua b/easyvend.lua index a5edf19..a26848b 100644 --- a/easyvend.lua +++ b/easyvend.lua @@ -24,32 +24,34 @@ end if minetest.get_modpath("select_item") then -- When player selects item via "select item" dialog, switch the -- machine's selected item and update the formspec. - select_item.register_on_select_item(function(playername, itemstring) - local player = minetest.get_player_by_name(playername) - if not player then - return - end - local pos = active_item_selection[playername] - if pos then - local node = minetest.get_node(pos) - if not easyvend.is_machine(node.name) then + select_item.register_on_select_item(function(playername, dialogname, itemstring) + if dialogname == "easyvend:trade_item" then + local player = minetest.get_player_by_name(playername) + if not player then return end - local meta = minetest.get_meta(pos) - local owner = meta:get_string("owner") - if playername == owner then - local inv = meta:get_inventory() - local stack = ItemStack(itemstring) - if stack == nil then - inv:set_stack( "item", 1, nil ) - else - inv:set_stack( "item", 1, stack) - meta:set_string("itemname", itemstring) - easyvend.set_formspec(pos, player) + local pos = active_item_selection[playername] + if pos then + local node = minetest.get_node(pos) + if not easyvend.is_machine(node.name) then + return + end + local meta = minetest.get_meta(pos) + local owner = meta:get_string("owner") + if playername == owner then + local inv = meta:get_inventory() + local stack = ItemStack(itemstring) + if stack == nil then + inv:set_stack( "item", 1, nil ) + else + inv:set_stack( "item", 1, stack) + meta:set_string("itemname", itemstring) + easyvend.set_formspec(pos, player) + end end end + active_item_selection[playername] = nil end - active_item_selection[playername] = nil end) end @@ -1001,7 +1003,7 @@ easyvend.on_receive_fields = function(pos, formname, fields, sender) if minetest.get_modpath("select_item") then if sendername == owner then active_item_selection[sendername] = pos - select_item.show_dialog(sendername, select_item.filters.creative) + select_item.show_dialog(sendername, "easyvend:trade_item", select_item.filters.creative) else meta:set_string("message", "Only the owner may change the configuration.") easyvend.sound_error(sendername) -- 2.11.4.GIT