mirror of
https://gitea.your-land.de/Sokomine/yl_speak_up.git
synced 2025-06-16 13:48:06 +02:00
added topics to dynamic dialogs as demonstration; also added common replacements like $ as demo
This commit is contained in:
parent
db2abf76fe
commit
48243f2ddc
@ -2,10 +2,11 @@
|
||||
-- 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.
|
||||
-- The strings topics are added as parameters to the dialog options.
|
||||
-- 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,
|
||||
new_text, answers, topics,
|
||||
back_option_o_id, back_option_target_dialog)
|
||||
if(not(player)) then
|
||||
return
|
||||
@ -29,6 +30,9 @@ yl_speak_up.generate_next_dynamic_dialog_simple = function(
|
||||
dialog.n_dialogs["d_dynamic"].d_text = new_text
|
||||
-- add all the answers:
|
||||
dialog.n_dialogs["d_dynamic"].d_options = {}
|
||||
if(not(topics)) then
|
||||
topics = {}
|
||||
end
|
||||
for i, text in ipairs(answers) do
|
||||
local future_o_id = "o_" .. tostring(i)
|
||||
-- add the dialog option as such:
|
||||
@ -39,6 +43,9 @@ yl_speak_up.generate_next_dynamic_dialog_simple = function(
|
||||
o_sort = i,
|
||||
o_text_when_prerequisites_not_met = "",
|
||||
o_text_when_prerequisites_met = (text or ""),
|
||||
-- some additional information to make it easier to
|
||||
-- react to a selected answer:
|
||||
tmp_topic = topics[i],
|
||||
}
|
||||
|
||||
-- create a fitting dialog result automaticly:
|
||||
@ -76,21 +83,64 @@ yl_speak_up.generate_next_dynamic_dialog = function(player, n_id, d_id, alternat
|
||||
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"..
|
||||
local dialog = yl_speak_up.speak_to[pname].dialog
|
||||
local prev_answer = "- unknown -"
|
||||
local tmp_topic = "- none -"
|
||||
if(dialog.n_dialogs[prev_d_id]
|
||||
and dialog.n_dialogs[prev_d_id].d_options
|
||||
and dialog.n_dialogs[prev_d_id].d_options[selected_o_id]
|
||||
and dialog.n_dialogs[prev_d_id].d_options[selected_o_id].o_text_when_prerequisites_met) then
|
||||
prev_answer = dialog.n_dialogs[prev_d_id].d_options[selected_o_id].o_text_when_prerequisites_met
|
||||
tmp_topic = dialog.n_dialogs[prev_d_id].d_options[selected_o_id].tmp_topic
|
||||
end
|
||||
-- pname is the name of the player; d_id is "d_dynamic"
|
||||
local new_text = "Hello $PLAYER_NAME$,\n".. -- also: pname
|
||||
"you're talking to me, $NPC_NAME$, who has the NPC ID "..tostring(n_id)..".\n"..
|
||||
"Previous dialog: "..tostring(prev_d_id)..".\n"..
|
||||
"Selected option: "..tostring(selected_o_id).."."
|
||||
"Selected option: "..tostring(selected_o_id).." with the text:\n"..
|
||||
"\t\""..tostring(prev_answer).."\".\n"..
|
||||
"We have shared "..tostring(dialog.n_dialogs["d_dynamic"].tmp_count or 0)..
|
||||
" such continous dynamic dialogs this time.\n"
|
||||
-- the answers/options the player can choose from:
|
||||
local answers = {"Hi!", "Can I help you?", "What is your name?", "Who is your employer?",
|
||||
local answers = {"$GOOD_DAY$! My name is $PLAYER_NAME$.",
|
||||
"Can I help you, $NPC_NAME$?",
|
||||
"What is your name? I'm called $PLAYER_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!"}
|
||||
"That's too boring. Let's talk normal again!"}
|
||||
-- store a topic for each answer so that the NPC can reply accordingly:
|
||||
local topics = {"my_name", "help_offered", "your_name", "your_employer", "your_job",
|
||||
"help_me", "test", "back"}
|
||||
-- react to the previously selected topic (usually you'd want a diffrent new_text,
|
||||
-- answers and topics based on what the player last selected; this here is just for
|
||||
-- demonstration):
|
||||
if(tmp_topic == "my_name") then
|
||||
new_text = new_text.."Pleased to meet you, $PLAYER_NAME$!"
|
||||
elseif(tmp_topic == "help_offered") then
|
||||
new_text = new_text.."Thanks! But I don't need any help right now."
|
||||
elseif(tmp_topic == "your_name") then
|
||||
new_text = new_text.."Thank you for asking for my name! It is $NPC_NAME$."
|
||||
elseif(tmp_topic == "your_employer") then
|
||||
new_text = new_text.."I work for $OWNER_NAME$."
|
||||
elseif(tmp_topic == "your_job") then
|
||||
new_text = new_text.."My job is to answer questions from adventurers like yourself."
|
||||
elseif(tmp_topic == "help_me") then
|
||||
new_text = new_text.."I'm afraid I'm unable to help you."
|
||||
elseif(tmp_topic == "test") then
|
||||
new_text = new_text.."Your test was successful. We're talking."
|
||||
else
|
||||
new_text = new_text.."Feel free to talk to me! Just choose an answer or question."
|
||||
end
|
||||
-- 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"
|
||||
-- store some additional values:
|
||||
if(d_id ~= "d_dynamic" or not(dialog.n_dialogs["d_dynamic"].tmp_count)) then
|
||||
dialog.n_dialogs["d_dynamic"].tmp_count = 0
|
||||
end
|
||||
dialog.n_dialogs["d_dynamic"].tmp_count = dialog.n_dialogs["d_dynamic"].tmp_count + 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)
|
||||
new_text, answers, topics, back_option_o_id, back_option_target_dialog)
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user