forked from udan11/samp-plugin-timerfix
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathtimerfix.inc
235 lines (210 loc) · 9.24 KB
/
timerfix.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
/**
* 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.
*/
/**
* <version>1.8</version>
* <remarks>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
* </remarks>
*/
#if defined _timerfix_included
#endinput
#endif
#define _timerfix_included
#pragma library timerfix
/**
* <summary>Same KillTimer is used for all types of timer.</summary>
*/
#define KillTimer_ KillTimer
/**
* <summary>Improved GetTickCount (more accurate).</summary>
* <returns>Current time in miliseconds.</returns>
*/
//native GetTickCount();
/**
* <summary>Checks if a timer is still alive.</summary>
* <param name="timerid">The ID of the timer.</param>
* <returns>`true` if the timer is valid or `false` otherwise.</returns>
*/
native IsValidTimer(timerid);
/**
* <summary>Gets the number of active timers.</summary>
* <returns>The number of active timers.</returns>
*/
native GetActiveTimers();
/**
* <summary>Kills specified timer owned by player.</summary>
* <param name="timerid">The ID of the timer.</param>
*/
native KillPlayerTimer(timerid) = KillTimer;
/**
* <summary>Kills all timers a player owns.</summary>
* <param name="playerid">The player that owns the timers.</param>
*/
native KillPlayerTimers(playerid);
/**
* <summary>Basic SetTimer.</summary>
* <param name="func">Name of the public function to call.</param>
* <param name="interval">Interval in milliseconds.</param>
* <param name="repeating">Whether this timer will repeat or will execute only one time.</param>
* <returns>The ID of the timer.</returns>
*/
//native SetTimer(const func[], interval, repeating);
/**
* <summary>Basic SetTimerEx.</summary>
* <param name="func">Name of the public function to call.</param>
* <param name="interval">Interval in milliseconds.</param>
* <param name="repeating">Whether this timer will repeat or will execute only one time.</param>
* <param name="format">Special format indicating the types of values the timer will pass.</param>
* <returns>The ID of the timer.</returns>
*/
//native SetTimerEx(const func[], interval, repeating, const format[], {Float,_}:...);
/**
* <summary>An improved version of SetTimer.</summary>
* <param name="func">Name of the public function to call.</param>
* <param name="interval">Interval in milliseconds.</param>
* <param name="delay">Time after this timer should be called for the first time.</param>
* <param name="count">How many times it should repeat before it's killed (-1 for unlimited).</param>
* <returns>The ID of the timer.</returns>
*/
native SetTimer_(const func[], interval, delay, count);
/**
* <summary>An improved version of SetTimerEx.</summary>
* <param name="func">Name of the public function to call.</param>
* <param name="interval">Interval in milliseconds.</param>
* <param name="delay">Time after this timer should be called for the first time.</param>
* <param name="count">How many times it should repeat before it's killed (-1 for unlimited).</param>
* <param name="format">Special format indicating the types of values the timer will pass.</param>
* <returns>The ID of the timer.</returns>
*/
native SetTimerEx_(const func[], interval, delay, count,const format[], {Float, _}:...);
/**
* <summary>Basic SetPlayerTimer.</summary>
* <param name="playerid">The player that owns the timer.</param>
* <param name="func">Name of the public function to call.</param>
* <param name="interval">Interval in milliseconds.</param>
* <param name="repeating">Whether this timer will repeat or will execute only one time.</param>
* <returns>The ID of the timer.</returns>
*/
native SetPlayerTimer(playerid,const func[], interval, repeating);
/**
* <summary>Basic SetPlayerTimerEx.</summary>
* <param name="playerid">The player that owns the timer.</param>
* <param name="func">Name of the public function to call.</param>
* <param name="interval">Interval in milliseconds.</param>
* <param name="repeating">Whether this timer will repeat or will execute only one time.</param>
* <param name="format">Special format indicating the types of values the timer will pass.</param>
* <returns>The ID of the timer.</returns>
*/
native SetPlayerTimerEx(playerid,const func[], interval, repeating, const format[], {Float,_}:...);
/**
* <summary>An improved version of SetPlayerTimer.</summary>
* <param name="playerid">The player that owns the timer.</param>
* <param name="func">Name of the public function to call.</param>
* <param name="interval">Interval in milliseconds.</param>
* <param name="delay">Time after this timer should be called for the first time.</param>
* <param name="count">How many times it should repeat before it's killed (-1 for unlimited).</param>
* <returns>The ID of the timer.</returns>
*/
native SetPlayerTimer_(playerid, const func[], interval, delay, count);
/**
* <summary>An improved version of SetPlayerTimerEx.</summary>
* <param name="playerid">The player that owns the timer.</param>
* <param name="func">Name of the public function to call.</param>
* <param name="interval">Interval in milliseconds.</param>
* <param name="delay">Time after this timer should be called for the first time.</param>
* <param name="count">How many times it should repeat before it's killed (-1 for unlimited).</param>
* <param name="format">Special format indicating the types of values the timer will pass.</param>
* <returns>The ID of the timer.</returns>
*/
native SetPlayerTimerEx_(playerid, const func[], interval, delay, count, const format[], {Float, _}:...);
/**
* <summary>Gets the name of the function that is called.</summary>
* <param name="timerid">The ID of the timer.</param>
* <param name="func">The name of the function.</param>
* <param name="maxlength">Maximum length of the returned function name.</param>
*/
native GetTimerFunctionName(timerid, const func[], maxlength = sizeof(func));
/**
* <summary>Sets the interval of a timer.</summary>
* <param name="timerid">The ID of the timer.</param>
* <param name="interval">The new interval.</param>
*/
native SetTimerInterval(timerid, interval);
/**
* <summary>Sets the time remaining before this timer is called again.</summary>
* <param name="timerid">The ID of the timer.</param>
* <param name="interval">The new interval.</param>
*/
native SetTimerIntervalLeft(timerid, interval);
/**
* <summary>Gets the interval of a timer.</summary>
* <param name="timerid">The ID of the timer.</param>
* <returns>0 for invalid timers or the interval (in miliseconds).</returns>
*/
native GetTimerInterval(timerid);
/**
* <summary>Gets the time remaining before this timer is called again.</summary>
* <param name="timerid">The ID of the timer.</param>
* <returns>0 for invalid timers or the time (in miliseconds) until the execution.</returns>
*/
native GetTimerIntervalLeft(timerid);
/**
* <summary>Sets the delay of a timer.</summary>
* <param name="timerid">The ID of the timer.</param>
* <param name="delay">The new delay.</param>
*/
native SetTimerDelay(timerid, delay);
/**
* <summary>Sets the count of a timer.</summary>
* <param name="timerid">The ID of the timer.</param>
* <param name="count">The new count.</param>
*/
native SetTimerCount(timerid, count);
/**
* <summary>Gets the number of remaining calls of this timer.</summary>
* <param name="timerid">The ID of the timer.</param>
* <returns>-1 for infinite timers, 0 for invalid ones and positive values for the others.</returns>
*/
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