Розыгрыш Premium и Уникальной юзергруппы на форуме! Перейти


  • УЖЕ ЗАВТРА! Просто зашёл, нажал на кнопку участия и забрал кучу призов уже 30-го декабря: https://yougame.biz/threads/366947/

Как выполнять код каждые x сек

САСУ САСУ ПОД СТОЛИКОМ
Забаненный
Забаненный
Статус
Оффлайн
Регистрация
8 Янв 2019
Сообщения
354
Реакции
18
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.
как выполнять команды каждые x сек? c++ код можете дать плиз
 
TimeCounter.h
Код:
Expand Collapse Copy
#ifndef __TIMECOUNTER222__H__
#define __TIMECOUNTER222__H__

#include <iostream>

//////////////////////////////////////////
/// Допустимые значения приоритета потока:
/// THREAD_PRIORITY_HIGHEST
/// THREAD_PRIORITY_ABOVE_NORMAL
/// THREAD_PRIORITY_NORMAL
/// THREAD_PRIORITY_BELOW_NORMAL
/// THREAD_PRIORITY_LOWEST
//////////////////////////////////////////

class TimeCounter
{
friend std::ostream& operator<<(std::ostream& out, TimeCounter& cntr);
public:
   TimeCounter() {started=false; stopped=false; tWord = 0;}
   void Start();
   void Start(int nPriority);
   void Stop();

   double timeElapsed() const;
   bool getStarted() const {return started;}
   bool getStopped() const {return stopped;}
   int getNewPriority() const {return new_priority;}
   ~TimeCounter();

   void Assign(TimeCounter &cntr);
   void Add(TimeCounter &cntr);
   void Clear();

protected:
   int new_priority;
   int old_priority;
   bool started;
   bool stopped;
   double tBefore, tAfter, i64PerfFrequency;
   double tWord;

};

#endif

TimeCounter.cpp
Код:
Expand Collapse Copy
#include "TimeCounter.h"
#include <windows.h>

//старт счетчика
void TimeCounter::Start()
{
   started=true;
   stopped=false;
   new_priority=0;

   LARGE_INTEGER pf;
    QueryPerformanceFrequency(&pf);
   i64PerfFrequency = pf.QuadPart;
    Sleep(0);
    QueryPerformanceCounter(&pf);
   tBefore = pf.QuadPart;

   tWord = 0;
}

void TimeCounter::Start(int nPriority)
{
   started=true;
   stopped=false;
   new_priority=nPriority;
   old_priority=GetThreadPriority(GetCurrentThread());
   SetThreadPriority(GetCurrentThread(),new_priority);

   LARGE_INTEGER pf;
    QueryPerformanceFrequency(&pf);
   i64PerfFrequency = pf.QuadPart;
    Sleep(0);
   QueryPerformanceCounter(&pf);
   tBefore = pf.QuadPart;
}

//остановка таймера
void TimeCounter::Stop()
{
   LARGE_INTEGER tAfter1;
   QueryPerformanceCounter(&tAfter1);
   tAfter = tAfter1.QuadPart;

   tWord = tAfter - tBefore;
   tWord /= i64PerfFrequency;
   if (new_priority)
      SetThreadPriority(GetCurrentThread(),old_priority);
   started=false;
   stopped=true;
}

double TimeCounter::timeElapsed() const
{
   LARGE_INTEGER tempAfter;
   double tempWord;

   if (started)
   {
      QueryPerformanceCounter(&tempAfter);
      tempWord = tempAfter.QuadPart - tBefore;
      tempWord /= i64PerfFrequency;

      return tempWord;
   }
   if (stopped)
      return tWord;

   return 0.;
}

TimeCounter::~TimeCounter()
{
   if (new_priority)
      SetThreadPriority(GetCurrentThread(),old_priority);
}

