created initial_config.lua so that overriding start dialogs becomes easier
This commit is contained in:
parent
f70bc72f85
commit
e2722d7c60
@ -116,8 +116,8 @@ yl_speak_up.add_to_command_help_text = yl_speak_up.add_to_command_help_text..
|
||||
dofile(modpath .. "exec_all_relevant_effects.lua")
|
||||
-- some helper functions for formatting text for a formspec talbe
|
||||
dofile(modpath .. "print_as_table.lua")
|
||||
-- -- create i.e. a dropdown list of player names
|
||||
-- dofile(modpath .. "api/formspec_helpers.lua")
|
||||
-- create i.e. a dropdown list of player names
|
||||
dofile(modpath .. "api/formspec_helpers.lua")
|
||||
-- handle alternate text for dialogs
|
||||
dofile(modpath .. "api/api_alternate_text.lua")
|
||||
-- helpful for debugging the content of the created dialog structure
|
||||
|
||||
@ -165,57 +165,10 @@ yl_speak_up.input_fs_initial_config = function(player, formname, fields)
|
||||
|
||||
-- give the NPC its first dialog
|
||||
if(not(dialog) or count==0) then
|
||||
local f = {}
|
||||
-- create a new dialog
|
||||
f.d_id = yl_speak_up.text_new_dialog_id
|
||||
-- ...with this text
|
||||
f.d_text = "$GOOD_DAY$ $PLAYER_NAME$,\n"..
|
||||
"I am $NPC_NAME$. I don't know much yet.\n"..
|
||||
"Hopefully $OWNER_NAME$ will teach me to talk soon."
|
||||
-- it is the first, initial dialog
|
||||
f.d_sort = "0"
|
||||
f.n_npc = fields.n_npc
|
||||
f.n_description = fields.n_description
|
||||
f.npc_owner = yl_speak_up.npc_owner[ n_id ]
|
||||
-- create and save the first dialog for this npc
|
||||
local dialog = yl_speak_up.fields_to_dialog(pname, f)
|
||||
-- TODO: pname == yl_speak_up.npc_owner[ n_id ] required
|
||||
-- initialize the NPC with first dialog, name, description and owner:
|
||||
yl_speak_up.initialize_npc_dialog_once(pname, nil, n_id, fields.n_npc, fields.n_description)
|
||||
|
||||
-- add example answers and dialogs; they may be irritating for experienced
|
||||
-- users, but help new users a lot in figuring out how the system works
|
||||
--
|
||||
-- first, we create three example dialogs as such:
|
||||
-- (the first one has already been created in the creation of the dialog;
|
||||
-- yl_speak_up.fields_to_dialog stores d_id in yl_speak_up.speak_to[pname].d_id)
|
||||
local new_d_1 = "d_1"
|
||||
local new_d_2 = yl_speak_up.add_new_dialog(dialog, pname, "2",
|
||||
"I'm glad that you wish me to talk to you.\n\n"..
|
||||
"I hope we can talk more soon!")
|
||||
local new_d_3 = yl_speak_up.add_new_dialog(dialog, pname, "3",
|
||||
"Oh! Do you really think so?\n\n"..
|
||||
"To me, talking is important.")
|
||||
-- we are dealing with a new NPC, so there are no options yet
|
||||
-- options added to dialog f.d_id:
|
||||
local new_d_1_o_1 = yl_speak_up.add_new_option(dialog, pname, nil,
|
||||
"d_1", "I hope so as well!", new_d_2)
|
||||
local new_d_1_o_2 = yl_speak_up.add_new_option(dialog, pname, nil,
|
||||
"d_1", "No. Talking is overrated.", new_d_3)
|
||||
-- options added to dialog new_d_2:
|
||||
local new_d_2_o_1 = yl_speak_up.add_new_option(dialog, pname, nil,
|
||||
"d_2", "Glad that we agree.", new_d_1)
|
||||
-- options added to dialog new_d_3:
|
||||
local new_d_3_o_1 = yl_speak_up.add_new_option(dialog, pname, nil,
|
||||
"d_3", "No. I was just joking. I want to talk to you!", new_d_2)
|
||||
local new_d_3_o_2 = yl_speak_up.add_new_option(dialog, pname, nil,
|
||||
"d_3", "Yes. Why am I talking to you anyway?", "d_end")
|
||||
-- save our new dialog
|
||||
yl_speak_up.save_dialog(n_id, dialog)
|
||||
yl_speak_up.speak_to[pname].dialog = dialog
|
||||
dialog.n_may_edit = {}
|
||||
-- now connect the dialogs via results
|
||||
yl_speak_up.log_change(pname, n_id,
|
||||
"Initial config saved. "..
|
||||
"NPC name: \""..tostring(fields.n_npc)..
|
||||
"\" Description: \""..tostring(fields.n_description).."\".")
|
||||
elseif(fields.add_may_edit and fields.add_may_edit ~= "") then
|
||||
yl_speak_up.save_dialog(n_id, dialog)
|
||||
yl_speak_up.log_change(pname, n_id,
|
||||
|
||||
6
init.lua
6
init.lua
@ -187,8 +187,8 @@ yl_speak_up.reload = function(modpath, log_entry)
|
||||
dofile(modpath .. "exec_apply_effects.lua")
|
||||
-- some helper functions for formatting text for a formspec talbe
|
||||
-- TODO dofile(modpath .. "print_as_table.lua")
|
||||
-- create i.e. a dropdown list of player names
|
||||
dofile(modpath .. "api/formspec_helpers.lua")
|
||||
-- -- create i.e. a dropdown list of player names
|
||||
-- TODO dofile(modpath .. "api/formspec_helpers.lua")
|
||||
-- -- handle alternate text for dialogs
|
||||
-- TODO dofile(modpath .. "api/api_alternate_text.lua")
|
||||
-- -- helpful for debugging the content of the created dialog structure
|
||||
@ -207,6 +207,8 @@ yl_speak_up.reload = function(modpath, log_entry)
|
||||
-- TODO dofile(modpath .. "fs/fs_edit_effects.lua")
|
||||
-- edit options dialog (detailed configuration of options in edit mode)
|
||||
-- TODO dofile(modpath .. "fs/fs_edit_options_dialog.lua")
|
||||
-- provide the NPC with an initial (example) dialog and store name, descr and owner:
|
||||
dofile(modpath .. "initial_config.lua")
|
||||
-- set name, description and owner (owner only with npc_talk_master priv)
|
||||
dofile(modpath .. "fs/fs_initial_config.lua")
|
||||
-- inspect and accept items the player gave to the NPC
|
||||
|
||||
80
initial_config.lua
Normal file
80
initial_config.lua
Normal file
@ -0,0 +1,80 @@
|
||||
|
||||
-- add example answers and dialogs; they may be irritating for experienced
|
||||
-- users, but help new users a lot in figuring out how the system works
|
||||
--
|
||||
-- first, we create three example dialogs as such:
|
||||
-- (the first one has already been created in the creation of the dialog;
|
||||
-- yl_speak_up.fields_to_dialog stores d_id in yl_speak_up.speak_to[pname].d_id)
|
||||
--
|
||||
-- Important: Overwrite this function if you want something diffrent here
|
||||
-- (i.e. texts in a language your players speak).
|
||||
yl_speak_up.setup_initial_dialog = function(dialog, pname)
|
||||
local new_d_1 = "d_1"
|
||||
local new_d_2 = yl_speak_up.add_new_dialog(dialog, pname, "2",
|
||||
"I'm glad that you wish me to talk to you.\n\n"..
|
||||
"I hope we can talk more soon!")
|
||||
local new_d_3 = yl_speak_up.add_new_dialog(dialog, pname, "3",
|
||||
"Oh! Do you really think so?\n\n"..
|
||||
"To me, talking is important.")
|
||||
-- we are dealing with a new NPC, so there are no options yet
|
||||
-- options added to dialog f.d_id:
|
||||
local new_d_1_o_1 = yl_speak_up.add_new_option(dialog, pname, nil,
|
||||
"d_1", "I hope so as well!", new_d_2)
|
||||
local new_d_1_o_2 = yl_speak_up.add_new_option(dialog, pname, nil,
|
||||
"d_1", "No. Talking is overrated.", new_d_3)
|
||||
-- options added to dialog new_d_2:
|
||||
local new_d_2_o_1 = yl_speak_up.add_new_option(dialog, pname, nil,
|
||||
"d_2", "Glad that we agree.", new_d_1)
|
||||
-- options added to dialog new_d_3:
|
||||
local new_d_3_o_1 = yl_speak_up.add_new_option(dialog, pname, nil,
|
||||
"d_3", "No. I was just joking. I want to talk to you!", new_d_2)
|
||||
local new_d_3_o_2 = yl_speak_up.add_new_option(dialog, pname, nil,
|
||||
"d_3", "Yes. Why am I talking to you anyway?", "d_end")
|
||||
end
|
||||
|
||||
|
||||
-- supply the NPC with its first (initial) dialog;
|
||||
-- pname will become the owner of the NPC;
|
||||
-- example call:
|
||||
-- yl_speak_up.initialize_npc_dialog_once(pname, nil, n_id, fields.n_npc, fields.n_description)
|
||||
yl_speak_up.initialize_npc_dialog_once = function(pname, dialog, n_id, npc_name, npc_description)
|
||||
local count = 0
|
||||
if(dialog and dialog.n_dialogs) then
|
||||
for k,v in pairs(dialog.n_dialogs) do
|
||||
count = count + 1
|
||||
end
|
||||
end
|
||||
|
||||
-- the NPC already has a dialog - do not overwrite it!
|
||||
if(dialog or count > 0) then
|
||||
return
|
||||
end
|
||||
|
||||
-- give the NPC its first dialog
|
||||
local f = {}
|
||||
-- create a new dialog
|
||||
f.d_id = yl_speak_up.text_new_dialog_id
|
||||
-- ...with this text
|
||||
f.d_text = "$GOOD_DAY$ $PLAYER_NAME$,\n"..
|
||||
"I am $NPC_NAME$. I don't know much yet.\n"..
|
||||
"Hopefully $OWNER_NAME$ will teach me to talk soon."
|
||||
-- it is the first, initial dialog
|
||||
f.d_sort = "0"
|
||||
f.n_npc = npc_name -- old: fields.n_npc
|
||||
f.n_description = npc_description -- old: fields.n_description
|
||||
f.npc_owner = pname -- old: yl_speak_up.npc_owner[ n_id ] (make sure to call it with right pname!)
|
||||
-- create and save the first dialog for this npc
|
||||
local dialog = yl_speak_up.fields_to_dialog(pname, f)
|
||||
-- overwrite this function if you want something diffrent added:
|
||||
yl_speak_up.setup_initial_dialog(dialog, pname)
|
||||
-- save our new dialog
|
||||
yl_speak_up.save_dialog(n_id, dialog)
|
||||
yl_speak_up.speak_to[pname].dialog = dialog
|
||||
dialog.n_may_edit = {}
|
||||
-- now connect the dialogs via results
|
||||
yl_speak_up.log_change(pname, n_id,
|
||||
"Initial config saved. "..
|
||||
"NPC name: \""..tostring(dialog.n_npc)..
|
||||
"\" Description: \""..tostring(dialog.n_description).."\".")
|
||||
return dialog
|
||||
end
|
||||
Loading…
Reference in New Issue
Block a user