I made this to my cavebot script [Coryms Port Hope with Rafzan]:
http://forums.tibiawindbot.com/showt...afzan-included
So here we go:
-- TIMER FUNCTIONS by Seminari (Cezarus)
-- mainQueryTimer <-- your query name in database
-- example:
-- put in waypoint 001 action and paste: timerStartCounting("exampleTimerLala")
-- then make some waypoints, and put in one action: timerStopCounting("exampleTimerLala")
-- okey, now you have to use function: timerCheck("exampleTimerLala")
-- timerCheck("exampleTimerLala") <-- will return how much seconds you counted between labels with actions
-- timerStartCounting("exampleTimerLala") and timerStopCounting("exampleTimerLala")
-- it's useful, you can use it to count how much time you wasted on refil :)
-- example of HUD to show time counted:
--init start
--local fontsize = 10
--local fontspacing = fontsize + 6
--setfontstyle('Tahoma', fontsize, 99, 0xE9D338, 1, 0)
--setmaskcolorxp(0)
--init end
--auto(1000)
--setposition($worldwin.right - 200, $worldwin.bottom-80)
--drawtext('Counted time: '..timerCheck("testTimera1").. ' in seconds', 2, 0)
--drawtext('Counted time: '..timerCheck("testTimera1")/60 .. ' in minutes', 2, fontspacing)
--drawtext('Counted time: '..timerCheck("testTimera1")/3600 .. ' in hours', 2, fontspacing*2)
function timerStartCounting(mainQueryTimer1x)
$chardb:setvalue(mainQueryTimer1x, mainQueryTimer1x.."StartCount", os.time())
end
function timerStopCounting(mainQueryTimer2x)
$chardb:setvalue(mainQueryTimer2x, mainQueryTimer2x.."StopCount", os.time())
local startedWhen = tonumber($chardb:getvalue(mainQueryTimer2x, mainQueryTimer2x.."StartCount"))
local stopedWhen = tonumber($chardb:getvalue(mainQueryTimer2x, mainQueryTimer2x.."StopCount"))
local countedValue = tonumber(os.difftime(stopedWhen, startedWhen))
$chardb:setvalue(mainQueryTimer2x, mainQueryTimer2x.."CountedTime", tonumber(timerCheck(mainQueryTimer2x)) + countedValue)
end
function timerCheck(mainQueryTimer3x)
if $chardb:getvalue(mainQueryTimer3x, mainQueryTimer3x.."CountedTime") ~= nil then
if not (tonumber($chardb:getvalue(mainQueryTimer3x, mainQueryTimer3x.."CountedTime")) >= 0) then
$chardb:setvalue(mainQueryTimer3x, mainQueryTimer3x.."CountedTime", 0)
end
else
$chardb:setvalue(mainQueryTimer3x, mainQueryTimer3x.."CountedTime", 0)
end
return tonumber($chardb:getvalue(mainQueryTimer3x, mainQueryTimer3x.."CountedTime"))
end
function timerSecondsToTime(secondsLalala)
if not (secondsLalala ~= nil) then
secondsLalala = 0
end
local xTxT_sec = secondsLalala
local xTxT_min = 0
local xTxT_h = 0
if xTxT_sec >= 3600 then
xTxT_h = math.floor(xTxT_sec/3600)
xTxT_sec = xTxT_h - (xTxT_min * 3660)
end
if xTxT_sec >= 60 and xTxT_sec < 3600 then
xTxT_min = math.floor(xTxT_sec/60)
xTxT_sec = xTxT_sec - (xTxT_min * 60)
end
return "[".. xTxT_h ..":".. xTxT_min ..":".. xTxT_sec .."]"
end
function resetTimers(mainQueryTimer4x)
$chardb:setvalue(mainQueryTimer4x, mainQueryTimer4x .."StartCount", 0)
$chardb:setvalue(mainQueryTimer4x, mainQueryTimer4x .."StopCount", 0)
$chardb:setvalue(mainQueryTimer4x, mainQueryTimer4x .."CountedTime", 0)
end
------->>><<<-----<<<>>>-----|^\/^|-----<<<>>>----->>><<<-------|
Screen, how to config it in cavebot waypoints:
example of HUD:
init start
local fontsize = 10
local fontspacing = fontsize + 6
setfontstyle('Tahoma', fontsize, 99, 0xE9D338, 1, 0)
setmaskcolorxp(0)
init end
auto(1000)
rrrlll = timerSecondsToTime(timerCheck("testTimera1"))
theTimerSuper = "[".. rrrlll.h ..":".. rrrlll.m ..":".. rrrlll.s .."]"
setposition($worldwin.right - 200, $worldwin.bottom-80)
drawtext('Counted time: '..timerCheck("testTimera1").. ' seconds', 2, 0)
drawtext('Counted time: '.. math.ceil(timerCheck("testTimera1")/60) .. ' minutes', 2, fontspacing)
drawtext('Counted time: '.. math.ceil(timerCheck("testTimera1")/3600) .. ' hours', 2, fontspacing*2)
drawtext('Counted time: '.. theTimerSuper .. '', 2, fontspacing*3)
HUD screen:
edit 1 ///// fixed few bugs with function timerSecondsToTime(secondsLalala)
edit 2 ///some screens
edit 3 /// fixed few bugs + added function to restart counter