plugins/include/events.inc
author Fyren <fyrenmoo@gmail.com>
Mon Apr 13 16:39:53 2009 -0700 (2009-04-13)
changeset 2696 32a50b96b644
parent 2289 44045ead61cd
child 2883 1d7b415cef73
permissions -rw-r--r--
Fix OnClientConnect rejectmsg handling, improve doc (bug 3690, r=dvander)
ds@576
     1
/**
ds@576
     2
 * vim: set ts=4 :
ds@1330
     3
 * =============================================================================
ds@1947
     4
 * SourceMod (C)2004-2008 AlliedModders LLC.  All rights reserved.
ds@1330
     5
 * =============================================================================
ds@1330
     6
 *
ds@1330
     7
 * This file is part of the SourceMod/SourcePawn SDK.
ds@576
     8
 *
ds@1330
     9
 * This program is free software; you can redistribute it and/or modify it under
ds@1330
    10
 * the terms of the GNU General Public License, version 3.0, as published by the
ds@1330
    11
 * Free Software Foundation.
ds@1330
    12
 * 
ds@1330
    13
 * This program is distributed in the hope that it will be useful, but WITHOUT
ds@1330
    14
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
ds@1330
    15
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
ds@1330
    16
 * details.
ds@1330
    17
 *
ds@1330
    18
 * You should have received a copy of the GNU General Public License along with
ds@1330
    19
 * this program.  If not, see <http://www.gnu.org/licenses/>.
ds@1330
    20
 *
ds@1330
    21
 * As a special exception, AlliedModders LLC gives you permission to link the
ds@1330
    22
 * code of this program (as well as its derivative works) to "Half-Life 2," the
ds@1330
    23
 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
ds@1330
    24
 * by the Valve Corporation.  You must obey the GNU General Public License in
ds@1330
    25
 * all respects for all other code used.  Additionally, AlliedModders LLC grants
ds@1330
    26
 * this exception to all derivative works.  AlliedModders LLC defines further
ds@1330
    27
 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
ds@1330
    28
 * or <http://www.sourcemod.net/license.php>.
ds@576
    29
 *
ds@576
    30
 * Version: $Id$
ds@576
    31
 */
ds@576
    32
 
ds@576
    33
#if defined _events_included
ds@576
    34
 #endinput
ds@576
    35
#endif
ds@576
    36
#define _events_included
ds@576
    37
ds@576
    38
/**
ds@576
    39
 * Event hook modes determining how hooking should be handled
ds@576
    40
 */
ds@576
    41
enum EventHookMode
ds@576
    42
{
ds@576
    43
	EventHookMode_Pre,					/**< Hook callback fired before event is fired */
ds@576
    44
	EventHookMode_Post,					/**< Hook callback fired after event is fired */
ds@576
    45
	EventHookMode_PostNoCopy			/**< Hook callback fired after event is fired, but event data won't be copied */
ds@576
    46
};
ds@576
    47
dvander@619
    48
/**
dvander@619
    49
 * Hook function types for events.
dvander@619
    50
 */
ds@576
    51
funcenum EventHook
ds@576
    52
{
ds@576
    53
	/**
ds@576
    54
	 * Called when a game event is fired.
ds@576
    55
	 *
ds@576
    56
	 * @param event			Handle to event. This could be INVALID_HANDLE if every plugin hooking 
ds@576
    57
	 *						this event has set the hook mode EventHookMode_PostNoCopy.
ds@576
    58
	 * @param name			String containing the name of the event.
ds@576
    59
	 * @param dontBroadcast	True if event was not broadcast to clients, false otherwise.
ds@576
    60
	 * @return				Ignored for post hooks. Plugin_Handled will block event if hooked as pre.
ds@576
    61
	 */
ds@576
    62
	Action:public(Handle:event, const String:name[], bool:dontBroadcast),
ds@576
    63
	/**
ds@576
    64
	 * Called when a game event is fired.
ds@576
    65
	 *
ds@576
    66
	 * @param event			Handle to event. This could be INVALID_HANDLE if every plugin hooking 
ds@576
    67
	 *						this event has set the hook mode EventHookMode_PostNoCopy.
ds@576
    68
	 * @param name			String containing the name of the event.
ds@576
    69
	 * @param dontBroadcast	True if event was not broadcast to clients, false otherwise.
ds@576
    70
	 * @noreturn
ds@576
    71
	 */
ds@576
    72
	public(Handle:event, const String:name[], bool:dontBroadcast),
ds@576
    73
};
ds@576
    74
