Not enough cleo timers? Create/use unlimited number of precise timers with this snippet!
  1. Difference between cleo built-in TIMERA/TIMERB and this Snippet:
    • Cleo timers depend on ingame tick, unstable FPS leads to unprecise timer measurements on both TIMERA and TIMERB.
    • This snippets uses your Operating System's Tick Timer as reference to do precise timing measurements.
  2. To Increase the number of custom timers, Find(CTRL+F) CustomTimerRegion and add 4 bytes of hex for each new index you create.
PHP:
:GetLapseOfCustomTimer // 0AB1: @GetLapseOfCustomTimer 1 _TimerIndex 0@ _ReturnLapseOfTime 30@
    0AC6: 31@ = label @CustomTimerRegion pointer
    0@ *= 4 // 4 bytes for each index
    005A: 31@ += 0@  // custom timer index pointer
    0A8D: 31@ = read_memory 31@ size 4 virtual_protect 0 // read custom timer's TickCount
    0AB1: @GetSystemTickCount 0 _returnTickCount 30@ // get precise TickCount from system
    0062: 30@ -= 31@ // compute lapse of time for the custom timer index
0AB2: ret 1 30@

:ResetCustomTimer // 0AB1: @ResetCustomTimer 1 _TimerIndex 0@
    0AC6: 31@ = label @CustomTimerRegion pointer
    0@ *= 4 // 4 bytes for each index
    005A: 31@ += 0@  // custom timer index pointer
    0AB1: @GetSystemTickCount 0 _returnTickCount 30@ // get precise TickCount from system
    0A8C: write_memory 31@ size 4 value 30@ virtual_protect 0 // save
0AB2: ret 0

:CustomTimerRegion // in case you want to increase the number of custom timers, add 4 bytes of hex for each new custom timer
hex
    00 00 00 00 // timer index 0
    00 00 00 00 // timer index 1
    00 00 00 00 // timer index 2
    00 00 00 00 // timer index 3
    00 00 00 00 // timer index 4
end




If you use Wait Opcode that has duration above 0ms. Use this snippet instead!​
  • Difference between cleo built-in Opcode 0001(Wait)and this Snippet
    • Cleo wait depend on ingame tick, unstable FPS leads to unprecise waiting time that might've been affecting your cleo script.
    • This snippet uses your Operating System's Tick Timer as reference to do precise waiting.
PHP:
:PreciseWait // 0AB1: @PreciseWait 1 _MilliSeconds 0@
    0AB1: @GetSystemTickCount 0 _returnTickCount 31@ // start timer
    repeat
        0001: wait 0 ms
        0AB1: @GetSystemTickCount 0 _returnTickCount 30@ // monitor timer
        0062: 30@ -= 31@ // compute lapse of time
    until 002D: 30@ >= 0@ // timer had expired
0AB2: ret 0




Required SubSnippet:
PHP:
:GetSystemTickCount // 0AB1: @GetSystemTickCount 0 _ReturnTickCount 29@
    // gets the number of milliseconds had passed since system start-up
if 0AA2: 31@ = load_library "kernel32.dll"
then
    if 0AA4: 30@ = get_proc_address "GetTickCount" library 31@
    then 0AA7: call_function 30@ num_params 0 pop 0 29@
    end
    0AA3: free_library 31@
end
0AB2: ret 1 29@




PHP:
{$CLEO}
0000:

    // initialize custom timers
for 0@ = 0 to 6
    0AB1: @ResetCustomTimer 1 _TimerIndex 0@
end
    //