//вывод в поток
std::ostream& operator<<(std::ostream& out, TimeCounter& cntr)
{
   double fsec = cntr.timeElapsed();
   int hour = int(fsec/3600.);
   double fmin = fsec-3600.*double(hour);
   int min = int(fmin/60.);
   double sec = fmin-60.*double(min);
   out<new_priority = cntr.new_priority;
    this->old_priority = cntr.old_priority;
    this->started = cntr.started;
    this->stopped = cntr.stopped;
    this->tBefore = cntr.tBefore;
    this->tAfter = cntr.tAfter;
    this->i64PerfFrequency = cntr.i64PerfFrequency;
    this->tWord = cntr.tWord;
}
//сложение значений двух таймеров
void TimeCounter::Add(TimeCounter& cntr)
{
    this->tWord += cntr.tWord;
}
//обнуление таймера
void TimeCounter::Clear()
{
    this->tWord = 0;
}

Использование
Код:
Expand Collapse Copy
TimeCounter t;
t.Start();
t.Stop();
cout<<t;
 
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.
TimeCounter.h
Код:
Expand Collapse Copy
#ifndef __TIMECOUNTER222__H__
#define __TIMECOUNTER222__H__

#include <iostream>

//////////////////////////////////////////
/// Допустимые значения приоритета потока:
/// THREAD_PRIORITY_HIGHEST
/// THREAD_PRIORITY_ABOVE_NORMAL
/// THREAD_PRIORITY_NORMAL
/// THREAD_PRIORITY_BELOW_NORMAL
/// THREAD_PRIORITY_LOWEST
//////////////////////////////////////////

class TimeCounter
{
friend std::ostream& operator<<(std::ostream& out, TimeCounter& cntr);
public:
   TimeCounter() {started=false; stopped=false; tWord = 0;}
   void Start();
   void Start(int nPriority);
   void Stop();

   double timeElapsed() const;
   bool getStarted() const {return started;}
   bool getStopped() const {return stopped;}
   int getNewPriority() const {return new_priority;}
   ~TimeCounter();

   void Assign(TimeCounter &cntr);
   void Add(TimeCounter &cntr);
   void Clear();

protected:
   int new_priority;
   int old_priority;
   bool started;
   bool stopped;
   double tBefore, tAfter, i64PerfFrequency;
   double tWord;

};

#endif

TimeCounter.cpp
Код:
Expand Collapse Copy
#include "TimeCounter.h"
#include <windows.h>

//старт счетчика
void TimeCounter::Start()
{
   started=true;
   stopped=false;
   new_priority=0;

   LARGE_INTEGER pf;
    QueryPerformanceFrequency(&pf);
   i64PerfFrequency = pf.QuadPart;
    Sleep(0);
    QueryPerformanceCounter(&pf);
   tBefore = pf.QuadPart;

   tWord = 0;
}

void TimeCounter::Start(int nPriority)
{
   started=true;
   stopped=false;
   new_priority=nPriority;
   old_priority=GetThreadPriority(GetCurrentThread());
   SetThreadPriority(GetCurrentThread(),new_priority);

   LARGE_INTEGER pf;
    QueryPerformanceFrequency(&pf);
   i64PerfFrequency = pf.QuadPart;
    Sleep(0);
   QueryPerformanceCounter(&pf);
   tBefore = pf.QuadPart;
}

//остановка таймера
void TimeCounter::Stop()
{
   LARGE_INTEGER tAfter1;
   QueryPerformanceCounter(&tAfter1);
   tAfter = tAfter1.QuadPart;

   tWord = tAfter - tBefore;
   tWord /= i64PerfFrequency;
   if (new_priority)
      SetThreadPriority(GetCurrentThread(),old_priority);
   started=false;
   stopped=true;
}

double TimeCounter::timeElapsed() const
{
   LARGE_INTEGER tempAfter;
   double tempWord;

   if (started)
   {
      QueryPerformanceCounter(&tempAfter);
      tempWord = tempAfter.QuadPart - tBefore;
      tempWord /= i64PerfFrequency;

      return tempWord;
   }
   if (stopped)
      return tWord;

   return 0.;
}

TimeCounter::~TimeCounter()
{
   if (new_priority)
      SetThreadPriority(GetCurrentThread(),old_priority);
}