ds@576
    75
/**
ds@576
    76
 * Creates a hook for when a game event is fired.
ds@576
    77
 *
ds@576
    78
 * @param name			Name of event.
ds@576
    79
 * @param callback		An EventHook function pointer.
ds@576
    80
 * @param mode			Optional EventHookMode determining the type of hook.
ds@576
    81
 * @noreturn
ds@576
    82
 * @error				Invalid event name or invalid callback function.
ds@576
    83
 */
ds@576
    84
native HookEvent(const String:name[], EventHook:callback, EventHookMode:mode=EventHookMode_Post);
ds@576
    85
ds@576
    86
/**
ds@801
    87
 * Creates a hook for when a game event is fired.
ds@801
    88
 *
ds@801
    89
 * @param name			Name of event.
ds@801
    90
 * @param callback		An EventHook function pointer.
ds@801
    91
 * @param mode			Optional EventHookMode determining the type of hook.
ds@801
    92
 * @return				True if event exists and was hooked successfully, false otherwise.
ds@801
    93
 * @error				Invalid callback function.
ds@801
    94
 */
ds@801
    95
native bool:HookEventEx(const String:name[], EventHook:callback, EventHookMode:mode=EventHookMode_Post);
ds@801
    96
ds@801
    97
/**
ds@576
    98
 * Removes a hook for when a game event is fired.
ds@576
    99
 *
ds@576
   100
 * @param name			Name of event.
ds@576
   101
 * @param callback		An EventHook function pointer.
ds@576
   102
 * @param mode			Optional EventHookMode determining the type of hook.
ds@576
   103
 * @noreturn
ds@576
   104
 * @error				Invalid callback function or no active hook for specified event.
ds@576
   105
 */
ds@576
   106
native UnhookEvent(const String:name[], EventHook:callback, EventHookMode:mode=EventHookMode_Post);
ds@576
   107
ds@576
   108
/**
ds@576
   109
 * Creates a game event to be fired later.
ds@576
   110
 *
dvander@1851
   111
 * The Handle should not be closed via CloseHandle().  It must be closed via 
dvander@1851
   112
 * FireEvent() or CancelCreatedEvent().
dvander@1851
   113
 *
ds@576
   114
 * @param name			Name of event.
ds@713
   115
 * @param force			If set to true, this forces the event to be created even if it's not being hooked.
ds@713
   116
 *						Note that this will not force it if the event doesn't exist at all.
ds@713
   117
 * @return				Handle to event. INVALID_HANDLE is returned if the event doesn't exist or isn't 
ds@713
   118
						being hooked (unless force is true).
ds@576
   119
 */
ds@713
   120
native Handle:CreateEvent(const String:name[], bool:force=false);
ds@576
   121
ds@576
   122
/**
ds@576
   123
 * Fires a game event.
ds@576
   124
 *
dvander@1851
   125
 * This function closes the event Handle after completing.
dvander@1851
   126
 *
ds@576
   127
 * @param event			Handle to the event.
ds@576
   128
 * @param dontBroadcast	Optional boolean that determines if event should be broadcast to clients.
ds@576
   129
 * @noreturn
ds@576
   130
 * @error				Invalid or corrupt Handle.
ds@576
   131
 */
ds@712
   132
native FireEvent(Handle:event, bool:dontBroadcast=false);
ds@576
   133
ds@576
   134
/**
ds@576
   135
 * Cancels a previously created game event that has not been fired.
ds@576
   136
 *
ds@576
   137
 * @param event			Handled to the event.
ds@576
   138
 * @noreturn
ds@576
   139
 * @error				Invalid or corrupt Handle.
ds@576
   140
 */
ds@576
   141
native CancelCreatedEvent(Handle:event);
ds@576
   142
ds@576
   143
/**
ds@576
   144
 * Returns the boolean value of a game event's key.
ds@576
   145
 *
ds@576
   146
 * @param event			Handle to the event.
ds@576
   147
 * @param key			Name of event key.
ds@576
   148
 * @return				The boolean value of the specfied event key.
ds@576
   149
 * @error				Invalid or corrupt Handle.
ds@576
   150
 */
ds@576
   151
native bool:GetEventBool(Handle:event, const String:key[]);
ds@576
   152
ds@576
   153
