count visits to dialogs
This commit is contained in:
parent
c2107d0bf3
commit
6381ea59b9
|
@ -191,6 +191,7 @@ yl_speak_up.show_fs_npc_text = function(pname, formspec, dialog, alternate_text,
|
|||
-- replace $NPC_NAME$ etc.
|
||||
local t = minetest.formspec_escape(yl_speak_up.replace_vars_in_text(
|
||||
alternate_text, dialog, pname))
|
||||
-- t = "Visits to this dialog: "..tostring(active_dialog.visits).."\n"..t
|
||||
if(fs_version > 2) then
|
||||
yl_speak_up.add_formspec_element_with_tooltip_if(formspec,
|
||||
"hypertext", "0.2,5;19.6,17.8", "d_text",
|
||||
|
|
|
@ -30,3 +30,21 @@ yl_speak_up.get_start_dialog_id = function(dialog)
|
|||
end
|
||||
|
||||
|
||||
-- count visits to this dialog - but *not* for generic dialogs as those are just linked and not
|
||||
-- copied for each player; also not in edit_mode as it makes no sense there
|
||||
yl_speak_up.count_visits_to_dialog = function(pname)
|
||||
if(not(pname)) then
|
||||
return
|
||||
end
|
||||
local d_id = yl_speak_up.speak_to[pname].d_id
|
||||
local dialog = yl_speak_up.speak_to[pname].dialog
|
||||
if(not(d_id) or not(dialog) or not(dialog.n_dialogs) or not(dialog.n_dialogs[d_id])) then
|
||||
return
|
||||
end
|
||||
if(not(dialog.n_dialogs[d_id].is_generic)) then
|
||||
if(not(dialog.n_dialogs[d_id].visits)) then
|
||||
dialog.n_dialogs[d_id].visits = 0
|
||||
end
|
||||
dialog.n_dialogs[d_id].visits = dialog.n_dialogs[d_id].visits + 1
|
||||
end
|
||||
end
|
||||
|
|
|
@ -45,6 +45,16 @@ yl_speak_up.load_dialog = function(n_id, player) -- returns the saved dialog
|
|||
end
|
||||
|
||||
|
||||
-- in edit mode the dialog may be saved. visits to a particular dialog are of no intrest here
|
||||
local old_count_visits_to_dialog = yl_speak_up.count_visits_to_dialog
|
||||
yl_speak_up.count_visits_to_dialog = function(pname)
|
||||
if(yl_speak_up.in_edit_mode(pname)) then
|
||||
return
|
||||
end
|
||||
return old_count_visits_to_dialog(pname)
|
||||
end
|
||||
|
||||
|
||||
local modname = minetest.get_current_modname()
|
||||
if(not(modname)) then
|
||||
modname = "yl_speak_up"
|
||||
|
|
|
@ -201,11 +201,11 @@ end
|
|||
-- in edit mode, *all* options are displayed
|
||||
local old_calculate_displayable_options = yl_speak_up.calculate_displayable_options
|
||||
yl_speak_up.calculate_displayable_options = function(pname, d_options, allow_recursion)
|
||||
-- no options - nothing to do
|
||||
if(not(d_options)) then
|
||||
return {}
|
||||
end
|
||||
if(yl_speak_up.in_edit_mode(pname)) then
|
||||
-- no options - nothing to do
|
||||
if(not(d_options)) then
|
||||
return {}
|
||||
end
|
||||
-- in edit mode: show all options (but sort them first)
|
||||
local retval = {}
|
||||
local sorted_list = yl_speak_up.get_sorted_options(d_options, "o_sort")
|
||||
|
|
|
@ -477,6 +477,9 @@ yl_speak_up.get_fs_talkdialog = function(player, n_id, d_id, alternate_text, rec
|
|||
"label[0.2,0.5;Ups! Something went wrong. Please try again.]"
|
||||
end
|
||||
|
||||
-- how often has the player visted this dialog?
|
||||
yl_speak_up.count_visits_to_dialog(pname)
|
||||
|
||||
-- evaluate the preconditions of each option and check if the option can be offered
|
||||
local allowed = yl_speak_up.calculate_displayable_options(pname, active_dialog.d_options,
|
||||
-- avoid loops by limiting max recoursion depths for autoanswers
|
||||
|
|
Loading…
Reference in New Issue