timerfix.inc 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. /**
  2. * Copyright (c) 2013-2014, Dan
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright notice, this
  9. * list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright notice,
  11. * this list of conditions and the following disclaimer in the documentation
  12. * and/or other materials provided with the distribution.
  13. *
  14. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  15. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  16. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  17. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
  18. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  19. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  20. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  21. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  22. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  23. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. /**
  26. * <version>1.5</version>
  27. * <remarks>Supported parameters:
  28. * a, A = arrays (must be followed by an integer - array's szie);
  29. * b, B = boolean; c, C = character; d, D, i, I = integer;
  30. * s, S = string; p, P = player's ID, t, T = timer's ID
  31. * </remarks>
  32. */
  33. /**
  34. * <summary>Same KillTimer is used for all types of timer.</summary>
  35. */
  36. #define KillTimer_ KillTimer
  37. /**
  38. * <summary>Improved GetTickCount (more accurate).</summary>
  39. * <returns>Current time in miliseconds.</returns>
  40. */
  41. //native GetTickCount();
  42. /**
  43. * <summary>Checks if a timer is still alive.</summary>
  44. * <param name="timerid">The ID of the timer.</param>
  45. * <returns>`true` if the timer is valid or `false` otherwise.</returns>
  46. */
  47. native IsValidTimer(timerid);
  48. /**
  49. * <summary>Gets the number of active timers.</summary>
  50. * <returns>The number of active timers.</returns>
  51. */
  52. native GetActiveTimers();
  53. /**
  54. * <summary>Kills all timers a player owns.</summary>
  55. * <param name="timerid">The ID of the timer.</param>
  56. */
  57. native KillPlayerTimer(timerid) = KillTimer;
  58. /**
  59. * <summary>Kills all timers a player owns.</summary>
  60. * <param name="playerid">The player that owns the timers.</param>
  61. */
  62. native KillPlayerTimers(playerid);
  63. /**
  64. * <summary>Basic SetTimer.</summary>
  65. * <param name="func">Name of the public function to call.</param>
  66. * <param name="interval">Interval in milliseconds.</param>
  67. * <param name="repeating">Whether this timer will repeat or will execute only one time.</param>
  68. * <returns>The ID of the timer.</returns>
  69. */
  70. //native SetTimer(func[], interval, repeating);
  71. /**
  72. * <summary>Basic SetTimerEx.</summary>
  73. * <param name="func">Name of the public function to call.</param>
  74. * <param name="interval">Interval in milliseconds.</param>
  75. * <param name="repeating">Whether this timer will repeat or will execute only one time.</param>
  76. * <param name="format">Special format indicating the types of values the timer will pass.</param>
  77. * <returns>The ID of the timer.</returns>
  78. */
  79. //native SetTimerEx(func[], interval, repeating, const format[], {Float,_}:...);
  80. /**
  81. * <summary>An improved version of SetTimer.</summary>
  82. * <param name="func">Name of the public function to call.</param>
  83. * <param name="interval">Interval in milliseconds.</param>
  84. * <param name="delay">Time after this timer should be called for the first time.</param>
  85. * <param name="count">How many times it should repeat before it's killed (-1 for unlimited).</param>
  86. * <returns>The ID of the timer.</returns>
  87. */
  88. native SetTimer_(func[], interval, delay, count);
  89. /**
  90. * <summary>An improved version of SetTimerEx.</summary>
  91. * <param name="func">Name of the public function to call.</param>
  92. * <param name="interval">Interval in milliseconds.</param>
  93. * <param name="delay">Time after this timer should be called for the first time.</param>
  94. * <param name="count">How many times it should repeat before it's killed (-1 for unlimited).</param>
  95. * <param name="format">Special format indicating the types of values the timer will pass.</param>
  96. * <returns>The ID of the timer.</returns>
  97. */
  98. native SetTimerEx_(func[], interval, delay, count, format[], {Float, _}:...);
  99. /**
  100. * <summary>Basic SetPlayerTimer.</summary>
  101. * <param name="playerid">The player that owns the timer.</param>
  102. * <param name="func">Name of the public function to call.</param>
  103. * <param name="interval">Interval in milliseconds.</param>
  104. * <param name="repeating">Whether this timer will repeat or will execute only one time.</param>
  105. * <returns>The ID of the timer.</returns>
  106. */
  107. native SetPlayerTimer(playerid, func[], interval, repeating);
  108. /**
  109. * <summary>Basic SetPlayerTimerEx.</summary>
  110. * <param name="playerid">The player that owns the timer.</param>
  111. * <param name="func">Name of the public function to call.</param>
  112. * <param name="interval">Interval in milliseconds.</param>
  113. * <param name="repeating">Whether this timer will repeat or will execute only one time.</param>
  114. * <param name="format">Special format indicating the types of values the timer will pass.</param>
  115. * <returns>The ID of the timer.</returns>
  116. */
  117. native SetPlayerTimerEx(playerid, func[], interval, repeating, const format[], {Float,_}:...);
  118. /**
  119. * <summary>An improved version of SetPlayerTimer.</summary>
  120. * <param name="playerid">The player that owns the timer.</param>
  121. * <param name="func">Name of the public function to call.</param>
  122. * <param name="interval">Interval in milliseconds.</param>
  123. * <param name="delay">Time after this timer should be called for the first time.</param>
  124. * <param name="count">How many times it should repeat before it's killed (-1 for unlimited).</param>
  125. * <returns>The ID of the timer.</returns>
  126. */
  127. native SetPlayerTimer_(playerid, func[], interval, delay, count);
  128. /**
  129. * <summary>An improved version of SetPlayerTimerEx.</summary>
  130. * <param name="playerid">The player that owns the timer.</param>
  131. * <param name="func">Name of the public function to call.</param>
  132. * <param name="interval">Interval in milliseconds.</param>
  133. * <param name="delay">Time after this timer should be called for the first time.</param>
  134. * <param name="count">How many times it should repeat before it's killed (-1 for unlimited).</param>
  135. * <param name="format">Special format indicating the types of values the timer will pass.</param>
  136. * <returns>The ID of the timer.</returns>
  137. */
  138. native SetPlayerTimerEx_(playerid, func[], interval, delay, count, format[], {Float, _}:...);
  139. /**
  140. * <summary>Gets the name of the function that is called.</summary>
  141. * <param name="timerid">The ID of the timer.</param>
  142. * <param name="func">The name of the function.</param>
  143. */
  144. native GetTimerFunctionName(timerid, func[]);
  145. /**
  146. * <summary>Sets the interval of a timer.</summary>
  147. * <param name="timerid">The ID of the timer.</param>
  148. * <param name="interval">The new interval.</param>
  149. */
  150. native SetTimerInterval(timerid, interval);
  151. /**
  152. * <summary>Gets the interval of a timer.</summary>
  153. * <param name="timerid">The ID of the timer.</param>
  154. * <returns>0 for invalid timers or the interval (in miliseconds).</returns>
  155. */
  156. native GetTimerInterval(timerid);
  157. /**
  158. * <summary>Gets the time remaining before this timer is called again.</summary>
  159. * <param name="timerid">The ID of the timer.</param>
  160. * <returns>0 for invalid timers or the time (in miliseconds) until the execution.</returns>
  161. */
  162. native GetTimerIntervalLeft(timerid);
  163. /**
  164. * <summary>Sets the delay of a timer.</summary>
  165. * <param name="timerid">The ID of the timer.</param>
  166. * <param name="delay">The new delay.</param>
  167. */
  168. native SetTimerDelay(timerid, delay);
  169. /**
  170. * <summary>Sets the count of a timer.</summary>
  171. * <param name="timerid">The ID of the timer.</param>
  172. * <param name="count">The new count.</param>
  173. */
  174. native SetTimerCount(timerid, count);
  175. /**
  176. * <summary>Gets the number of remaining calls of this timer.</summary>
  177. * <param name="timerid">The ID of the timer.</param>
  178. * <returns>-1 for infinite timers, 0 for invalid ones and positive values for the others.</returns>
  179. */
  180. native GetTimerCallsLeft(timerid);
  181. // Kills a player's timers on disconnect.
  182. public OnPlayerDisconnect(playerid, reason) {
  183. KillPlayerTimers(playerid);
  184. #if defined TIMERFIX_OnPlayerDisconnect
  185. return TIMERFIX_OnPlayerDisconnect(playerid, reason);
  186. #else
  187. return 1;
  188. #endif
  189. }
  190. #if defined _ALS_OnPlayerDisconnect
  191. #undef OnPlayerDisconnect
  192. #else
  193. #define _ALS_OnPlayerDisconnect
  194. #endif
  195. #define OnPlayerDisconnect TIMERFIX_OnPlayerDisconnect
  196. #if defined TIMERFIX_OnPlayerDisconnect
  197. forward TIMERFIX_OnPlayerDisconnect(playerid, reason);
  198. #endif