/**
ds@576
   154
 * Sets the boolean value of a game event's key.
ds@576
   155
 *
ds@576
   156
 * @param event			Handle to the event.
ds@576
   157
 * @param key			Name of event key.
ds@576
   158
 * @param value			New boolean value.
ds@576
   159
 * @noreturn
ds@576
   160
 * @error				Invalid or corrupt Handle.
ds@576
   161
 */
ds@576
   162
native SetEventBool(Handle:event, const String:key[], bool:value);
ds@576
   163
ds@576
   164
/**
ds@576
   165
 * Returns the integer value of a game event's key.
ds@576
   166
 *
ds@576
   167
 * @param event			Handle to the event.
ds@576
   168
 * @param key			Name of event key.
ds@576
   169
 * @return				The integer value of the specfied event key.
ds@576
   170
 * @error				Invalid or corrupt Handle.
ds@576
   171
 */
ds@576
   172
native GetEventInt(Handle:event, const String:key[]);
ds@576
   173
ds@576
   174
/**
ds@576
   175
 * Sets the integer value of a game event's key.
ds@576
   176
 *
dvander@1851
   177
 * Integer value refers to anything that can be reduced to an integer.
dvander@1851
   178
 * The various size specifiers, such as "byte" and "short" are still 
dvander@1851
   179
 * integers, and only refer to how much data will actually be sent 
dvander@1851
   180
 * over the network (if applicable).
dvander@1851
   181
 *
ds@576
   182
 * @param event			Handle to the event.
ds@576
   183
 * @param key			Name of event key.
ds@576
   184
 * @param value			New integer value.
ds@576
   185
 * @noreturn
ds@576
   186
 * @error				Invalid or corrupt Handle.
ds@576
   187
 */
ds@576
   188
native SetEventInt(Handle:event, const String:key[], value);
ds@576
   189
ds@576
   190
/**
ds@576
   191
 * Returns the floating point value of a game event's key.
ds@576
   192
 *
ds@576
   193
 * @param event			Handle to the event.
ds@576
   194
 * @param key			Name of event key.
ds@576
   195
 * @return				The floating point value of the specfied event key.
ds@576
   196
 * @error				Invalid or corrupt Handle.
ds@576
   197
 */
ds@576
   198
native Float:GetEventFloat(Handle:event, const String:key[]);
ds@576
   199
ds@576
   200
/**
ds@576
   201
 * Sets the floating point value of a game event's key.
ds@576
   202
 *
ds@576
   203
 * @param event			Handle to the event.
ds@576
   204
 * @param key			Name of event key.
ds@576
   205
 * @param value			New floating point value.
ds@576
   206
 * @noreturn
ds@576
   207
 * @error				Invalid or corrupt Handle.
ds@576
   208
 */
ds@576
   209
native SetEventFloat(Handle:event, const String:key[], Float:value);
ds@576
   210
ds@576
   211
/**
ds@576
   212
 * Retrieves the string value of a game event's key.
ds@576
   213
 *
ds@576
   214
 * @param event			Handle to the event.
ds@576
   215
 * @param key			Name of event key.
ds@576
   216
 * @param value			Buffer to store the value of the specified event key.
ds@576
   217
 * @param maxlength		Maximum length of string buffer.
ds@576
   218
 * @noreturn
ds@576
   219
 * @error				Invalid or corrupt Handle.
ds@576
   220
 */
ds@576
   221
native GetEventString(Handle:event, const String:key[], String:value[], maxlength);
ds@576
   222
ds@576
   223
/**
ds@576
   224
 * Sets the string value of a game event's key.
ds@576
   225
 *
ds@576
   226
 * @param event			Handle to the event.
ds@576
   227
 * @param key			Name of event key.
ds@576
   228
 * @param value			New string value.
ds@576
   229
 * @noreturn
ds@576
   230
 * @error				Invalid or corrupt Handle.
ds@576
   231
 */
ds@576
   232
native SetEventString(Handle:event, const String:key[], const String:value[]);
ds@576
   233
ds@576
   234
/**
ds@576
   235
 * Retrieves the name of a game event.
ds@576
   236
 *
ds@576
   237
 * @param event			Handle to the event.
ds@576
   238
 * @param value			Buffer to store the name of the event.
ds@576
   239
 * @param maxlength		Maximum length of string buffer.
ds@576
   240
 * @noreturn
ds@576
   241
 * @error				Invalid or corrupt Handle.     
ds@576
   242
 */
ds@576
   243
native GetEventName(Handle:event, String:name[], maxlength);