took care of delete_trade_simple regarding edit_mode

This commit is contained in:
Sokomine 2024-02-09 05:44:30 +01:00
parent e7369f3075
commit 1659aed8ab
2 changed files with 33 additions and 13 deletions

View File

@ -165,19 +165,8 @@ yl_speak_up.delete_trade_simple = function(player, trade_id)
if(dialog and dialog.trades and trade_id
and dialog.trades[ trade_id ] and n_id) then
if( dialog.trades[ trade_id ].d_id
and yl_speak_up.edit_mode[pname] ~= 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
-- Note: That the trade cannot be deleted outside edit mode if it is the action
-- belonging to an option is checked in editor/trade_*.lua
if( dialog.trades[ trade_id ].d_id ) then
back_to_d_id = dialog.trades[ trade_id ].d_id
back_to_o_id = dialog.trades[ trade_id ].o_id

View File

@ -37,3 +37,34 @@ yl_speak_up.do_trade_simple = function(player, count)
end
return old_do_trade_simple(player, count)
end
-- overrides for api/api_trade.lua:
-- do not allow deleting trades that are actions of an option if not in edit mode:
local old_delete_trade_simple = yl_speak_up.delete_trade_simple
yl_speak_up.delete_trade_simple = function(player, trade_id)
local pname = player:get_player_name()
local n_id = yl_speak_up.speak_to[pname].n_id
-- get the necessary dialog data
local dialog = yl_speak_up.speak_to[pname].dialog
if(dialog and dialog.trades and trade_id
and dialog.trades[ trade_id ] and n_id) then
if( dialog.trades[ trade_id ].d_id
and yl_speak_up.edit_mode[pname] ~= 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
end
return old_delete_trade_simple(player, trade_id)
end