[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
#2

Nice script man
Reply
#3

Amazing work dude, and good idea of Github, repo your other project also at Github.
Reply
#4

nice job.

it's easy with this do timers.
Reply
#5

Thanks guys.

I'm also planning on creating a "OnNativeTimer" callback, such as this:

pawn Code:
public OnNativeTimer(timerid, function[])
{
    return 1;
}
Which would be called every time a native timer calls.
Reply
#6

Actually, Nice so this gets a default native from SA-MP include and you could create a timer without using any callback? If that is the include for that is GREAT, might be using this in my future project
Reply
#7

Quote:
Originally Posted by pds2k12
View Post
Actually, Nice so this gets a default native from SA-MP include and you could create a timer without using any callback? If that is the include for that is GREAT, might be using this in my future project
Yeah, exactly.

It works with all SA-MP native functions and I suppose that it would work with natives from other plugins too, but it needs to be used in the script already or SYSREQ.C will bug up.
Reply
#8

So if I get this straight this would instead of create new functions just go to using "Kick", "Ban", "BanEx" etc? Is there any list on these kind of actions that are there from the beginning? :S Would like to know the list hehe'.

Also are these timers exact time or do they lack some miliseconds like the normal SetTimer and SetTimerEx?
Reply
#9

Quote:
Originally Posted by Hansrutger
View Post
So if I get this straight this would instead of create new functions just go to using "Kick", "Ban", "BanEx" etc? Is there any list on these kind of actions that are there from the beginning? :S Would like to know the list hehe'.

Also are these timers exact time or do they lack some miliseconds like the normal SetTimer and SetTimerEx?
Yeah. All natives can be used (Kick, Ban, CreateVehicle, etc). It uses SetTimer to call the natives, so of course it might be a few milliseconds off.

Quote:
Originally Posted by QuaTTrO
View Post
Does it works with custom made functions?
No - native functions only.
Reply
#10

Great include function!

Keep up the good work!

I hope i can find more releases from you which can be very usefull

+REP
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)