summaryrefslogtreecommitdiff
path: root/sourcemod-1.5-dev/scripting/include/events.inc
blob: d7e8f4c54728cab3a2886564b1bbd447116d0a52 (plain)
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
/**
 * vim: set ts=4 :
 * =============================================================================
 * SourceMod (C)2004-2008 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.
 */
funcenum 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.
	 * @return				Ignored for post hooks. Plugin_Handled will block event if hooked as pre.
	 */
	Action:public(Handle:event, const String: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.
	 * @noreturn
	 */
	public(Handle:event, const String:name[], bool:dontBroadcast),
};

/**
 * 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.
 * @noreturn
 * @error				Invalid event name or invalid callback function.
 */
native HookEvent(const String: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 String: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.
 * @noreturn
 * @error				Invalid callback function or no active hook for specified event.
 */
native UnhookEvent(const String: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 
 * FireEvent() or CancelCreatedEvent().
 *
 * @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 Handle:CreateEvent(const String: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.
 * @noreturn
 * @error				Invalid or corrupt Handle.
 */
native FireEvent(Handle:event, bool:dontBroadcast=false);

/**
 * Cancels a previously created game event that has not been fired.
 *
 * @param event			Handled to the event.
 * @noreturn
 * @error				Invalid or corrupt Handle.
 */
native 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.
 * @return				The boolean value of the specfied event key.
 * @error				Invalid or corrupt Handle.
 */
native bool:GetEventBool(Handle:event, const String:key[]);

/**
 * 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.
 * @noreturn
 * @error				Invalid or corrupt Handle.
 */
native SetEventBool(Handle:event, const String: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.
 * @return				The integer value of the specfied event key.
 * @error				Invalid or corrupt Handle.
 */
native GetEventInt(Handle:event, const String:key[]);

/**
 * 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.
 * @noreturn
 * @error				Invalid or corrupt Handle.
 */
native SetEventInt(Handle:event, const String:key[], value);

/**
 * Returns the floating point value of a game event's key.
 *
 * @param event			Handle to the event.
 * @param key			Name of event key.
 * @return				The floating point value of the specfied event key.
 * @error				Invalid or corrupt Handle.
 */
native Float:GetEventFloat(Handle:event, const String:key[]);

/**
 * 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.
 * @noreturn
 * @error				Invalid or corrupt Handle.
 */
native SetEventFloat(Handle:event, const String: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.
 * @noreturn
 * @error				Invalid or corrupt Handle.
 */
native GetEventString(Handle:event, const String:key[], String:value[], maxlength);

/**
 * 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.
 * @noreturn
 * @error				Invalid or corrupt Handle.
 */
native SetEventString(Handle:event, const String:key[], const String: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.
 * @noreturn
 * @error				Invalid or corrupt Handle.     
 */
native GetEventName(Handle:event, String:name[], 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.
 * @noreturn
 * @error               Invalid Handle.
 */
native SetEventBroadcast(Handle:event, bool:dontBroadcast);