//вывод в поток
std::ostream& operator<<(std::ostream& out, TimeCounter& cntr)
{
   double fsec = cntr.timeElapsed();
   int hour = int(fsec/3600.);
   double fmin = fsec-3600.*double(hour);
   int min = int(fmin/60.);
   double sec = fmin-60.*double(min);
   out<new_priority = cntr.new_priority;
    this->old_priority = cntr.old_priority;
    this->started = cntr.started;
    this->stopped = cntr.stopped;
    this->tBefore = cntr.tBefore;
    this->tAfter = cntr.tAfter;
    this->i64PerfFrequency = cntr.i64PerfFrequency;
    this->tWord = cntr.tWord;
}
//сложение значений двух таймеров
void TimeCounter::Add(TimeCounter& cntr)
{
    this->tWord += cntr.tWord;
}
//обнуление таймера
void TimeCounter::Clear()
{
    this->tWord = 0;
}

Использование
Код:
Expand Collapse Copy
TimeCounter t;
t.Start();
t.Stop();
cout<<t;
как выполнять команды каждые x сек? c++ код можете дать плиз
всм как мне твой код поможет
 
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.
TimeCounter.h
Код:
Expand Collapse Copy
#ifndef __TIMECOUNTER222__H__
#define __TIMECOUNTER222__H__

#include <iostream>

//////////////////////////////////////////
/// Допустимые значения приоритета потока:
/// THREAD_PRIORITY_HIGHEST
/// THREAD_PRIORITY_ABOVE_NORMAL
/// THREAD_PRIORITY_NORMAL
/// THREAD_PRIORITY_BELOW_NORMAL
/// THREAD_PRIORITY_LOWEST
//////////////////////////////////////////

class TimeCounter
{
friend std::ostream& operator<<(std::ostream& out, TimeCounter& cntr);
public:
   TimeCounter() {started=false; stopped=false; tWord = 0;}
   void Start();
   void Start(int nPriority);
   void Stop();

   double timeElapsed() const;
   bool getStarted() const {return started;}
   bool getStopped() const {return stopped;}
   int getNewPriority() const {return new_priority;}
   ~TimeCounter();

   void Assign(TimeCounter &cntr);
   void Add(TimeCounter &cntr);
   void Clear();

protected:
   int new_priority;
   int old_priority;
   bool started;
   bool stopped;
   double tBefore, tAfter, i64PerfFrequency;
   double tWord;

};

#endif

TimeCounter.cpp
Код:
Expand Collapse Copy
#include "TimeCounter.h"
#include <windows.h>

//старт счетчика
void TimeCounter::Start()
{
   started=true;
   stopped=false;
   new_priority=0;

   LARGE_INTEGER pf;
    QueryPerformanceFrequency(&pf);
   i64PerfFrequency = pf.QuadPart;
    Sleep(0);
    QueryPerformanceCounter(&pf);
   tBefore = pf.QuadPart;

   tWord = 0;
}

void TimeCounter::Start(int nPriority)
{
   started=true;
   stopped=false;
   new_priority=nPriority;
   old_priority=GetThreadPriority(GetCurrentThread());
   SetThreadPriority(GetCurrentThread(),new_priority);

   LARGE_INTEGER pf;
    QueryPerformanceFrequency(&pf);
   i64PerfFrequency = pf.QuadPart;
    Sleep(0);
   QueryPerformanceCounter(&pf);
   tBefore = pf.QuadPart;
}

//остановка таймера
void TimeCounter::Stop()
{
   LARGE_INTEGER tAfter1;
   QueryPerformanceCounter(&tAfter1);
   tAfter = tAfter1.QuadPart;

   tWord = tAfter - tBefore;
   tWord /= i64PerfFrequency;
   if (new_priority)
      SetThreadPriority(GetCurrentThread(),old_priority);
   started=false;
   stopped=true;
}

