mirror of
https://gitea.your-land.de/Sokomine/yl_speak_up.git
synced 2025-07-24 14:28:54 +02:00
created yl_speak_up.generate_next_dynamic_dialog_simple
This commit is contained in:
parent
774b076f3b
commit
691301019b
@ -1,8 +1,12 @@
|
||||
|
||||
-- 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)
|
||||
-- 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
|
||||
@ -21,7 +25,72 @@ yl_speak_up.generate_next_dynamic_dialog = function(player, n_id, d_id, alternat
|
||||
-- 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).."."
|
||||
-- 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
|
||||
|
@ -155,7 +155,7 @@ yl_speak_up.input_talk = function(player, formname, fields)
|
||||
|
||||
-- we may soon need actions and o_results from the selected_option
|
||||
local selected_option = {}
|
||||
if(yl_speak_up.check_if_dialog_has_option(dialog, d_id, o)) then
|
||||
if(yl_speak_up.check_if_dialog_has_option(dialog, d_id, o)) then
|
||||
selected_option = dialog.n_dialogs[d_id].d_options[o]
|
||||
end
|
||||
|
||||
@ -164,6 +164,8 @@ yl_speak_up.input_talk = function(player, formname, fields)
|
||||
return
|
||||
end
|
||||
yl_speak_up.speak_to[pname].o_id = o
|
||||
-- store this a bit longer than o_id above (for yl_speak_up.generate_next_dynamic_dialog):
|
||||
yl_speak_up.speak_to[pname].selected_o_id = o
|
||||
-- start with executing the first action
|
||||
yl_speak_up.execute_next_action(player, nil, true, formname)
|
||||
return
|
||||
|
Loading…
Reference in New Issue
Block a user