show formspec instead of chat message in case of wrong inventory placement of dammaged tools etc

This commit is contained in:
Sokomine 2021-06-02 23:01:10 +02:00
parent a2e11f5fb6
commit ba96bf6975

View File

@ -36,6 +36,11 @@ yl_speak_up.input_inventory = function(player, formname, fields)
-- after closing the inventory formspec:
-- ..save the (very probably) modified inventory
yl_speak_up.save_npc_inventory(n_id)
-- show inventory again?
if(fields.back_from_error_msg) then
yl_speak_up.show_fs(player, "inventory")
return
end
-- show the trade list?
if(fields.inventory_show_tradelist) then
yl_speak_up.show_fs(player, "trade_list")
@ -133,17 +138,22 @@ yl_speak_up.load_npc_inventory = function(n_id)
if(not(yl_speak_up.may_edit_npc(player, n_id))) then
return 0
end
local error_msg = nil
if(stack:get_wear() > 0) then
minetest.chat_send_player(player:get_player_name(),
"Your NPC accepts only undammaged items. "..
"Trading dammaged items would be unfair.")
return 0
end
error_msg = "Your NPC accepts only undammaged items.\n"..
"Trading dammaged items would be unfair."
-- items with metadata cannot be traded
if(yl_speak_up.check_stack_has_meta(player, stack)) then
minetest.chat_send_player(player:get_player_name(),
"Your NPC cannot sell items that contain "..
"additional (meta-) data.")
elseif(yl_speak_up.check_stack_has_meta(player, stack)) then
error_msg = "Your NPC cannot sell items that contain\n"..
"additional (meta-) data."
end
if(error_msg) then
yl_speak_up.show_fs(player, "msg", {
input_to = "yl_speak_up:inventory",
formspec = "size[6,2]"..
"label[0.2,-0.2;"..tostring(error_msg).."]"..
"button[2,1.5;1,0.9;back_from_error_msg;"..
"OK]"})
return 0
end
return stack:get_count()