Signup Now
Results 1 to 6 of 6
  1. #1
    Free User Cezarus's Avatar
    Join Date
    Jul 2014
    Location
    Proland
    Posts
    57
    Reputation
    14
    Rep Power
    20

    Time Counter (To count how much time u lost on refil for example)

    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
    Last edited by Cezarus; 08-26-2014 at 06:44 PM.
    Seminari
    [FREE] Port Hope Coryms for ek (90-120 exp/h 16-22 k gold/h)
    http://forums.tibiawindbot.com/attac...2&d=1409228006
    Sort your loot even in depot!
    http://forums.tibiawindbot.com/showt...-even-in-depot!

  2. #2
    Moderator Raphael's Avatar
    Join Date
    Dec 2013
    Location
    raphseller.com
    Posts
    2,441
    Reputation
    309
    Rep Power
    28
    I've been thinking of writing something like this for a while already.
    Pretty nice job.

  3. #3
    Free User Cezarus's Avatar
    Join Date
    Jul 2014
    Location
    Proland
    Posts
    57
    Reputation
    14
    Rep Power
    20
    Fixed few bugs + added new function to restart counters:

    resetTimers(mainQueryTimer4x) --<-- mainQueryTimer4x should be replaced with name of your query in database

    exaple of hotkey:

    -- use it to reset timers
    resetTimers("PHCoryms_PHDPTimer")
    resetTimers("PHCoryms_CorymsWay")
    resetTimers("PHCoryms_RafzanTime")
    Seminari
    [FREE] Port Hope Coryms for ek (90-120 exp/h 16-22 k gold/h)
    http://forums.tibiawindbot.com/attac...2&d=1409228006
    Sort your loot even in depot!
    http://forums.tibiawindbot.com/showt...-even-in-depot!

  4. #4
    Free User
    Join Date
    Aug 2014
    Location
    Rio de Janeiro - Brazil
    Posts
    356
    Reputation
    66
    Rep Power
    20
    This idea is great, I tried to tweak those settings to suit my needs but my LUA skills aren`t good. I'm trying to make timerCheck() work without having to use timerStopCounting(). Why? Because I`m trying to check all the time if timerCheck() <= specifictime

    And the way it works now I need to stop my current counting to check the time.

    Can any enlightened soul help me tweaking it to my needs? Maybe @Raphael? It doesn`t seems to be hard, I will keep trying anyway.

  5. #5
    Moderator Raphael's Avatar
    Join Date
    Dec 2013
    Location
    raphseller.com
    Posts
    2,441
    Reputation
    309
    Rep Power
    28
    Quote Originally Posted by Jesseh View Post
    This idea is great, I tried to tweak those settings to suit my needs but my LUA skills aren`t good. I'm trying to make timerCheck() work without having to use timerStopCounting(). Why? Because I`m trying to check all the time if timerCheck() <= specifictime

    And the way it works now I need to stop my current counting to check the time.

    Can any enlightened soul help me tweaking it to my needs? Maybe @Raphael? It doesn`t seems to be hard, I will keep trying anyway.
    Sorry, what exactly is it that you want?

  6. #6
    Free User
    Join Date
    Aug 2014
    Location
    Rio de Janeiro - Brazil
    Posts
    356
    Reputation
    66
    Rep Power
    20
    Quote Originally Posted by Raphael View Post
    Sorry, what exactly is it that you want?
    What happens now: I use timerStartCounting('timer'). I can`t check with timerCheck('timer') now because it returns Zero, unless I do timerStopCounting('timer').

    What I want: Use timerStartCounting('timer'), then I have a persistent that is always checking a condition, lets say: auto(100) if timerCheck('timer') > 10 then gotolabel() end. I want timerCheck('timer') to return the time that has passed since I used timerStartCounting('timer') without having to actually stop the timer. I just need timerCheck() to return the time that has passed since I started that timer.

    I didn`t understand $chardb:getvalue and setvalue very well as they aren`t very good documented.

    Edit: Corrected it by using a sloppy solution, but working now.

    function timerCheck(mainQueryTimer3x)
    if $chardb:getvalue(mainQueryTimer3x, mainQueryTimer3x.."CountedTime") ~= nil then
    local startedWhen = tonumber($chardb:getvalue(mainQueryTimer3x, mainQueryTimer3x.."StartCount"))
    local countedValue = tonumber(os.difftime(os.time(), startedWhen))
    $chardb:setvalue(mainQueryTimer3x, mainQueryTimer3x.."CountedTime", tonumber(countedValue))
    if (tonumber($chardb:getvalue(mainQueryTimer3x, mainQueryTimer3x.."CountedTime")) < 0) then
    $chardb:setvalue(mainQueryTimer3x, mainQueryTimer3x.."CountedTime", 0)
    elseif (tonumber($chardb:getvalue(mainQueryTimer3x, mainQueryTimer3x.."CountedTime")) > 86400) then
    $chardb:setvalue(mainQueryTimer3x, mainQueryTimer3x.."CountedTime", 0)
    end
    else
    $chardb:setvalue(mainQueryTimer3x, mainQueryTimer3x.."CountedTime", 0)
    end
    return tonumber($chardb:getvalue(mainQueryTimer3x, mainQueryTimer3x.."CountedTime"))
    end
    Last edited by Jesseh; 07-30-2015 at 03:35 PM. Reason: corrected

 

 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •