report multiple dialog results and refuse edit in such a disambigous case

This commit is contained in:
Sokomine 2021-05-09 16:51:24 +02:00
parent fcebadf6c4
commit 573753b80d

View File

@ -2531,6 +2531,43 @@ minetest.register_on_player_receive_fields(
)
-- identify multiple results that lead to target dialogs
yl_speak_up.check_for_disambigous_results = function(n_id, pname)
local errors_found = false
local dialog = load_dialog(n_id)
-- nothing defined yet - nothing to repair
if(not(dialog.n_dialogs)) then
return
end
-- iterate over all dialogs
for d_id, d in pairs(dialog.n_dialogs) do
if(d_id and d and d.d_options) then
-- iterate over all options
for o_id, o in pairs(d.d_options) do
if(o_id and o and o.o_results) then
local dialog_results = {}
-- iterate over all results
for r_id, r in pairs(o.o_results) do
if(r.r_type == "dialog") then
table.insert(dialog_results, r_id)
end
end
if(#dialog_results>1) then
minetest.chat_send_player(pname, "ERROR: Dialog "..
tostring(d_id)..", option "..tostring(o_id)..
", has multiple results of type dialog: "..
minetest.serialize(dialog_results)..". Please "..
"let someone with npc_master priv fix that first!")
errors_found = true
end
end
end
end
end
return errors_found
end
minetest.register_on_player_receive_fields(
function(player, formname, fields)
if formname ~= "yl_speak_up:talk" then
@ -2637,6 +2674,13 @@ minetest.register_on_player_receive_fields(
minetest.chat_send_player(pname, "Sorry. You do not have the npc_talk_owner or npc_master priv.")
return
end
-- the staff allows to create multiple target dialogs as result; this makes no sense
-- and is too disambigous
if(yl_speak_up.check_for_disambigous_results(n_id, pname)) then
-- this needs to be fixed by someone with a staff; we don't know which dialog is the right
-- result
return
end
-- enter edit mode with that particular NPC
yl_speak_up.edit_mode[pname] = yl_speak_up.speak_to[pname].n_id
-- start a new chat - but this time in edit mode