plugins/include/events.inc
author Dr!fter
Thu Jul 18 21:04:03 2013 -0400 (2013-07-18)
changeset 3956 1ccbc1dfa814
parent 2883 1d7b415cef73
child 3967 ceafb87d38a7
permissions -rw-r--r--
Fix gdc-psyfork when checking linux offset (NPOTB)
     1 /**
     2  * vim: set ts=4 :
     3  * =============================================================================
     4  * SourceMod (C)2004-2008 AlliedModders LLC.  All rights reserved.
     5  * =============================================================================
     6  *
     7  * This file is part of the SourceMod/SourcePawn SDK.
     8  *
     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.
    12  * 
    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
    16  * details.
    17  *
    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/>.
    20  *
    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>.
    29  *
    30  * Version: $Id$
    31  */
    32  
    33 #if defined _events_included
    34  #endinput
    35 #endif
    36 #define _events_included
    37 
    38 /**
    39  * Event hook modes determining how hooking should be handled
    40  */
    41 enum EventHookMode
    42 {
    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 */
    46 };
    47 
    48 /**
    49  * Hook function types for events.
    50  */
    51 funcenum EventHook
    52 {
    53 	/**
    54 	 * Called when a game event is fired.
    55 	 *
    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.
    61 	 */
    62 	Action:public(Handle:event, const String:name[], bool:dontBroadcast),
    63 	/**
    64 	 * Called when a game event is fired.
    65 	 *
    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.
    70 	 * @noreturn
    71 	 */
    72 	public(Handle:event, const String:name[], bool:dontBroadcast),
    73 };
    74 
    75 /**
    76  * Creates a hook for when a game event is fired.
    77  *
    78  * @param name			Name of event.
    79  * @param callback		An EventHook function pointer.
    80  * @param mode			Optional EventHookMode determining the type of hook.
    81  * @noreturn
    82  * @error				Invalid event name or invalid callback function.
    83  */
    84 native HookEvent(const String:name[], EventHook:callback, EventHookMode:mode=EventHookMode_Post);
    85 
    86 /**
    87  * Creates a hook for when a game event is fired.
    88  *
    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.
    94  */
    95 native bool:HookEventEx(const String:name[], EventHook:callback, EventHookMode:mode=EventHookMode_Post);
    96 
    97 /**
    98  * Removes a hook for when a game event is fired.
    99  *
   100  * @param name			Name of event.
   101  * @param callback		An EventHook function pointer.
   102  * @param mode			Optional EventHookMode determining the type of hook.
   103  * @noreturn
   104  * @error				Invalid callback function or no active hook for specified event.
   105  */
   106 native UnhookEvent(const String:name[], EventHook:callback, EventHookMode:mode=EventHookMode_Post);
   107 
   108 /**
   109  * Creates a game event to be fired later.
   110  *
   111  * The Handle should not be closed via CloseHandle().  It must be closed via 
   112  * FireEvent() or CancelCreatedEvent().
   113  *
   114  * @param name			Name of event.
   115  * @param force			If set to true, this forces the event to be created even if it's not being hooked.
   116  *						Note that this will not force it if the event doesn't exist at all.
   117  * @return				Handle to event. INVALID_HANDLE is returned if the event doesn't exist or isn't 
   118 						being hooked (unless force is true).
   119  */
   120 native Handle:CreateEvent(const String:name[], bool:force=false);
   121 
   122 /**
   123  * Fires a game event.
   124  *
   125  * This function closes the event Handle after completing.
   126  *
   127  * @param event			Handle to the event.
   128  * @param dontBroadcast	Optional boolean that determines if event should be broadcast to clients.
   129  * @noreturn
   130  * @error				Invalid or corrupt Handle.
   131  */
   132 native FireEvent(Handle:event, bool:dontBroadcast=false);
   133 
   134 /**
   135  * Cancels a previously created game event that has not been fired.
   136  *
   137  * @param event			Handled to the event.
   138  * @noreturn
   139  * @error				Invalid or corrupt Handle.
   140  */
   141 native CancelCreatedEvent(Handle:event);
   142 
   143 /**
   144  * Returns the boolean value of a game event's key.
   145  *
   146  * @param event			Handle to the event.
   147  * @param key			Name of event key.
   148  * @return				The boolean value of the specfied event key.
   149  * @error				Invalid or corrupt Handle.
   150  */
   151 native bool:GetEventBool(Handle:event, const String:key[]);
   152 
   153 /**
   154  * Sets the boolean value of a game event's key.
   155  *
   156  * @param event			Handle to the event.
   157  * @param key			Name of event key.
   158  * @param value			New boolean value.
   159  * @noreturn
   160  * @error				Invalid or corrupt Handle.
   161  */
   162 native SetEventBool(Handle:event, const String:key[], bool:value);
   163 
   164 /**
   165  * Returns the integer value of a game event's key.
   166  *
   167  * @param event			Handle to the event.
   168  * @param key			Name of event key.
   169  * @return				The integer value of the specfied event key.
   170  * @error				Invalid or corrupt Handle.
   171  */
   172 native GetEventInt(Handle:event, const String:key[]);
   173 
   174 /**
   175  * Sets the integer value of a game event's key.
   176  *
   177  * Integer value refers to anything that can be reduced to an integer.
   178  * The various size specifiers, such as "byte" and "short" are still 
   179  * integers, and only refer to how much data will actually be sent 
   180  * over the network (if applicable).
   181  *
   182  * @param event			Handle to the event.
   183  * @param key			Name of event key.
   184  * @param value			New integer value.
   185  * @noreturn
   186  * @error				Invalid or corrupt Handle.
   187  */
   188 native SetEventInt(Handle:event, const String:key[], value);
   189 
   190 /**
   191  * Returns the floating point value of a game event's key.
   192  *
   193  * @param event			Handle to the event.
   194  * @param key			Name of event key.
   195  * @return				The floating point value of the specfied event key.
   196  * @error				Invalid or corrupt Handle.
   197  */
   198 native Float:GetEventFloat(Handle:event, const String:key[]);
   199 
   200 /**
   201  * Sets the floating point value of a game event's key.
   202  *
   203  * @param event			Handle to the event.
   204  * @param key			Name of event key.
   205  * @param value			New floating point value.
   206  * @noreturn
   207  * @error				Invalid or corrupt Handle.
   208  */
   209 native SetEventFloat(Handle:event, const String:key[], Float:value);
   210 
   211 /**
   212  * Retrieves the string value of a game event's key.
   213  *
   214  * @param event			Handle to the event.
   215  * @param key			Name of event key.
   216  * @param value			Buffer to store the value of the specified event key.
   217  * @param maxlength		Maximum length of string buffer.
   218  * @noreturn
   219  * @error				Invalid or corrupt Handle.
   220  */
   221 native GetEventString(Handle:event, const String:key[], String:value[], maxlength);
   222 
   223 /**
   224  * Sets the string value of a game event's key.
   225  *
   226  * @param event			Handle to the event.
   227  * @param key			Name of event key.
   228  * @param value			New string value.
   229  * @noreturn
   230  * @error				Invalid or corrupt Handle.
   231  */
   232 native SetEventString(Handle:event, const String:key[], const String:value[]);
   233 
   234 /**
   235  * Retrieves the name of a game event.
   236  *
   237  * @param event			Handle to the event.
   238  * @param value			Buffer to store the name of the event.
   239  * @param maxlength		Maximum length of string buffer.
   240  * @noreturn
   241  * @error				Invalid or corrupt Handle.     
   242  */
   243 native GetEventName(Handle:event, String:name[], maxlength);
   244 
   245 /**
   246  * Sets whether an event's broadcasting will be disabled or not.
   247  *
   248  * This has no effect on events Handles that are not from HookEvent
   249  * or HookEventEx callbacks.
   250  *
   251  * @param event         Handle to an event from an event hook.
   252  * @param dontBroadcast True to disable broadcasting, false otherwise.
   253  * @noreturn
   254  * @error               Invalid Handle.
   255  */
   256 native SetEventBroadcast(Handle:event, bool:dontBroadcast);
   257