mirror of
https://gitea.your-land.de/Sokomine/yl_speak_up.git
synced 2025-07-08 06:48:54 +02:00
97 lines
3.7 KiB
Lua
97 lines
3.7 KiB
Lua
|
|
-- This is a quick way to generate a simple d_dynamic dialog with
|
|
-- displayed text new_text and options/answers from the table
|
|
-- (list) answers.
|
|
-- TODO: do the common replacements like $PLAYER_NAME$, $NPC_NAME$ etc?
|
|
yl_speak_up.generate_next_dynamic_dialog_simple = function(
|
|
player, n_id, d_id, alternate_text, recursion_depth,
|
|
new_text, answers,
|
|
back_option_o_id, back_option_target_dialog)
|
|
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
|
|
-- set the new text:
|
|
dialog.n_dialogs["d_dynamic"].d_text = new_text
|
|
-- add all the answers:
|
|
dialog.n_dialogs["d_dynamic"].d_options = {}
|
|
for i, text in ipairs(answers) do
|
|
local future_o_id = "o_" .. tostring(i)
|
|
-- add the dialog option as such:
|
|
dialog.n_dialogs["d_dynamic"].d_options[future_o_id] = {
|
|
o_id = future_o_id,
|
|
o_hide_when_prerequisites_not_met = "false",
|
|
o_grey_when_prerequisites_not_met = "false",
|
|
o_sort = i,
|
|
o_text_when_prerequisites_not_met = "",
|
|
o_text_when_prerequisites_met = (text or ""),
|
|
}
|
|
|
|
-- create a fitting dialog result automaticly:
|
|
-- give this new dialog a dialog result that leads back to this dialog
|
|
-- (this can be changed later on if needed):
|
|
local future_r_id = "r_1"
|
|
-- actually store the new result
|
|
dialog.n_dialogs["d_dynamic"].d_options[future_o_id].o_results = {}
|
|
dialog.n_dialogs["d_dynamic"].d_options[future_o_id].o_results[future_r_id] = {
|
|
r_id = future_r_id,
|
|
r_type = "dialog",
|
|
r_value = "d_dynamic"}
|
|
end
|
|
-- go back to back_option_target_dialog:
|
|
if(back_option_o_id
|
|
and dialog.n_dialogs["d_dynamic"].d_options[back_option_o_id]) then
|
|
dialog.n_dialogs["d_dynamic"].d_options[back_option_o_id].o_results["r_1"].r_value =
|
|
back_option_target_dialog
|
|
end
|
|
end
|
|
|
|
|
|
-- 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
|
|
-- which dialog did the player come from?
|
|
local prev_d_id = yl_speak_up.speak_to[pname].d_id
|
|
local selected_o_id = yl_speak_up.speak_to[pname].selected_o_id
|
|
-- the text the NPC shall say:
|
|
local new_text = "Hello "..tostring(pname)..".\n"..
|
|
"You used d_id: "..tostring(d_id)..
|
|
" while talking to NPC "..tostring(n_id)..".\n"..
|
|
"Previous dialog: "..tostring(prev_d_id)..".\n"..
|
|
"Selected option: "..tostring(selected_o_id).."."
|
|
-- the answers/options the player can choose from:
|
|
local answers = {"Hi!", "Can I help you?", "What is your name?", "Who is your employer?",
|
|
"What are you doing here?", "Help me, please!", "This is just a test.",
|
|
"That's too stupid. Let's talk normal again!"}
|
|
-- With this answer/option, the player can leave the d_dynamic dialog and return..
|
|
local back_option_o_id = "o_"..tostring(#answers)
|
|
-- ..back to dialog d_1 (usually the start dialog):
|
|
local back_option_target_dialog = "d_1"
|
|
-- actually update the d_dynamic dialog
|
|
return yl_speak_up.generate_next_dynamic_dialog_simple(
|
|
player, n_id, d_id, alternate_text, recursion_depth,
|
|
new_text, answers, back_option_o_id, back_option_target_dialog)
|
|
end
|