count visits to options

This commit is contained in:
Sokomine 2024-02-29 12:40:59 +01:00
parent 6381ea59b9
commit 189165dd22
3 changed files with 31 additions and 0 deletions

View File

@ -48,3 +48,28 @@ yl_speak_up.count_visits_to_dialog = function(pname)
dialog.n_dialogs[d_id].visits = dialog.n_dialogs[d_id].visits + 1
end
end
-- count visits to options - but *not* for generic dialogs as those are just linked and not
-- copied for each player;
-- called after all effects have been executed successfully
-- not called in edit_mode because effects are not executed there
yl_speak_up.count_visits_to_option = function(pname, o_id)
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])
or not(o_id)
or not(dialog.n_dialogs[d_id].d_options)
or not(dialog.n_dialogs[d_id].d_options[o_id])) then
return
end
local o_data = dialog.n_dialogs[d_id].d_options[o_id]
if(not(o_data.is_generic)) then
if(not(o_data.visits)) then
o_data.visits = 0
end
o_data.visits = o_data.visits + 1
end
end

View File

@ -60,6 +60,8 @@ yl_speak_up.execute_all_relevant_effects = function(player, effects, o_id, actio
n_id, d_id, o_id)
end
yl_speak_up.debug_msg(player, n_id, o_id, "No effects given.")
-- the player has visited this option successfully
yl_speak_up.count_visits_to_option(pname, o_id)
-- no effects? Then...return to the start dialog
return {next_dialog = "", alternate_text = nil}
end
@ -137,6 +139,7 @@ yl_speak_up.execute_all_relevant_effects = function(player, effects, o_id, actio
tostring(r.r_id)..". New target dialog: "..tostring(r.r_value)..".")
-- we also stop execution here
-- any quest step is NOT set (because effects and/or action weren't successful)
-- the visit counter for this option is not incresed - after all the visit failed
return {next_dialog = r.r_value, alternate_text = r.alternate_text}
end
last_result = res
@ -161,6 +164,8 @@ yl_speak_up.execute_all_relevant_effects = function(player, effects, o_id, actio
yl_speak_up.quest_step_reached(player, d_option.quest_step, d_option.quest_id,
n_id, d_id, o_id)
end
-- the player has visited this option successfully
yl_speak_up.count_visits_to_option(pname, o_id)
return {next_dialog = target_dialog, alternate_text = alternate_text}
end

View File

@ -224,6 +224,7 @@ yl_speak_up.get_fs_talkdialog_line = function(
sb_v.o_text_when_prerequisites_not_met, dialog, pname))
end
if(t or t_alt) then
-- if(t) then t = "Visits: "..tostring(sb_v.visits or 0).." "..tostring(t) end
-- actually show the button
h = yl_speak_up.add_edit_button_fs_talkdialog(formspec, h,
"button_" .. oid,