added a button for buying directly in a trade
This commit is contained in:
parent
b7d0f88790
commit
b313f6fd98
@ -41,6 +41,11 @@ yl_speak_up.input_do_trade_simple = function(player, formname, fields)
|
||||
return
|
||||
end
|
||||
|
||||
if(fields.buy_directly) then
|
||||
yl_speak_up.show_fs(player, "trade_simple", yl_speak_up.speak_to[pname].trade_id)
|
||||
return
|
||||
end
|
||||
|
||||
local n_id = yl_speak_up.speak_to[pname].n_id
|
||||
-- if in edit mode: go back to the edit options dialog
|
||||
if(fields.back_to_edit_options
|
||||
@ -629,10 +634,14 @@ yl_speak_up.get_fs_trade_simple = function(player, trade_id)
|
||||
|
||||
|
||||
local trade_possible_msg = "Status of trade: Unknown."
|
||||
-- has the NPC room for the payment?
|
||||
if(not(npc_inv:room_for_item("npc_main", trade.player_gives))) then
|
||||
-- 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)..
|
||||
" ran out of inventory space.\nThere is no room to store your payment!]"
|
||||
" ran out of stock.\nPlease come back later."
|
||||
-- has the NPC room for the payment?
|
||||
elseif(not(npc_inv:room_for_item("npc_main", trade.player_gives))) then
|
||||
trade_possible_msg = "Sorry. "..minetest.formspec_escape(trade.npc_name)..
|
||||
" ran out of inventory space.\nThere is no room to store your payment!"
|
||||
-- can the player pay?
|
||||
elseif(not(player_inv:contains_item("main", trade.player_gives))) then
|
||||
-- both slots will remain empty
|
||||
@ -641,14 +650,20 @@ yl_speak_up.get_fs_trade_simple = function(player, trade_id)
|
||||
elseif not(trade_inv:is_empty("pay")) then
|
||||
-- both slots will remain empty
|
||||
-- (the slot may already contain the right things; we'll find that out later on)
|
||||
trade_possible_msg = "Please insert the right payment!"
|
||||
trade_possible_msg = "This is not what "..minetest.formspec_escape(trade.npc_name)..
|
||||
" wants.\nPlease insert the right payment!"
|
||||
-- all good so far; move the price stack to the pay slot
|
||||
-- else
|
||||
-- -- move price item to the price slot
|
||||
-- local stack = player_inv:remove_item("main", trade.player_gives)
|
||||
-- trade_inv:add_item("pay", stack)
|
||||
else
|
||||
trade_possible_msg = "Please insert the right payment in the pay slot."
|
||||
trade_possible_msg = "Please insert the right payment in the pay slot\n"..
|
||||
"or click on \"buy\"."..
|
||||
"]button[6.5,2.0;1.2,0.9;buy_directly;Buy]"..
|
||||
"tooltip[buy_directly;"..
|
||||
"Click here in order to buy directly without having to insert\n"..
|
||||
"your payment manually into the pay slot."
|
||||
end
|
||||
|
||||
-- make sure the sale slot is empty (we will fill it if the trade is possible)
|
||||
@ -657,14 +672,10 @@ yl_speak_up.get_fs_trade_simple = function(player, trade_id)
|
||||
if(trade_inv:contains_item("pay", trade.player_gives)) then
|
||||
trade_possible_msg = "Take the offered item(s) in order to buy them."
|
||||
|
||||
-- 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)..
|
||||
" ran out of stock.\nPlease come back later."
|
||||
-- only new/undammaged tools, weapons and armor are accepted
|
||||
elseif(trade_inv:get_stack("pay", 1):get_wear() > 0) then
|
||||
if(trade_inv:get_stack("pay", 1):get_wear() > 0) then
|
||||
trade_possible_msg = "Sorry. "..minetest.formspec_escape(trade.npc_name)..
|
||||
" accepts only undammaged items.]"
|
||||
" accepts only undammaged items."
|
||||
else
|
||||
-- put a *copy* of the item(stack) that is to be sold in the sale slot
|
||||
trade_inv:add_item("buy", trade.npc_gives)
|
||||
@ -674,7 +685,7 @@ yl_speak_up.get_fs_trade_simple = function(player, trade_id)
|
||||
if(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.]"
|
||||
"free inventory space to store your purchase."
|
||||
end
|
||||
|
||||
return formspec..
|
||||
|
Loading…
Reference in New Issue
Block a user