fixed bug in trading where the npc could sell when out of stock

This commit is contained in:
Sokomine 2022-08-16 05:53:14 +02:00
parent 9c95aa2074
commit 9358a27b03

View File

@ -703,6 +703,7 @@ yl_speak_up.get_fs_trade_simple = function(player, trade_id)
local trade_possible_msg = "Status of trade: Unknown."
local can_trade = false
-- can the NPC provide his part?
if(not(npc_inv:contains_item("npc_main", trade.npc_gives))) then
trade_possible_msg = "Sorry. "..minetest.formspec_escape(trade.npc_name)..
@ -733,12 +734,13 @@ yl_speak_up.get_fs_trade_simple = function(player, trade_id)
"tooltip[buy_directly;"..
"Click here in order to buy directly without having to insert\n"..
"your payment manually into the pay slot."
can_trade = true
end
-- make sure the sale slot is empty (we will fill it if the trade is possible)
trade_inv:set_stack("buy", 1, "")
-- after all this: does the payment slot contain the right things?
if(trade_inv:contains_item("pay", trade.player_gives)) then
if(can_trade and trade_inv:contains_item("pay", trade.player_gives)) then
trade_possible_msg = "Take the offered item(s) in order to buy them."
-- only new/undammaged tools, weapons and armor are accepted
@ -751,7 +753,7 @@ yl_speak_up.get_fs_trade_simple = function(player, trade_id)
end
end
if(not(player_inv:room_for_item("main", trade.npc_gives))) then
if(can_trade and not(player_inv:room_for_item("main", trade.npc_gives))) then
-- the player has no room for the sold item; give a warning
trade_possible_msg = "Careful! You do not seem to have enough\n"..
"free inventory space to store your purchase."