From 244377b2a941bf4b89531858e6781b69144d0346 Mon Sep 17 00:00:00 2001 From: Sokomine Date: Sun, 11 Sep 2022 21:55:02 +0200 Subject: [PATCH] fixed bug in action timers and added better debuging info --- exec_actions.lua | 40 +++++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/exec_actions.lua b/exec_actions.lua index ed025e6..31ad6a5 100644 --- a/exec_actions.lua +++ b/exec_actions.lua @@ -94,17 +94,19 @@ yl_speak_up.execute_next_action = function(player, a_id, result_of_a_id) -- is there a limiton how many failed attempts there can be per time? local timer_name = "timer_on_failure_"..tostring(d_id).."_"..tostring(o_id) local timer_data = yl_speak_up.get_variable_metadata( timer_name, "parameter", true) - if(timer_data - and timer_data["max_attempts"] and tonumber(timer_data["max_attempts"]) > 0 - and timer_data["duration"] and tonumber(timer_data["duration"]) > 0) then + or {} + local max_attempts = tonumber(timer_data["max_attempts"] or 0) + local duration = tonumber(timer_data["duration"] or 0) + if(max_attempts > 0 and duration > 0) then local new_times = "" local times = yl_speak_up.get_quest_variable_value(pname, timer_name) local parts = string.split(times or "", " ") local count = 0 for i, p in ipairs(parts) do - if(p and tonumber(p) - and (tonumber(p) + tonumber(timer_data["duration"])>time_now)) then - new_times = new_times.." "..p + p = tonumber(p) + -- eliminate entries that are in the future + if(p and p < time_now and (p + duration > time_now)) then + new_times = new_times.." "..tostring(p) count = count + 1 end end @@ -115,7 +117,13 @@ yl_speak_up.execute_next_action = function(player, a_id, result_of_a_id) elseif(new_times ~= times) then yl_speak_up.set_quest_variable_value(pname, timer_name, new_times) end - if(count >= tonumber(timer_data["max_attempts"])) then + if(count >= max_attempts) then + yl_speak_up.debug_msg(player, n_id, o_id, "Action for option ".. + tostring(d_id).."_"..tostring(o_id).. + " was attempted "..tostring(count).. + " times withhin the last "..tostring(duration).. + " seconds. Maximum allowed attempts are: ".. + tostring(max_attempts)..".") -- show the same dialog again, but with the failure message yl_speak_up.show_fs(player, "talk", {n_id = n_id, d_id = d_id, alternate_text = timer_data[ "alternate_text" ] @@ -126,12 +134,22 @@ yl_speak_up.execute_next_action = function(player, a_id, result_of_a_id) -- is there a limiton how fast the action may be repeated again? timer_name = "timer_on_success_"..tostring(d_id).."_"..tostring(o_id) timer_data = yl_speak_up.get_variable_metadata(timer_name, "parameter", true) - if(timer_data - and timer_data["duration"] and tonumber(timer_data["duration"]) > 0) then + or {} + duration = tonumber(timer_data["duration"] or 0) + if(duration > 0) then local last_time = yl_speak_up.get_quest_variable_value(pname, timer_name) - if(last_time and tonumber(last_time) - and tonumber(last_time) + tonumber(timer_data["duration"]) > time_now) then + last_time = tonumber(last_time or 0) + -- timers in the future are ignored + if(last_time > 0 and last_time < time_now + and last_time + duration > time_now) then -- show the same dialog again, but with the failure message + yl_speak_up.debug_msg(player, n_id, o_id, "Action for option ".. + tostring(d_id).."_"..tostring(o_id).. + " has last been completed ".. + tostring(time_now - last_time).. + " seconds ago. It can only be repeated after ".. + tostring(duration).. + " seconds have passed.") yl_speak_up.show_fs(player, "talk", {n_id = n_id, d_id = d_id, alternate_text = timer_data[ "alternate_text" ] or yl_speak_up.standard_text_if_action_repeated_too_soon})