first implementation of actual d_dynamic execution

This commit is contained in:
Sokomine 2024-02-14 04:10:08 +01:00
parent e3e03ee990
commit 774b076f3b
3 changed files with 38 additions and 0 deletions

27
dynamic_dialog.lua Normal file
View File

@ -0,0 +1,27 @@
-- the dialog will be modified for this player only:
-- (pass on all the known parameters in case they're relevant):
-- called from yl_speak_up.get_fs_talkdialog(..):
yl_speak_up.generate_next_dynamic_dialog = function(player, n_id, d_id, alternate_text, recursion_depth)
if(not(player)) then
return
end
local pname = player:get_player_name()
if(not(yl_speak_up.speak_to[pname])) then
return
end
local dialog = yl_speak_up.speak_to[pname].dialog
if(not(dialog)) then
return
end
local dyn_dialog = dialog.n_dialogs["d_dynamic"]
if(not(dyn_dialog)) then
return
end
-- which dialog did the player come from?
local prev_d_id = yl_speak_up.speak_to[pname].d_id
-- the dialog d_dynamic is modified directly; we do not return anything
dyn_dialog.d_text = "Hello "..tostring(pname)..". You used d_id: "..tostring(d_id)..
" while talking to NPC "..tostring(n_id)..".\n"..
"Previous dialog: "..tostring(prev_d_id).."."
end

View File

@ -456,6 +456,15 @@ yl_speak_up.get_fs_talkdialog = function(player, n_id, d_id, alternate_text, rec
if c_d_id == nil then return yl_speak_up.get_error_message() end
-- show the player a dynamic dialog text:
if(c_d_id == "d_dynamic") then
-- the dialog will be modified for this player only:
-- (pass on all the known parameters in case they're relevant):
yl_speak_up.generate_next_dynamic_dialog(player, n_id, d_id, alternate_text, recursion_depth)
-- just to make sure that the right dialog is loaded:
active_dialog = dialog.n_dialogs[c_d_id]
end
yl_speak_up.speak_to[pname].d_id = c_d_id
-- Now we have a dialog to display to the user

View File

@ -155,6 +155,8 @@ yl_speak_up.reload = function(modpath, log_entry)
dofile(modpath .. "fs/fs_show_log.lua")
-- general decoration part for main formspec, trade window etc.
dofile(modpath .. "api/api_decorated.lua")
-- change dialog d_dynamic via an extra function on the fly when the player talks to the NPC:
dofile(modpath .. "dynamic_dialog.lua")
-- the formspec and input handling for the main dialog
dofile(modpath .. "api/api_talk.lua")
dofile(modpath .. "fs/fs_talkdialog.lua")