while true
    0AB1: @PreciseWait 1 _MilliSeconds 1000
    0AB1: @ResetCustomTimer 1 _TimerIndex 0
    0AB1: @GetLapseOfCustomTimer 1 _TimerIndex 0 _ReturnLapseOfTime 0@
    0AB1: @GetLapseOfCustomTimer 1 _TimerIndex 1 _ReturnLapseOfTime 1@
    0AB1: @GetLapseOfCustomTimer 1 _TimerIndex 2 _ReturnLapseOfTime 2@
    0AB1: @GetLapseOfCustomTimer 1 _TimerIndex 3 _ReturnLapseOfTime 3@
    0AB1: @GetLapseOfCustomTimer 1 _TimerIndex 4 _ReturnLapseOfTime 4@
    0AB1: @GetLapseOfCustomTimer 1 _TimerIndex 5 _ReturnLapseOfTime 5@
    0AB1: @GetLapseOfCustomTimer 1 _TimerIndex 6 _ReturnLapseOfTime 6@
    0AD1: show_formatted_text_highpriority "Updated Timer 0~n~%d %d %d %d~n~%d %d %d" time 2000 0@ 1@ 2@ 3@ 4@ 5@ 6@

    0AB1: @PreciseWait 1 _MilliSeconds 1000
    0AB1: @ResetCustomTimer 1 _TimerIndex 1
    for 0@ = 0 to 6
        0AB1: @GetLapseOfCustomTimer 1 _TimerIndex 0@ _ReturnLapseOfTime 1@(0@,7i) // array starts at pointer of 1@ // 0@ value is the array index // total number of index is 7 // data type i=integer
    end
    0AD1: show_formatted_text_highpriority "Updated Timer 1~n~%d %d %d %d~n~%d %d %d" time 2000 1@ 2@ 3@ 4@ 5@ 6@ 7@

    0AB1: @PreciseWait 1 _MilliSeconds 1000
    0AB1: @ResetCustomTimer 1 _TimerIndex 2
    for 0@ = 0 to 6
        0AB1: @GetLapseOfCustomTimer 1 _TimerIndex 0@ _ReturnLapseOfTime 1@(0@,7i) // array starts at pointer of 1@ // 0@ value is the array index // total number of index is 7 // data type i=integer
    end
    0AD1: show_formatted_text_highpriority "Updated Timer 2~n~%d %d %d %d~n~%d %d %d" time 2000 1@ 2@ 3@ 4@ 5@ 6@ 7@

    0AB1: @PreciseWait 1 _MilliSeconds 1000
    0AB1: @ResetCustomTimer 1 _TimerIndex 3
    for 0@ = 0 to 6
        0AB1: @GetLapseOfCustomTimer 1 _TimerIndex 0@ _ReturnLapseOfTime 1@(0@,7i) // array starts at pointer of 1@ // 0@ value is the array index // total number of index is 7 // data type i=integer
    end
    0AD1: show_formatted_text_highpriority "Updated Timer 3~n~%d %d %d %d~n~%d %d %d" time 2000 1@ 2@ 3@ 4@ 5@ 6@ 7@

    0AB1: @PreciseWait 1 _MilliSeconds 1000
    0AB1: @ResetCustomTimer 1 _TimerIndex 4
    for 0@ = 0 to 6
        0AB1: @GetLapseOfCustomTimer 1 _TimerIndex 0@ _ReturnLapseOfTime 1@(0@,7i) // array starts at pointer of 1@ // 0@ value is the array index // total number of index is 7 // data type i=integer
    end
    0AD1: show_formatted_text_highpriority "Updated Timer 4~n~%d %d %d %d~n~%d %d %d" time 2000 1@ 2@ 3@ 4@ 5@ 6@ 7@

    0AB1: @PreciseWait 1 _MilliSeconds 1000
    0AB1: @ResetCustomTimer 1 _TimerIndex 5
    for 0@ = 0 to 6
        0AB1: @GetLapseOfCustomTimer 1 _TimerIndex 0@ _ReturnLapseOfTime 1@(0@,7i) // array starts at pointer of 1@ // 0@ value is the array index // total number of index is 7 // data type i=integer
    end
    0AD1: show_formatted_text_highpriority "Updated Timer 5~n~%d %d %d %d~n~%d %d %d" time 2000 1@ 2@ 3@ 4@ 5@ 6@ 7@

    0AB1: @PreciseWait 1 _MilliSeconds 1000
    0AB1: @ResetCustomTimer 1 _TimerIndex 6
    for 0@ = 0 to 6
        0AB1: @GetLapseOfCustomTimer 1 _TimerIndex 0@ _ReturnLapseOfTime 1@(0@,7i) // array starts at pointer of 1@ // 0@ value is the array index // total number of index is 7 // data type i=integer
    end
    0AD1: show_formatted_text_highpriority "Updated Timer 6~n~%d %d %d %d~n~%d %d %d" time 2000 1@ 2@ 3@ 4@ 5@ 6@ 7@
end

:GetSystemTickCount // 0AB1: @GetSystemTickCount 0 _ReturnTickCount 29@
    // gets the number of milliseconds had passed since system start-up
if 0AA2: 31@ = load_library "kernel32.dll"
then
    if 0AA4: 30@ = get_proc_address "GetTickCount" library 31@
    then 0AA7: call_function 30@ num_params 0 pop 0 29@
    end
    0AA3: free_library 31@
end
0AB2: ret 1 29@

:PreciseWait // 0AB1: @PreciseWait 1 _MilliSeconds 0@
    0AB1: @GetSystemTickCount 0 _returnTickCount 31@ // start timer
    repeat
        0001: wait 0 ms
        0AB1: @GetSystemTickCount 0 _returnTickCount 30@ // monitor timer
        0062: 30@ -= 31@ // compute lapse of time
    until 002D: 30@ >= 0@ // timer had expired
