/**
* Copyright (c) 2013-2014, Dan
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* 1.5
* Supported parameters:
* a, A = arrays (must be followed by an integer - array's szie);
* b, B = boolean; c, C = character; d, D, i, I = integer;
* s, S = string; p, P = player's ID, t, T = timer's ID
*
*/
/**
* Same KillTimer is used for all types of timer.
*/
#define KillTimer_ KillTimer
/**
* Improved GetTickCount (more accurate).
* Current time in miliseconds.
*/
//native GetTickCount();
/**
* Checks if a timer is still alive.
* The ID of the timer.
* `true` if the timer is valid or `false` otherwise.
*/
native IsValidTimer(timerid);
/**
* Gets the number of active timers.
* The number of active timers.
*/
native GetActiveTimers();
/**
* Kills all timers a player owns.
* The ID of the timer.
*/
native KillPlayerTimer(timerid) = KillTimer;
/**
* Kills all timers a player owns.
* The player that owns the timers.
*/
native KillPlayerTimers(playerid);
/**
* Basic SetTimer.
* Name of the public function to call.
* Interval in milliseconds.
* Whether this timer will repeat or will execute only one time.
* The ID of the timer.
*/
//native SetTimer(func[], interval, repeating);
/**
* Basic SetTimerEx.
* Name of the public function to call.
* Interval in milliseconds.
* Whether this timer will repeat or will execute only one time.
* Special format indicating the types of values the timer will pass.
* The ID of the timer.
*/
//native SetTimerEx(func[], interval, repeating, const format[], {Float,_}:...);
/**
* An improved version of SetTimer.
* Name of the public function to call.
* Interval in milliseconds.
* Time after this timer should be called for the first time.
* How many times it should repeat before it's killed (-1 for unlimited).
* The ID of the timer.
*/
native SetTimer_(func[], interval, delay, count);
/**
* An improved version of SetTimerEx.
* Name of the public function to call.
* Interval in milliseconds.
* Time after this timer should be called for the first time.
* How many times it should repeat before it's killed (-1 for unlimited).
* Special format indicating the types of values the timer will pass.
* The ID of the timer.
*/
native SetTimerEx_(func[], interval, delay, count, format[], {Float, _}:...);
/**
* Basic SetPlayerTimer.
* The player that owns the timer.
* Name of the public function to call.
* Interval in milliseconds.
* Whether this timer will repeat or will execute only one time.
* The ID of the timer.
*/
native SetPlayerTimer(playerid, func[], interval, repeating);
/**
* Basic SetPlayerTimerEx.
* The player that owns the timer.
* Name of the public function to call.
* Interval in milliseconds.
* Whether this timer will repeat or will execute only one time.
* Special format indicating the types of values the timer will pass.
* The ID of the timer.
*/
native SetPlayerTimerEx(playerid, func[], interval, repeating, const format[], {Float,_}:...);
/**
* An improved version of SetPlayerTimer.
* The player that owns the timer.
* Name of the public function to call.
* Interval in milliseconds.
* Time after this timer should be called for the first time.
* How many times it should repeat before it's killed (-1 for unlimited).
* The ID of the timer.
*/
native SetPlayerTimer_(playerid, func[], interval, delay, count);
/**
* An improved version of SetPlayerTimerEx.
* The player that owns the timer.
* Name of the public function to call.
* Interval in milliseconds.
* Time after this timer should be called for the first time.
* How many times it should repeat before it's killed (-1 for unlimited).
* Special format indicating the types of values the timer will pass.
* The ID of the timer.
*/
native SetPlayerTimerEx_(playerid, func[], interval, delay, count, format[], {Float, _}:...);
/**
* Gets the name of the function that is called.
* The ID of the timer.
* The name of the function.
*/
native GetTimerFunctionName(timerid, func[]);
/**
* Sets the interval of a timer.
* The ID of the timer.
* The new interval.
*/
native SetTimerInterval(timerid, interval);
/**
* Gets the interval of a timer.
* The ID of the timer.
* 0 for invalid timers or the interval (in miliseconds).
*/
native GetTimerInterval(timerid);
/**
* Gets the time remaining before this timer is called again.
* The ID of the timer.
* 0 for invalid timers or the time (in miliseconds) until the execution.
*/
native GetTimerIntervalLeft(timerid);
/**
* Sets the delay of a timer.
* The ID of the timer.
* The new delay.
*/
native SetTimerDelay(timerid, delay);
/**
* Sets the count of a timer.
* The ID of the timer.
* The new count.
*/
native SetTimerCount(timerid, count);
/**
* Gets the number of remaining calls of this timer.
* The ID of the timer.
* -1 for infinite timers, 0 for invalid ones and positive values for the others.
*/
native GetTimerCallsLeft(timerid);
// Kills a player's timers on disconnect.
public OnPlayerDisconnect(playerid, reason) {
KillPlayerTimers(playerid);
#if defined TIMERFIX_OnPlayerDisconnect
return TIMERFIX_OnPlayerDisconnect(playerid, reason);
#else
return 1;
#endif
}
#if defined _ALS_OnPlayerDisconnect
#undef OnPlayerDisconnect
#else
#define _ALS_OnPlayerDisconnect
#endif
#define OnPlayerDisconnect TIMERFIX_OnPlayerDisconnect
#if defined TIMERFIX_OnPlayerDisconnect
forward TIMERFIX_OnPlayerDisconnect(playerid, reason);
#endif