diff --git a/fs_player_offers_item.lua b/fs_player_offers_item.lua index f33da96..bd4ee49 100644 --- a/fs_player_offers_item.lua +++ b/fs_player_offers_item.lua @@ -28,6 +28,18 @@ yl_speak_up.input_player_offers_item = function(player, formname, fields) end local pname = player:get_player_name() local trade_inv = minetest.get_inventory({type="detached", name="yl_speak_up_player_"..pname}) + if(fields.quit) then + -- return the items + local player_inv = player:get_inventory() + local stack = trade_inv:get_stack("npc_wants", 1) + if( trade_inv and player_inv:room_for_item("main", stack)) then + player_inv:add_item("main", stack) + trade_inv:set_stack("npc_wants", 1, "") + end + -- sometimes players are desperate and just want to leave - allow them to do so + yl_speak_up.stop_talking(pname) + return + end local error_msg = "Please insert the item for the npc and click on \"Give\"!\n".. "If you don't want to give anything, click on \"Back to talk\".]" -- is the npc_wants inv empty and the player pressed the back to talk button? diff --git a/fs_talkdialog.lua b/fs_talkdialog.lua index bf8e67a..c40a2df 100644 --- a/fs_talkdialog.lua +++ b/fs_talkdialog.lua @@ -1,6 +1,9 @@ -- This is the main talkdialog the NPC shows when right-clicked. yl_speak_up.stop_talking = function(pname) + if(not(pname)) then + return + end yl_speak_up.edit_mode[pname] = nil yl_speak_up.speak_to[pname] = nil minetest.close_formspec(pname, "yl_speak_up:talk")