0AB2: ret 0

:GetLapseOfCustomTimer // 0AB1: @GetLapseOfCustomTimer 1 _TimerIndex 0@ _ReturnLapseOfTime 30@
    0AC6: 31@ = label @CustomTimerRegion pointer
    0@ *= 4 // 4 bytes for each index
    005A: 31@ += 0@  // custom timer index pointer
    0A8D: 31@ = read_memory 31@ size 4 virtual_protect 0 // read custom timer's TickCount
    0AB1: @GetSystemTickCount 0 _returnTickCount 30@ // get precise TickCount from system
    0062: 30@ -= 31@ // compute lapse of time for the custom timer index
0AB2: ret 1 30@

:ResetCustomTimer // 0AB1: @ResetCustomTimer 1 _TimerIndex 0@
    0AC6: 31@ = label @CustomTimerRegion pointer
    0@ *= 4 // 4 bytes for each index
    005A: 31@ += 0@  // custom timer index pointer
    0AB1: @GetSystemTickCount 0 _returnTickCount 30@ // get precise TickCount from system
    0A8C: write_memory 31@ size 4 value 30@ virtual_protect 0 // save
0AB2: ret 0

:CustomTimerRegion // in case you want to increase the number of custom timers, add 4 bytes of hex for each new custom timer
hex
    00 00 00 00 // timer index 0
    00 00 00 00 // timer index 1
    00 00 00 00 // timer index 2
    00 00 00 00 // timer index 3
    00 00 00 00 // timer index 4
    00 00 00 00 // timer index 5
    00 00 00 00 // timer index 6
end
 

SobFoX

Expert
Joined
Jul 14, 2015
Messages
1,463
Solutions
5
Reaction score
916
Location
Israel
In the rockstar remakes they made a huge mess with how time and weather work
 

SamThapa

Active member
Joined
Jan 22, 2018
Messages
82
Reaction score
2
so confused here

as
timera
timerb

can do

if timera > 1000
then 0ad1: "working each 1 sec" 2000
end

but yours so confuse stuff here how to use it

can you do as

call @settimer 2 _index 1 _timelapse 1000

call @gettimer 1 _index 1 _timelapseret 10@
if 10@ == 1 //
then 0ad1: "working " 2000
end
call @settimer 2 _index 2 _timelapse 500

call @gettimer 1 _index 2 _timelapseret 10@
if 10@ == 1 //
then 0ad1: "working " 2000
end
like this
 

Zin

Expert
Joined
Aug 1, 2013
Messages
1,724
Solutions
2
Reaction score
113
o confused here

as
timera
timerb

can do

if timera > 1000
then 0ad1: "working each 1 sec" 2000
end

but yours so confuse stuff here how to use it

can you do as

call @settimer 2 _index 1 _timelapse 1000

call @gettimer 1 _index 1 _timelapseret 10@
if 10@ == 1 //
then 0ad1: "working " 2000
end
call @settimer 2 _index 2 _timelapse 500

call @gettimer 1 _index 2 _timelapseret 10@
if 10@ == 1 //
then 0ad1: "working " 2000
end
like this
Those snippets don't look like the ones posted, post the rest of the code if you still need help.
 

Zin

Expert
Joined
Aug 1, 2013
Messages
1,724
Solutions
2
Reaction score
113
Those snippets don't look like the ones posted, post the rest of the code if you still need help.
Oh wait nvm. For better understanding experiment with CLEO timers 32@ and 33@ (use opcode 0ad1: or w/e debug shit). This is just a more refined way which is more accurate and you can have more than just the two timers (32@/33@). The basic concept of a timer though is that it will just constantly tick up in ms regardless of what value you would set it to.
Code:
// TIMER INDEX is TIMER1/TIMER2/ETC

0AB1: @GetLapseOfCustomTimer 1 _TimerIndex 0@ _ReturnLapseOfTime 30@ // returns elapsed timer

0AB1: @ResetCustomTimer 1 _TimerIndex 0@ // this sets the selected timer to 0ms, do this to START YOUR TIMER

WHILE TRUE
    WAIT 0
    
    IF
        KEY_DOWN 1
    THEN
        0AB1: @ResetCustomTimer 1 _TimerIndex 0
    END

    0AB1: @GetLapseOfCustomTimer 1 _TimerIndex 0 _ReturnLapseOfTime 0@
    0AD1: "%d" 1 0@ // WILL DISPLAY ELAPSED TIME

END
BTW this method uses get_tick_count which is tied to system time which in my experience has sometimes been broken (returning negative value of "time elapsed from system start") which very rarely requires a restart.
 
Top