fixed deleting tades associated with dialog options
This commit is contained in:
parent
e6f9dbac67
commit
7b12a37efe
@ -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..
|
-- 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 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
|
-- * the player has the necessary privs
|
||||||
-- This option is available without having to enter edit mode first.
|
-- This option is available without having to enter edit mode first.
|
||||||
if(fields.delete_trade_simple
|
if(fields.delete_trade_simple
|
||||||
and yl_speak_up.may_edit_npc(player, trade.n_id)) then
|
and yl_speak_up.may_edit_npc(player, trade.n_id)) then
|
||||||
-- get the necessary dialog data
|
-- get the necessary dialog data
|
||||||
local dialog = yl_speak_up.speak_to[pname].dialog
|
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
|
if(dialog and dialog.trades and trade.trade_id
|
||||||
and dialog.trades[ trade.trade_id ] and
|
and dialog.trades[ trade.trade_id ] and trade.n_id) then
|
||||||
not(dialog.trades[ trade.trade_id ].d_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
|
-- log the change
|
||||||
yl_speak_up.log_change(pname, n_id,
|
yl_speak_up.log_change(pname, n_id,
|
||||||
"Trade: Deleted offer "..tostring(trade.trade_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
|
-- we are done with this trade
|
||||||
yl_speak_up.trade[pname] = nil
|
yl_speak_up.trade[pname] = nil
|
||||||
end
|
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)
|
-- go back showing the trade list (since we deleted this trade)
|
||||||
yl_speak_up.show_fs(player, "trade_list")
|
yl_speak_up.show_fs(player, "trade_list")
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user