double TimeCounter::timeElapsed() const
{
   LARGE_INTEGER tempAfter;
   double tempWord;

   if (started)
   {
      QueryPerformanceCounter(&tempAfter);
      tempWord = tempAfter.QuadPart - tBefore;
      tempWord /= i64PerfFrequency;

      return tempWord;
   }
   if (stopped)
      return tWord;

   return 0.;
}

TimeCounter::~TimeCounter()
{
   if (new_priority)
      SetThreadPriority(GetCurrentThread(),old_priority);
}

//вывод в поток
std::ostream& operator<<(std::ostream& out, TimeCounter& cntr)
{
   double fsec = cntr.timeElapsed();
   int hour = int(fsec/3600.);
   double fmin = fsec-3600.*double(hour);
   int min = int(fmin/60.);
   double sec = fmin-60.*double(min);
   out<new_priority = cntr.new_priority;
    this->old_priority = cntr.old_priority;
    this->started = cntr.started;
    this->stopped = cntr.stopped;
    this->tBefore = cntr.tBefore;
    this->tAfter = cntr.tAfter;
    this->i64PerfFrequency = cntr.i64PerfFrequency;
    this->tWord = cntr.tWord;
}
//сложение значений двух таймеров
void TimeCounter::Add(TimeCounter& cntr)
{
    this->tWord += cntr.tWord;
}
//обнуление таймера
void TimeCounter::Clear()
{
    this->tWord = 0;
}

Использование
Код:
Expand Collapse Copy
TimeCounter t;
t.Start();
t.Stop();
cout<<t;
и зачем такая мозгоебля?
в отдельный поток while ( true ) { Sleep( value ) } :roflanzdarova:

p.s. @Kentavrik , сука, хватит уже мучаться с этими тредами постоянными, посети хоть раз learncpp.com или даже сололерн ебучий
p.s.s. правильнее было бы считать все в тиках, лул
 
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.
и зачем такая мозгоебля?
в отдельный поток while ( true ) { Sleep( value ) } :roflanzdarova:

p.s. @Kentavrik , сука, хватит уже мучаться с этими тредами постоянными, посети хоть раз learncpp.com или даже сололерн ебучий
p.s.s. правильнее было бы считать все в тиках, лул
я пробежался не нашел
 
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.
Реализация чего?
ладно скажу .............................
чат спам
пока сделал еще более уебешный код
C++:
Expand Collapse Copy
        g_csgo.m_engine()->ExecuteClientCmd("say NEVERTAP PREMIUM MISSING SOFTWARE");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
    }
 
ладно скажу .............................
чат спам
пока сделал еще более уебешный код
C++:
Expand Collapse Copy
        g_csgo.m_engine()->ExecuteClientCmd("say NEVERTAP PREMIUM MISSING SOFTWARE");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
    }
Мои глаза, я плачу..

C++:
Expand Collapse Copy
    float fSec = 1;
    static int iTimer = 0;

    if (!iTimer)
        iTimer = GetTickCount();

    if (GetTickCount() > iTimer + (fSec * 1000))
    {
        // Тут код

        iTimer = 0;
    }
 
ладно скажу .............................
чат спам
пока сделал еще более уебешный код
C++:
Expand Collapse Copy
        g_csgo.m_engine()->ExecuteClientCmd("say NEVERTAP PREMIUM MISSING SOFTWARE");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
        g_csgo.m_engine()->ExecuteClientCmd(" ");
    }
Мда, сказать сразу нельзя было, я кидал код под win приложения :orehus:
 
Мда, сказать сразу нельзя было, я кидал код под win приложения :orehus:
Мне кажется, он не поймет разницу.

Интернал софт внедряются в уже готовую функцию из движка игры, которая работает циклично, по-этому цикл там не нужен и код выполняется каждый тик. Если же ты делаешь свою прогу, ты сам должен создавать цикл, как писал spearmint: "while ( true ) { Sleep( value ) }"

Sleep полностью останавливает выполнение кода в потоке, по-этому в интернал чите его нельзя использовать для таймера, остановится выполнение ксго в принципе всей
 
Назад
Сверху Снизу