Skip to content
This repository has been archived by the owner on Sep 1, 2024. It is now read-only.

aaamouii/Timer-Fix-plugin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

68 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Timer-Fix-plugin

This plugin makes timers more accurate. Topic.
This plugin is no longer supported.
Previous versions on the Releases page might have problems and bugs, use at your own risk.

Usage

Plugin uses default SA-MP natives so you don't have to change your code. Example:

#include <a_samp>

forward Function();
public Function()
{
  printf("Function called after 1 second.");
}

forward FunctionWithArguments(number);
public FunctionWithArguments(number)
{
  printf("Function called after 2 seconds. Number: %d", number);
}

main()
{
  SetTimer("Function", 1000, false);
  SetTimerEx("FunctionWithArguments", 2000, false, "d", 10);
}

Natives

native SetCustomTimer(const funcname[], interval, delay, count);

Replacement for a standart native function that includes additional parameters.

  • delay - the delay before the timer starts.
  • count - count of executions.

Note: if you want timer to repeat put -1 instead of count.
Example: SetCustomTimer("Test", 1000, 500, -1);

native SetCustomTimerEx(const funcname[], interval, delay, count, const format[], {Float,_}:...);

The same function but with argument passing.
Note: if you want timer to repeat put -1 instead of count.
Example: SetCustomTimerEx("Test", 1000, 500, -1, "i", 1);

native PauseTimer(timerid);

Stops the timer but doesn't delete it.
Use the ContinueTimer() to start it again.

  • Note: the callback will be executed after the time remaining before the call.
native ContinueTimer(timerid);

Continues the timer after pausing.

native AddTimerHandler(timerid, handler[]);

Adds the custom callback for the timer.
For example:

 new a = SetTimer("function_1");
 AddTimerHandler(a, "function_2");

The timer will execute both callbacks.

  • Note: arguments will be passed to both functions.
native RemoveTimerHandler(timerid, handler[]);

Removes the added handler.

Another natives.

native KillAllTimers();
native IsValidTimer(timerid);
native GetTimerInterval(timerid);
native SetTimerInterval(timerid, interval);
native GetTimerRemainingTime(timerid);
native GetCountOfRunningTimers();

Building

Build a shared library is provided for only two platforms.

Windows

  1. First of all you should download CMake from the official site.
  2. Then clone this repository or download source code from the Releases page.
  3. Generate project with CMake for MSVC.
  4. Build generated project (Don't forget to change configuration to Release Win32).

Linux

  1. Install everything you need to build a library (if not installed)
// Ubuntu, Debian, etc
apt-get install cmake
apt-get install git
apt-get install gcc-multilib g++-multilib

// CentOS
yum install cmake
yum install git
yum install gcc-multilib g++-multilib
  1. Clone this repository
git clone --recursive https://github.com/KashCherry/Timer-Fix-plugin
  1. Generate project with CMake in this folder or create other one
mkdir build && cd build && cmake ..
  1. Build generated project with make
make

License

Licensed under MIT License. Learn more about it here.