implemented d_end

This commit is contained in:
Sokomine 2022-07-11 19:48:50 +02:00
parent 952111c7fe
commit 80ce8d4892
7 changed files with 50 additions and 4 deletions

View File

@ -49,6 +49,15 @@ effect/result Further effects (like setting variables, handing out items)
alternate text Text shown instead of the normal dialog text.
Special dialogs
===============
In general, dialogs follow the naming schem "d_<nr>". However, some few have a
special meaning:
d_end End the conversation (i.e. after teleporting the player).
d_got_item The NPC got something and is trying to decide what to do with it.
How to configure NPC and add dialogs
====================================
There are two ways:

View File

@ -68,7 +68,7 @@ yl_speak_up.rewrite_dialog_id = function(data, field_name, start_dialog, append_
if(data[field_name] == start_dialog
or data[field_name]..append_str == start_dialog) then
return "d_generic_start_dialog"
elseif(data[field_name] ~= "d_got_item") then
elseif(data[field_name] ~= "d_got_item" and data[field_name] ~= "d_end") then
return data[field_name]..append_str
end
return data[field_name]

View File

@ -228,6 +228,11 @@ yl_speak_up.execute_next_action = function(player, a_id, result_of_a_id)
local target_dialog = res.next_dialog
yl_speak_up.speak_to[pname].o_id = nil
yl_speak_up.speak_to[pname].a_id = nil
-- end conversation
if(target_dialog and target_dialog == "d_end") then
yl_speak_up.stop_talking(pname)
return
end
if(not(target_dialog)
or target_dialog == ""
or not(dialog.n_dialogs[target_dialog])) then

View File

@ -344,6 +344,10 @@ yl_speak_up.show_colored_dialog_text = function(dialog, data, d_id, hypertext_po
color = "777777"
text = "[This dialog shall only have automatic options. The text is therefore irrelevant.]"
end
if(d_id == "d_end") then
color = "777777"
text = "[The NPC will end this conversation.]"
end
if(data and data.alternate_text and data.alternate_text ~= "") then
add_info_alternate_text = alternate_label_text
-- replace $TEXT$ with the normal dialog text and make the new text yellow

View File

@ -330,7 +330,7 @@ yl_speak_up.get_fs_edit_option_dialog = function(player, n_id, d_id, o_id, calle
local sorted_key_list = yl_speak_up.sort_keys(results)
for i, k in ipairs(sorted_key_list) do
local v = results[ k ]
if v.r_type == "dialog" and dialog.n_dialogs[v.r_value] ~= nil then
if v.r_type == "dialog" and (dialog.n_dialogs[v.r_value] ~= nil or v.r_value == "d_end" or v.r_value == "d_got_item") then
list_of_effects = list_of_effects..
minetest.formspec_escape(v.r_id)..",#999999,"..
minetest.formspec_escape(v.r_type)..","..
@ -357,7 +357,10 @@ yl_speak_up.get_fs_edit_option_dialog = function(player, n_id, d_id, o_id, calle
end
-- if no target dialog has been selected: default is to go to the dialog with d_sort 0
if(not(target_dialog) or target_dialog == "" or not(dialog.n_dialogs[target_dialog])) then
if(not(target_dialog) or target_dialog == "" or
(not(dialog.n_dialogs[target_dialog])
and target_dialog ~= "d_end"
and target_dialog ~= "d_got_item")) then
for d, v in pairs(dialog.n_dialogs) do
if(v.d_sort and tonumber(v.d_sort) == 0) then
target_dialog = d
@ -379,7 +382,11 @@ yl_speak_up.get_fs_edit_option_dialog = function(player, n_id, d_id, o_id, calle
dialog_selected = tostring(n)
end
end
if(target_dialog == "d_end") then
dialog_selected = tostring(n + 1)
end
end
dialog_list = dialog_list..",d_end"
if(not(target_dialog)) then
target_dialog = "- none -"
end

View File

@ -1,5 +1,10 @@
-- This is the main talkdialog the NPC shows when right-clicked.
yl_speak_up.stop_talking = function(pname)
yl_speak_up.edit_mode[pname] = nil
yl_speak_up.speak_to[pname] = nil
minetest.close_formspec(pname, "yl_speak_up:talk")
end
yl_speak_up.input_talk = function(player, formname, fields)
if formname ~= "yl_speak_up:talk" then
@ -377,6 +382,13 @@ yl_speak_up.get_fs_talkdialog = function(player, n_id, d_id, alternate_text, rec
local target_dialog = res.next_dialog
yl_speak_up.speak_to[pname].o_id = nil
yl_speak_up.speak_to[pname].a_id = nil
-- end the conversation?
if(target_dialog and target_dialog == "d_end") then
yl_speak_up.stop_talking(pname)
-- a formspec is expected here; provide one that has an exit button only
return "size[2,1]"..
"button_exit[0,0;1,1;Exit;exit]"
end
if(not(target_dialog)
or target_dialog == ""
or not(dialog.n_dialogs[target_dialog])) then
@ -448,6 +460,8 @@ yl_speak_up.get_fs_talkdialog = function(player, n_id, d_id, alternate_text, rec
end
d_id_to_dropdown_index[d] = i + 1
end
dialog_list = dialog_list..",d_end"
d_id_to_dropdown_index["d_end"] = #sorted_list + 2
table.insert(formspec, "label[0.2,4.6;Dialog:]") -- "..minetest.formspec_escape(c_d_id)..":]")
table.insert(formspec, "dropdown[3.0,4.0;5,1;d_id;"..dialog_list..";"..
@ -518,7 +532,10 @@ yl_speak_up.get_fs_talkdialog = function(player, n_id, d_id, alternate_text, rec
local has_other_results = false
if(results ~= nil) then
for k, v in pairs(results) do
if v.r_type == "dialog" and dialog.n_dialogs[v.r_value] ~= nil then
if v.r_type == "dialog"
and (dialog.n_dialogs[v.r_value] ~= nil
or v.r_value == "d_end"
or v.r_value == "d_got_item") then
-- there may be more than one in the data structure
target_dialog = v.r_value
elseif v.r_type ~= "dialog" then

View File

@ -240,6 +240,10 @@ yl_speak_up.show_fs = function(player, fs_name, param)
if(not(param)) then
param = {}
end
if(param.d_id and param.d_id == "d_end") then
yl_speak_up.stop_talking(pname)
return
end
yl_speak_up.show_fs_ver(pname, "yl_speak_up:talk",
-- recursion depth from autoanswer: 0 (the player selected manually)
yl_speak_up.get_fs_talkdialog(player, param.n_id, param.d_id, param.alternate_text,0))