[Include] Native function timers!
#1

Native function timers!

Introduction
This is just a simple but useful include which allows you to run timers that call native functions. This can be useful for run-time native calling and for many other occasions also, so you don't have to include an extra public function to call one native.

How it works
This works by storing the timer's data in advance, and calls the native after the interval has passed, pushing the arguments onto the stack every call. Say you've had a function like this:

pawn Code:
forward KickPlayer(playerid);
public KickPlayer(playerid)
{
    Kick(playerid);
}

SetTimerEx("KickPlayer", 1000, false, "d", playerid);
You can improve that using only one line with this include:

pawn Code:
Native_Timer("Kick", 1000, false, "d", playerid);
Which can be VERY useful and easier in some cases!

Installation
Add this code at the top of your script, preferably under a_samp:

pawn Code:
#include <a_samp>
#include <ntimers>
And you're done!

Functions
pawn Code:
// Setup a native timer.
forward Native_Timer(function[], interval, repeating, specifiers[] = "", {Float,_}:...);

// Setup a native timer (which is called a specified amount of times).
forward Native_TimerEx(function[], interval, count, specifiers[] = "", {Float,_}:...);

// Kills a native timer.
forward Native_Kill(timerid);
Notes
  • You cannot use "CallLocalFunction" or "CallRemoteFunction" with Native_Timer.
  • Some functions might not be called correctly, but I ensure that 98% of them are very stable.
Downloads
Available at my GitHub page - click here.
Reply


Messages In This Thread
Native function timers! - by Emmet_ - 28.12.2013, 04:17
Re: Native function timers! - by Alphlax - 28.12.2013, 05:03
Re: Native function timers! - by iZN - 28.12.2013, 06:34
Re: Native function timers! - by PT - 28.12.2013, 06:43
Re: Native function timers! - by Emmet_ - 28.12.2013, 21:29
Re: Native function timers! - by Patrick - 28.12.2013, 21:39
Re: Native function timers! - by Emmet_ - 28.12.2013, 21:43
Re: Native function timers! - by Hansrutger - 29.12.2013, 15:28
Re: Native function timers! - by Emmet_ - 30.12.2013, 00:41
Re: Native function timers! - by qazwsx - 30.12.2013, 02:10

Forum Jump:


Users browsing this thread: 1 Guest(s)