From 706f6d7436d9eb71251193bcf25d2ccd1782ebdc Mon Sep 17 00:00:00 2001 From: Sokomine Date: Mon, 21 Jun 2021 21:28:31 +0200 Subject: [PATCH] give wrong items back or drop at the player's feet --- fs_edit_actions.lua | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/fs_edit_actions.lua b/fs_edit_actions.lua index 7813b1d..7297ffc 100644 --- a/fs_edit_actions.lua +++ b/fs_edit_actions.lua @@ -372,15 +372,26 @@ yl_speak_up.action_quest_item_take_back = function(player) if(not(a) or not(a.a_id) or not(a.a_value)) then return false end - -- TODO: what to do with the item? it is something wrong...giving it back might be nice - if(not(yl_speak_up.action_quest_item_check(player))) then - return false - end local pname = player:get_player_name() local n_id = yl_speak_up.speak_to[pname].n_id -- get the item that the NPC shall take back (or accept in npc_wants) local trade_inv = minetest.get_inventory({type="detached", name="yl_speak_up_player_"..pname}) local stack = trade_inv:get_stack("npc_wants", 1) + -- if it was the wrong item: + if(not(yl_speak_up.action_quest_item_check(player))) then + local player_inv = player:get_inventory() + -- give the item back to the player + local remaining = player_inv:add_item("main", stack) + -- very unlikely - but in case the item did not fit back into the player's inv: + if(remaining and not(remaining:is_empty())) then + local p = player:get_pos() + -- throw it at the player + minetest.add_item({x=p.x, y=p.y+1, z=p.z}, stack) + end + -- remove it from the trade inv slot + trade_inv:set_stack("npc_wants", 1, ItemStack()) + return false + end -- we already checked that it is the correct item local meta = stack:get_meta() -- if given: set the item stack description