This snippets makes it easy to make timers without having to make the timer function and then the callback timer callback.
This ugly and hacky looking wrapper does it in one move. It should also be noted that it's preferable to use this wrapper function for NON-Repeating timers.
Example code!
PHP Code:
SetPawnTimer(AddTwoNumbers, 1.0, 2, 2);
the Parameters are ignorable so there's less hassle.
Of course, due to the way it's structured, you can't use arrays or strings unless you modify it.
Source Code Below
Spoiler
PHP Code:
#include <datapack>
#include <timers>
#include <functions>
/**
* Wrapper Function for easily setting up timers
*
* @param func Function pointer to callback desired function when time elapses
* @param thinktime time in seconds when timer function will be called
* @param param1 1st param for the call back function
* @param param2 2nd param for the call back function
* @param param3 3rd param for the call back function
* @param param4 4th param for the call back function
*
* @noreturn
*/
stock void SetPawnTimer(Function func, float thinktime = 0.1, any param1 = -999, any param2 = -999, any param3 = -999, any param4 = -999)
{
DataPack thinkpack = new DataPack();
thinkpack.WriteFunction(func);
thinkpack.WriteCell(param1);
thinkpack.WriteCell(param2);
thinkpack.WriteCell(param3);
thinkpack.WriteCell(param4);
CreateTimer(thinktime, DoTimer, thinkpack, TIMER_DATA_HNDL_CLOSE);
}
public Action DoTimer(Handle hTimer, DataPack hndl)
{
hndl.Reset();
Function pFunc = hndl.ReadFunction();
Call_StartFunction( null, pFunc );
any param1 = hndl.ReadCell();
if ( param1 != -999 ) Call_PushCell(param1);
any param2 = hndl.ReadCell();
if ( param2 != -999 ) Call_PushCell(param2);
any param3 = hndl.ReadCell();
if ( param3 != -999 ) Call_PushCell(param3);
any param4 = hndl.ReadCell();
if ( param4 != -999 ) Call_PushCell(param4);
Call_Finish();
return Plugin_Continue;
}
N-JOY