3 * =============================================================================
4 * SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved.
5 * =============================================================================
7 * This file is part of the SourceMod/SourcePawn SDK.
9 * This program is free software; you can redistribute it and/or modify it under
10 * the terms of the GNU General Public License, version 3.0, as published by the
11 * Free Software Foundation.
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
18 * You should have received a copy of the GNU General Public License along with
19 * this program. If not, see <http://www.gnu.org/licenses/>.
21 * As a special exception, AlliedModders LLC gives you permission to link the
22 * code of this program (as well as its derivative works) to "Half-Life 2," the
23 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
24 * by the Valve Corporation. You must obey the GNU General Public License in
25 * all respects for all other code used. Additionally, AlliedModders LLC grants
26 * this exception to all derivative works. AlliedModders LLC defines further
27 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
28 * or <http://www.sourcemod.net/license.php>.
33 #if defined _events_included
36 #define _events_included
39 * Event hook modes determining how hooking should be handled
43 EventHookMode_Pre, /**< Hook callback fired before event is fired */
44 EventHookMode_Post, /**< Hook callback fired after event is fired */
45 EventHookMode_PostNoCopy /**< Hook callback fired after event is fired, but event data won't be copied */
49 * Hook function types for events.
54 * Called when a game event is fired.
56 * @param event Handle to event. This could be INVALID_HANDLE if every plugin hooking
57 * this event has set the hook mode EventHookMode_PostNoCopy.
58 * @param name String containing the name of the event.
59 * @param dontBroadcast True if event was not broadcast to clients, false otherwise.
60 * @return Ignored for post hooks. Plugin_Handled will block event if hooked as pre.
62 Action:public(Handle:event, const String:name[], bool:dontBroadcast),
64 * Called when a game event is fired.
66 * @param event Handle to event. This could be INVALID_HANDLE if every plugin hooking
67 * this event has set the hook mode EventHookMode_PostNoCopy.
68 * @param name String containing the name of the event.
69 * @param dontBroadcast True if event was not broadcast to clients, false otherwise.
72 public(Handle:event, const String:name[], bool:dontBroadcast),
76 * Creates a hook for when a game event is fired.
78 * @param name Name of event.
79 * @param callback An EventHook function pointer.
80 * @param mode Optional EventHookMode determining the type of hook.
82 * @error Invalid event name or invalid callback function.
84 native HookEvent(const String:name[], EventHook:callback, EventHookMode:mode=EventHookMode_Post);
87 * Creates a hook for when a game event is fired.
89 * @param name Name of event.
90 * @param callback An EventHook function pointer.
91 * @param mode Optional EventHookMode determining the type of hook.
92 * @return True if event exists and was hooked successfully, false otherwise.
93 * @error Invalid callback function.
95 native bool:HookEventEx(const String:name[], EventHook:callback, EventHookMode:mode=EventHookMode_Post);
98 * Removes a hook for when a game event is fired.
100 * @param name Name of event.
101 * @param callback An EventHook function pointer.
102 * @param mode Optional EventHookMode determining the type of hook.
104 * @error Invalid callback function or no active hook for specified event.
106 native UnhookEvent(const String:name[], EventHook:callback, EventHookMode:mode=EventHookMode_Post);
109 * Creates a game event to be fired later.
111 * @param name Name of event.
112 * @param force If set to true, this forces the event to be created even if it's not being hooked.
113 * Note that this will not force it if the event doesn't exist at all.
114 * @return Handle to event. INVALID_HANDLE is returned if the event doesn't exist or isn't
115 being hooked (unless force is true).
117 native Handle:CreateEvent(const String:name[], bool:force=false);
120 * Fires a game event.
122 * @param event Handle to the event.
123 * @param dontBroadcast Optional boolean that determines if event should be broadcast to clients.
125 * @error Invalid or corrupt Handle.
127 native FireEvent(Handle:event, bool:dontBroadcast=false);
130 * Cancels a previously created game event that has not been fired.
132 * @param event Handled to the event.
134 * @error Invalid or corrupt Handle.
136 native CancelCreatedEvent(Handle:event);
139 * Returns the boolean value of a game event's key.
141 * @param event Handle to the event.
142 * @param key Name of event key.
143 * @return The boolean value of the specfied event key.
144 * @error Invalid or corrupt Handle.
146 native bool:GetEventBool(Handle:event, const String:key[]);
149 * Sets the boolean value of a game event's key.
151 * @param event Handle to the event.
152 * @param key Name of event key.
153 * @param value New boolean value.
155 * @error Invalid or corrupt Handle.
157 native SetEventBool(Handle:event, const String:key[], bool:value);
160 * Returns the integer value of a game event's key.
162 * @param event Handle to the event.
163 * @param key Name of event key.
164 * @return The integer value of the specfied event key.
165 * @error Invalid or corrupt Handle.
167 native GetEventInt(Handle:event, const String:key[]);
170 * Sets the integer value of a game event's key.
172 * @param event Handle to the event.
173 * @param key Name of event key.
174 * @param value New integer value.
176 * @error Invalid or corrupt Handle.
178 native SetEventInt(Handle:event, const String:key[], value);
181 * Returns the floating point value of a game event's key.
183 * @param event Handle to the event.
184 * @param key Name of event key.
185 * @return The floating point value of the specfied event key.
186 * @error Invalid or corrupt Handle.
188 native Float:GetEventFloat(Handle:event, const String:key[]);
191 * Sets the floating point value of a game event's key.
193 * @param event Handle to the event.
194 * @param key Name of event key.
195 * @param value New floating point value.
197 * @error Invalid or corrupt Handle.
199 native SetEventFloat(Handle:event, const String:key[], Float:value);
202 * Retrieves the string value of a game event's key.
204 * @param event Handle to the event.
205 * @param key Name of event key.
206 * @param value Buffer to store the value of the specified event key.
207 * @param maxlength Maximum length of string buffer.
209 * @error Invalid or corrupt Handle.
211 native GetEventString(Handle:event, const String:key[], String:value[], maxlength);
214 * Sets the string value of a game event's key.
216 * @param event Handle to the event.
217 * @param key Name of event key.
218 * @param value New string value.
220 * @error Invalid or corrupt Handle.
222 native SetEventString(Handle:event, const String:key[], const String:value[]);
225 * Retrieves the name of a game event.
227 * @param event Handle to the event.
228 * @param value Buffer to store the name of the event.
229 * @param maxlength Maximum length of string buffer.
231 * @error Invalid or corrupt Handle.
233 native GetEventName(Handle:event, String:name[], maxlength);