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,389
Solutions
4
Reaction score
893
Location
Israel
In the rockstar remakes they made a huge mess with how time and weather work
 
Top