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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
|
/**
* vim: set ts=4 sw=4 tw=99 noet :
* =============================================================================
* SourceMod (C)2004-2014 AlliedModders LLC. All rights reserved.
* =============================================================================
*
* This file is part of the SourceMod/SourcePawn SDK.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*
* As a special exception, AlliedModders LLC gives you permission to link the
* code of this program (as well as its derivative works) to "Half-Life 2," the
* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
* by the Valve Corporation. You must obey the GNU General Public License in
* all respects for all other code used. Additionally, AlliedModders LLC grants
* this exception to all derivative works. AlliedModders LLC defines further
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
* or <http://www.sourcemod.net/license.php>.
*
* Version: $Id$
*/
#if defined _events_included
#endinput
#endif
#define _events_included
/**
* Event hook modes determining how hooking should be handled
*/
enum EventHookMode
{
EventHookMode_Pre, //< Hook callback fired before event is fired */
EventHookMode_Post, //< Hook callback fired after event is fired */
EventHookMode_PostNoCopy //< Hook callback fired after event is fired, but event data won't be copied */
};
/**
* Hook function types for events.
*/
typeset EventHook
{
// Called when a game event is fired.
//
// @param event Handle to event. This could be INVALID_HANDLE if every plugin hooking
// this event has set the hook mode EventHookMode_PostNoCopy.
// @param name String containing the name of the event.
// @param dontBroadcast True if event was not broadcast to clients, false otherwise.
// May not correspond to the real value. Use the property BroadcastDisabled.
// @return Ignored for post hooks. Plugin_Handled will block event if hooked as pre.
///
function Action (Event event, const char[] name, bool dontBroadcast);
//
// Called when a game event is fired.
//
// @param event Handle to event. This could be INVALID_HANDLE if every plugin hooking
// this event has set the hook mode EventHookMode_PostNoCopy.
// @param name String containing the name of the event.
// @param dontBroadcast True if event was not broadcast to clients, false otherwise.
///
function void (Event event, const char[] name, bool dontBroadcast);
};
methodmap Event < Handle
{
// Fires a game event.
//
// This function closes the event Handle after completing.
//
// @param dontBroadcast Optional boolean that determines if event should be broadcast to clients.
public native void Fire(bool dontBroadcast=false);
// Fires a game event to only the specified client.
//
// Unlike Fire, this function DOES NOT close the event Handle.
//
// @param client Index of client to receive the event..
public native void FireToClient(int client);
// Cancels a previously created game event that has not been fired. This
// is necessary to avoid leaking memory when an event isn't fired.
public native void Cancel();
// Returns the boolean value of a game event's key.
//
// @param key Name of event key.
// @param defValue Optional default value to use if the key is not found.
// @return The boolean value of the specified event key.
public native bool GetBool(const char[] key, bool defValue=false);
// Sets the boolean value of a game event's key.
//
// @param key Name of event key.
// @param value New boolean value.
public native void SetBool(const char[] key, bool value);
// Returns the integer value of a game event's key.
//
// @param key Name of event key.
// @param defValue Optional default value to use if the key is not found.
// @return The integer value of the specified event key.
public native int GetInt(const char[] key, int defValue=0);
// Sets the integer value of a game event's key.
//
// Integer value refers to anything that can be reduced to an integer.
// The various size specifiers, such as "byte" and "short" are still
// integers, and only refer to how much data will actually be sent
// over the network (if applicable).
//
// @param key Name of event key.
// @param value New integer value.
public native void SetInt(const char[] key, int value);
// Returns the floating point value of a game event's key.
//
// @param key Name of event key.
// @param defValue Optional default value to use if the key is not found.
// @return The floating point value of the specified event key.
public native float GetFloat(const char[] key, float defValue=0.0);
// Sets the floating point value of a game event's key.
//
// @param key Name of event key.
// @param value New floating point value.
public native void SetFloat(const char[] key, float value);
// Retrieves the string value of a game event's key.
//
// @param key Name of event key.
// @param value Buffer to store the value of the specified event key.
// @param maxlength Maximum length of string buffer.
// @param defValue Optional default value to use if the key is not found.
public native void GetString(const char[] key, char[] value, int maxlength, const char[] defvalue="");
// Sets the string value of a game event's key.
//
// @param key Name of event key.
// @param value New string value.
public native void SetString(const char[] key, const char[] value);
// Retrieves the name of a game event.
//
// @param name Buffer to store the name of the event.
// @param maxlength Maximum length of string buffer.
public native void GetName(char[] name, int maxlength);
// Sets whether an event's broadcasting will be disabled or not.
//
// This has no effect on events Handles that are not from HookEvent
// or HookEventEx callbacks.
property bool BroadcastDisabled {
public native set(bool dontBroadcast);
public native get();
}
}
/**
* Creates a hook for when a game event is fired.
*
* @param name Name of event.
* @param callback An EventHook function pointer.
* @param mode Optional EventHookMode determining the type of hook.
* @error Invalid event name or invalid callback function.
*/
native void HookEvent(const char[] name, EventHook callback, EventHookMode mode=EventHookMode_Post);
/**
* Creates a hook for when a game event is fired.
*
* @param name Name of event.
* @param callback An EventHook function pointer.
* @param mode Optional EventHookMode determining the type of hook.
* @return True if event exists and was hooked successfully, false otherwise.
* @error Invalid callback function.
*/
native bool HookEventEx(const char[] name, EventHook callback, EventHookMode mode=EventHookMode_Post);
/**
* Removes a hook for when a game event is fired.
*
* @param name Name of event.
* @param callback An EventHook function pointer.
* @param mode Optional EventHookMode determining the type of hook.
* @error Invalid callback function or no active hook for specified event.
*/
native void UnhookEvent(const char[] name, EventHook callback, EventHookMode mode=EventHookMode_Post);
/**
* Creates a game event to be fired later.
*
* The Handle should not be closed via CloseHandle(). It must be closed via
* event.Fire() or event.Cancel().
*
* @param name Name of event.
* @param force If set to true, this forces the event to be created even if it's not being hooked.
* Note that this will not force it if the event doesn't exist at all.
* @return Handle to event. INVALID_HANDLE is returned if the event doesn't exist or isn't
* being hooked (unless force is true).
*/
native Event CreateEvent(const char[] name, bool force=false);
/**
* Fires a game event.
*
* This function closes the event Handle after completing.
*
* @param event Handle to the event.
* @param dontBroadcast Optional boolean that determines if event should be broadcast to clients.
* @error Invalid or corrupt Handle.
*/
native void FireEvent(Handle event, bool dontBroadcast=false);
/**
* Cancels a previously created game event that has not been fired.
*
* @param event Handled to the event.
* @error Invalid or corrupt Handle.
*/
native void CancelCreatedEvent(Handle event);
/**
* Returns the boolean value of a game event's key.
*
* @param event Handle to the event.
* @param key Name of event key.
* @param defValue Optional default value to use if the key is not found.
* @return The boolean value of the specified event key.
* @error Invalid or corrupt Handle.
*/
native bool GetEventBool(Handle event, const char[] key, bool defValue=false);
/**
* Sets the boolean value of a game event's key.
*
* @param event Handle to the event.
* @param key Name of event key.
* @param value New boolean value.
* @error Invalid or corrupt Handle.
*/
native void SetEventBool(Handle event, const char[] key, bool value);
/**
* Returns the integer value of a game event's key.
*
* @param event Handle to the event.
* @param key Name of event key.
* @param defValue Optional default value to use if the key is not found.
* @return The integer value of the specified event key.
* @error Invalid or corrupt Handle.
*/
native int GetEventInt(Handle event, const char[] key, int defValue=0);
/**
* Sets the integer value of a game event's key.
*
* Integer value refers to anything that can be reduced to an integer.
* The various size specifiers, such as "byte" and "short" are still
* integers, and only refer to how much data will actually be sent
* over the network (if applicable).
*
* @param event Handle to the event.
* @param key Name of event key.
* @param value New integer value.
* @error Invalid or corrupt Handle.
*/
native void SetEventInt(Handle event, const char[] key, int value);
/**
* Returns the floating point value of a game event's key.
*
* @param event Handle to the event.
* @param key Name of event key.
* @param defValue Optional default value to use if the key is not found.
* @return The floating point value of the specified event key.
* @error Invalid or corrupt Handle.
*/
native float GetEventFloat(Handle event, const char[] key, float defValue=0.0);
/**
* Sets the floating point value of a game event's key.
*
* @param event Handle to the event.
* @param key Name of event key.
* @param value New floating point value.
* @error Invalid or corrupt Handle.
*/
native void SetEventFloat(Handle event, const char[] key, float value);
/**
* Retrieves the string value of a game event's key.
*
* @param event Handle to the event.
* @param key Name of event key.
* @param value Buffer to store the value of the specified event key.
* @param maxlength Maximum length of string buffer.
* @param defValue Optional default value to use if the key is not found.
* @error Invalid or corrupt Handle.
*/
native void GetEventString(Handle event, const char[] key, char[] value, int maxlength, const char[] defvalue="");
/**
* Sets the string value of a game event's key.
*
* @param event Handle to the event.
* @param key Name of event key.
* @param value New string value.
* @error Invalid or corrupt Handle.
*/
native void SetEventString(Handle event, const char[] key, const char[] value);
/**
* Retrieves the name of a game event.
*
* @param event Handle to the event.
* @param name Buffer to store the name of the event.
* @param maxlength Maximum length of string buffer.
* @error Invalid or corrupt Handle.
*/
native void GetEventName(Handle event, char[] name, int maxlength);
/**
* Sets whether an event's broadcasting will be disabled or not.
*
* This has no effect on events Handles that are not from HookEvent
* or HookEventEx callbacks.
*
* @param event Handle to an event from an event hook.
* @param dontBroadcast True to disable broadcasting, false otherwise.
* @error Invalid Handle.
*/
native void SetEventBroadcast(Handle event, bool dontBroadcast);
|