faluco@612: /** faluco@612: * vim: set ts=4 : faluco@612: * =============================================================== faluco@612: * SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved. faluco@612: * =============================================================== faluco@612: * faluco@612: * This file is part of the SourceMod/SourcePawn SDK. This file may only be used faluco@612: * or modified under the Terms and Conditions of its License Agreement, which is found faluco@612: * in LICENSE.txt. The Terms and Conditions for making SourceMod extensions/plugins faluco@612: * may change at any time. To view the latest information, see: faluco@612: * http://www.sourcemod.net/license.php faluco@612: * faluco@612: * Version: $Id$ faluco@612: */ faluco@612: faluco@612: #if defined _timers_included faluco@612: #endinput faluco@612: #endif faluco@612: #define _timers_included faluco@612: faluco@612: #include faluco@612: dvander@1108: #define TIMER_REPEAT (1<<0) /**< Timer will repeat until it returns Plugin_Stop */ dvander@1108: #define TIMER_FLAG_NO_MAPCHANGE (1<<1) /**< Timer will not carry over mapchanges */ dvander@1108: #define TIMER_HNDL_CLOSE (1<<9) /**< Timer will automatically call CloseHandle() on its value when finished */ faluco@612: faluco@612: /** faluco@612: * Any of the following prototypes will work for a timed function. faluco@612: */ faluco@612: funcenum Timer faluco@612: { faluco@612: /** faluco@612: * Called when the timer interval has elapsed. faluco@612: * faluco@612: * @param timer Handle to the timer object. faluco@612: * @param hndl Handle passed when the timer was created. faluco@612: * @return Plugin_Stop to stop a repeating timer, any other value for faluco@612: * default behavior. faluco@612: */ faluco@612: Action:public(Handle:timer, Handle:hndl), faluco@612: faluco@612: /** faluco@612: * Called when the timer interval has elapsed. faluco@612: * faluco@612: * @param timer Handle to the timer object. faluco@612: * @param value Value passed when the timer was created. faluco@612: * @return Plugin_Stop to stop a repeating timer, any other value for faluco@612: * default behavior. faluco@612: */ dvander@716: Action:public(Handle:timer, any:value), faluco@612: faluco@612: /** faluco@612: * Called when the timer interval has elapsed. faluco@612: * faluco@612: * @param timer Handle to the timer object. faluco@612: * @return Plugin_Stop to stop a repeating timer, any other value for faluco@612: * default behavior. faluco@612: */ faluco@612: Action:public(Handle:timer), faluco@612: }; faluco@612: faluco@612: /** faluco@612: * Creates a basic timer. Calling CloseHandle() on a timer will end the timer. faluco@612: * faluco@612: * @param interval Interval from the current game time to execute the given function. faluco@612: * @param func Function to execute once the given interval has elapsed. faluco@612: * @param value Handle or value to give to the timer function. faluco@612: * @param flags Flags to set (such as repeatability or auto-Handle closing). faluco@612: * @return Handle to the timer object. You do not need to call CloseHandle(). faluco@612: */ dvander@716: native Handle:CreateTimer(Float:interval, Timer:func, any:value=INVALID_HANDLE, flags=0); faluco@612: faluco@612: /** faluco@612: * Kills a timer. Use this instead of CloseHandle() if you need more options. faluco@612: * faluco@612: * @param autoClose If autoClose is true, the timer's value will be faluco@612: * closed as a handle if TIMER_HNDL_CLOSE was not specified. faluco@612: * @noreturn faluco@612: */ faluco@612: native KillTimer(Handle:timer, bool:autoClose=false); faluco@612: faluco@612: /** faluco@612: * Manually triggers a timer so its function will be called. faluco@612: * faluco@612: * @param timer Timer Handle to trigger. faluco@612: * @param reset If reset is true, the elapsed time counter is reset faluco@612: * so the full interval must pass again. faluco@612: * @noreturn faluco@612: */ faluco@612: native TriggerTimer(Handle:timer, bool:reset=false); faluco@612: faluco@612: /** dvander@822: * Returns the simulated game time. dvander@822: * dvander@822: * @param simulated Retrieves whether or not the tick count dvander@822: * is being manually simulated by SourceMod. dvander@822: * This is the case if no players have joined dvander@822: * the map yet. dvander@822: * @return Time based on the game tick count. dvander@822: */ dvander@822: native Float:GetTickedTime(&bool:simulated); dvander@822: dvander@822: /** faluco@612: * Creates a timer associated with a new data pack, and returns the datapack. faluco@612: * @note The datapack is automatically freed when the timer ends. faluco@612: * @note The position of the datapack is not reset or changed for the timer function. faluco@612: * faluco@612: * @param interval Interval from the current game time to execute the given function. faluco@612: * @param func Function to execute once the given interval has elapsed. faluco@612: * @param data The newly created datapack is passed though this by-reference parameter. faluco@612: * @param flags Timer flags. faluco@612: * @return Handle to the timer object. You do not need to call CloseHandle(). faluco@612: */ dvander@716: stock Handle:CreateDataTimer(Float:interval, Timer:func, &Handle:data, flags=0) faluco@612: { faluco@612: data = CreateDataPack(); faluco@612: flags |= TIMER_HNDL_CLOSE; faluco@612: return CreateTimer(interval, func, data, flags); faluco@612: }