Post: [SPRX] Timer for hooks (instead of using sleep)
07-16-2016, 02:29 AM #1
Swaqq
Professional Thanker
(adsbygoogle = window.adsbygoogle || []).push({}); Hello everyone, been working on a project, and needed a timer for my project so I made one. It's quite simple, and meant for hooking because you can't use sleeps.

Here is the struct to add to your header because we can't use classes Smile
    
struct Timer
{
void Start();
void Init(int ms);
void Reset();
bool Ready();
void Run(int Time);
bool running;
int interval;
int beginTime;
int time;
};



Here is the functions
    
void Timer::Start()
{
running = true;
}

void Timer::Init(int ms)
{
interval = ms;
}

bool Timer::Ready()
{
return time >= beginTime + interval;
}

void Timer::Reset()
{
beginTime = time;
}

void Timer::Run(int Time)
{
time = Time;
}


And to use it (Put this in your hook):
    
Timer timer; //Keep this outside your hook, put it in the globals
timer.Init(0.1);
timer.Start();
sys_time_sec_t t;
sys_time_get_current_time(&t, NULL);
timer.Run(t);
if(timer.Ready())
{
//do stuff
timer.Reset();
}



As you can see it's very simple to use. If you use this, please credit me and don't claim it as your own.
Permission to post this on other forums is denied.


CREDITS TO BITWISE FOR INVENTING C++
Last edited by Swaqq ; 07-17-2016 at 08:52 PM.

The following 11 users say thank you to Swaqq for this useful post:

2much4u, Basic_Code, DSG24, Father Luckeyy, K51, Kryptus, modzlife2000, ParadoxSPRX, Sabotage, TheGreenPlanet, UGz-
11-25-2016, 04:35 AM #11
Sabotage
Gaming Squad
Thanks bitwise.
01-07-2017, 06:54 PM #12
sprx13
Banned
thank you

Copyright © 2024, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo