From 310488920896da62c346175d3bbcc3ad56c7a069 Mon Sep 17 00:00:00 2001 From: Sokomine Date: Sat, 1 Oct 2022 22:25:57 +0200 Subject: [PATCH] taking the purchase in a trade_simple inside an action finished the action successfully --- trade_simple.lua | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/trade_simple.lua b/trade_simple.lua index 0ac37ff..a5086b0 100644 --- a/trade_simple.lua +++ b/trade_simple.lua @@ -940,7 +940,32 @@ yl_speak_up.player_joined_add_trade_inv = function(player, last_login) -- show formspec with updated information (perhaps sale is now possible) yl_speak_up.show_fs(player, "trade_simple") elseif(listname == "buy") then + -- do the exchange yl_speak_up.do_trade_simple(player, stack:get_count()) + local pname = player:get_player_name() + -- which trade are we talking about? + local trade = yl_speak_up.trade[pname] + -- when the player traded once inside an action: that action was a success; + -- execute next action + -- but only if not in edit mode + if(trade and trade.trade_done > 0 + and not(trade.trade_is_trade_list) + and yl_speak_up.edit_mode[pname] ~= trade.n_id) then + local trade_inv = minetest.get_inventory({type="detached", name="yl_speak_up_player_"..pname}) + -- return surplus items from the pay slot + local pay = trade_inv:get_stack("pay", 1) + local player_inv = player:get_inventory() + if( pay and player_inv:room_for_item("main", pay)) then + player_inv:add_item("main", pay) + trade_inv:set_stack("pay", 1, "") + end + -- done trading + yl_speak_up.speak_to[pname].target_d_id = nil + yl_speak_up.speak_to[pname].trade_id = nil + -- execute the next action + yl_speak_up.execute_next_action(player, trade.a_id, true) + return + end -- information may require an update (NPC might now be out of stock), or -- the player can do the trade a second time yl_speak_up.show_fs(player, "trade_simple")