From 45616bb4bae35f19fd0d8aac6541d27f0ca821e3 Mon Sep 17 00:00:00 2001 From: Sokomine Date: Sun, 2 Jan 2022 06:12:50 +0100 Subject: [PATCH] auto-refuse unwanted items and let the player take them back --- functions.lua | 23 +++++++++++++++++++++++ show_fs.lua | 1 + 2 files changed, 24 insertions(+) diff --git a/functions.lua b/functions.lua index bb3306a..e8e4789 100644 --- a/functions.lua +++ b/functions.lua @@ -334,6 +334,22 @@ yl_speak_up.get_fs_talkdialog = function(player, n_id, d_id, alternate_text, rec return yl_speak_up.get_fs_talkdialog(player, n_id, target_dialog, res.alternate_text, recursion_depth + 1) end + + -- is the player comming back from trying to offer something to the NPC? + -- And is the NPC trying to return the item? + if(not(edit_mode) and d_id == "d_got_item") then + local pname = player:get_player_name() + local trade_inv = minetest.get_inventory({type="detached", name="yl_speak_up_player_"..pname}) + if(not(trade_inv:is_empty("npc_wants"))) then + return "size[8,1.5]".. + "label[0.2,-0.2;".. + minetest.formspec_escape(dialog.n_npc or "- ? -").. + " does not seem to be intrested.\n".. + "Please take your item back and try something else.]".. + "button[2,1.0;1.5,0.9;show_player_offers_item;Ok]" + end + end + yl_speak_up.speak_to[pname].allowed = allowed local portrait = calculate_portrait(pname, n_id) @@ -1667,6 +1683,13 @@ yl_speak_up.input_talk = function(player, formname, fields) return end + -- allow the player to take the item back + if(fields.show_player_offers_item and fields.show_player_offers_item ~= "") then + yl_speak_up.show_fs(player, "player_offers_item", nil) + return + end + + if fields.button_up then yl_speak_up.speak_to[pname].option_index = yl_speak_up.speak_to[pname].option_index + yl_speak_up.max_number_of_buttons diff --git a/show_fs.lua b/show_fs.lua index 20cd630..6c08134 100644 --- a/show_fs.lua +++ b/show_fs.lua @@ -125,6 +125,7 @@ yl_speak_up.show_fs = function(player, fs_name, param) elseif(fs_name -- msg is just a loop for displaying (mostly error) messages and fs_name ~= "msg" + and fs_name ~= "player_offers_item" -- is the player editing the NPC? that is: might there be any changes? and (yl_speak_up.edit_mode[pname] == yl_speak_up.speak_to[pname].n_id)) then local last_fs = yl_speak_up.speak_to[pname].last_fs