fixed deleting tades associated with dialog options

This commit is contained in:
Sokomine 2021-06-02 18:05:40 +02:00
parent e6f9dbac67
commit 7b12a37efe

View File

@ -60,15 +60,38 @@ yl_speak_up.input_do_trade_simple = function(player, formname, fields)
-- delete a trade; this can be done here only if..
-- * it is a trade from the trade list (not an effect of a dialog option)
-- * it is a trade associated with a dialog option and the player is in
-- edit mode
-- * the player has the necessary privs
-- This option is available without having to enter edit mode first.
if(fields.delete_trade_simple
and yl_speak_up.may_edit_npc(player, trade.n_id)) then
-- get the necessary dialog data
local dialog = yl_speak_up.speak_to[pname].dialog
-- store d_id and o_id in order to be able to return to the right
-- edit options dialog
local back_to_d_id = nil
local back_to_o_id = nil
if(dialog and dialog.trades and trade.trade_id
and dialog.trades[ trade.trade_id ] and
not(dialog.trades[ trade.trade_id ].d_id)) then
and dialog.trades[ trade.trade_id ] and trade.n_id) then
if( dialog.trades[ trade.trade_id ].d_id
and yl_speak_up.edit_mode[pname] ~= trade.n_id) then
yl_speak_up.show_fs(player, "msg", {
input_to = "yl_speak_up:do_trade_simple",
formspec = "size[6,2]"..
"label[0.2,-0.2;"..
"Trades that are attached to dialog options\n"..
"can only be deleted in edit mode. Please tell\n"..
"your NPC that you are its owner and have\n"..
"new commands!]"..
"button[2,1.5;1,0.9;back_from_error_msg;Back]"})
return
end
if( dialog.trades[ trade.trade_id ].d_id ) then
back_to_d_id = dialog.trades[ trade.trade_id ].d_id
back_to_o_id = dialog.trades[ trade.trade_id ].o_id
end
-- log the change
yl_speak_up.log_change(pname, n_id,
"Trade: Deleted offer "..tostring(trade.trade_id)..".")
@ -79,6 +102,12 @@ yl_speak_up.input_do_trade_simple = function(player, formname, fields)
-- we are done with this trade
yl_speak_up.trade[pname] = nil
end
-- always return to edit options dialog if deleting a trade that belonged to one
if(back_to_d_id and back_to_o_id) then
yl_speak_up.show_fs(player, "edit_option_dialog",
{n_id = n_id, d_id = back_to_d_id, o_id = back_to_o_id})
return
end
-- go back showing the trade list (since we deleted this trade)
yl_speak_up.show_fs(player, "trade_list")
return