added yl_speak_up.get_start_dialog_id and reload dialog when entering edit mode

This commit is contained in:
Sokomine 2022-04-22 21:28:23 +02:00
parent 795dce0c2b
commit f3573e746f

View File

@ -89,6 +89,8 @@ yl_speak_up.input_talk = function(player, formname, fields)
yl_speak_up.speak_to[pname].option_index = 1
-- enter edit mode with that particular NPC
yl_speak_up.edit_mode[pname] = yl_speak_up.speak_to[pname].n_id
-- load the NPC dialog anew - but only what the NPC itself has to say, no generic dialogs
yl_speak_up.speak_to[pname].dialog = yl_speak_up.load_dialog(n_id, false)
-- start a new chat - but this time in edit mode
yl_speak_up.speak_to[pname].d_id = nil
yl_speak_up.show_fs(player, "talk", {n_id = yl_speak_up.speak_to[pname].n_id, d_id = nil})
@ -267,6 +269,27 @@ yl_speak_up.input_talk = function(player, formname, fields)
end
-- helper function for
-- yl_speak_up.get_fs_talkdialog and
-- yl_speak_up.check_generic_dialog_get_errors
-- find the dialog with d_sort == 0 or lowest number
yl_speak_up.get_start_dialog_id = function(dialog)
if(not(dialog) or not(dialog.n_dialogs)) then
return nil
end
-- Find the dialog with d_sort = 0 or alternatively with the lowest number
local lowest_sort = nil
local d_id = nil
for k, v in pairs(dialog.n_dialogs) do
local nr = tonumber(v.d_sort)
if(not(lowest_sort) or (nr and nr >= 0 and nr < lowest_sort)) then
lowest_sort = nr
d_id = k
end
end
return d_id
end
-- recursion_depth is increased each time autoanswer is automaticly selected
yl_speak_up.get_fs_talkdialog = function(player, n_id, d_id, alternate_text, recursion_depth)
@ -305,18 +328,10 @@ yl_speak_up.get_fs_talkdialog = function(player, n_id, d_id, alternate_text, rec
active_dialog = dialog.n_dialogs[c_d_id]
elseif dialog.n_dialogs ~= nil then
-- Find the dialog with d_sort = 0
local lowest_sort = nil
for k, v in pairs(dialog.n_dialogs) do
if tonumber(v.d_sort) ~= nil then
if not lowest_sort or tonumber(v.d_sort) < tonumber(lowest_sort) or v.d_sort == "0" then
if tonumber(v.d_sort) >= 0 then
lowest_sort = v.d_sort
active_dialog = v
c_d_id = k
end
end
end
end
c_d_id = yl_speak_up.get_start_dialog_id(dialog)
if(c_d_id) then
active_dialog = dialog.n_dialogs[c_d_id]
end
else
-- it may be possible that this player can initialize this npc
minetest.log(