plugins/include/events.inc
author Scott Ehlert <ds@alliedmods.net>
Thu Jun 07 07:36:41 2007 +0000 (2007-06-07)
changeset 915 62c6fb7c533b
parent 801 712a6e20b3e1
child 1330 ab94316bb52b
permissions -rw-r--r--
Whoa, bug. Hopefully fixed PrintToChatAll and PrintCenterTextAll once and for all...
     1 /**
     2  * vim: set ts=4 :
     3  * ===============================================================
     4  * SourceMod (C)2004-2007 AlliedModders LLC.  All rights reserved.
     5  * ===============================================================
     6  *
     7  *  This file is part of the SourceMod/SourcePawn SDK.  This file may only be used 
     8  * or modified under the Terms and Conditions of its License Agreement, which is found 
     9  * in LICENSE.txt.  The Terms and Conditions for making SourceMod extensions/plugins 
    10  * may change at any time.  To view the latest information, see:
    11  *   http://www.sourcemod.net/license.php
    12  *
    13  * Version: $Id$
    14  */
    15  
    16 #if defined _events_included
    17  #endinput
    18 #endif
    19 #define _events_included
    20 
    21 /**
    22  * Event hook modes determining how hooking should be handled
    23  */
    24 enum EventHookMode
    25 {
    26 	EventHookMode_Pre,					/**< Hook callback fired before event is fired */
    27 	EventHookMode_Post,					/**< Hook callback fired after event is fired */
    28 	EventHookMode_PostNoCopy			/**< Hook callback fired after event is fired, but event data won't be copied */
    29 };
    30 
    31 /**
    32  * Hook function types for events.
    33  */
    34 funcenum EventHook
    35 {
    36 	/**
    37 	 * Called when a game event is fired.
    38 	 *
    39 	 * @param event			Handle to event. This could be INVALID_HANDLE if every plugin hooking 
    40 	 *						this event has set the hook mode EventHookMode_PostNoCopy.
    41 	 * @param name			String containing the name of the event.
    42 	 * @param dontBroadcast	True if event was not broadcast to clients, false otherwise.
    43 	 * @return				Ignored for post hooks. Plugin_Handled will block event if hooked as pre.
    44 	 */
    45 	Action:public(Handle:event, const String:name[], bool:dontBroadcast),
    46 	/**
    47 	 * Called when a game event is fired.
    48 	 *
    49 	 * @param event			Handle to event. This could be INVALID_HANDLE if every plugin hooking 
    50 	 *						this event has set the hook mode EventHookMode_PostNoCopy.
    51 	 * @param name			String containing the name of the event.
    52 	 * @param dontBroadcast	True if event was not broadcast to clients, false otherwise.
    53 	 * @noreturn
    54 	 */
    55 	public(Handle:event, const String:name[], bool:dontBroadcast),
    56 };
    57 
    58 /**
    59  * Creates a hook for when a game event is fired.
    60  *
    61  * @param name			Name of event.
    62  * @param callback		An EventHook function pointer.
    63  * @param mode			Optional EventHookMode determining the type of hook.
    64  * @noreturn
    65  * @error				Invalid event name or invalid callback function.
    66  */
    67 native HookEvent(const String:name[], EventHook:callback, EventHookMode:mode=EventHookMode_Post);
    68 
    69 /**
    70  * Creates a hook for when a game event is fired.
    71  *
    72  * @param name			Name of event.
    73  * @param callback		An EventHook function pointer.
    74  * @param mode			Optional EventHookMode determining the type of hook.
    75  * @return				True if event exists and was hooked successfully, false otherwise.
    76  * @error				Invalid callback function.
    77  */
    78 native bool:HookEventEx(const String:name[], EventHook:callback, EventHookMode:mode=EventHookMode_Post);
    79 
    80 /**
    81  * Removes a hook for when a game event is fired.
    82  *
    83  * @param name			Name of event.
    84  * @param callback		An EventHook function pointer.
    85  * @param mode			Optional EventHookMode determining the type of hook.
    86  * @noreturn
    87  * @error				Invalid callback function or no active hook for specified event.
    88  */
    89 native UnhookEvent(const String:name[], EventHook:callback, EventHookMode:mode=EventHookMode_Post);
    90 
    91 /**
    92  * Creates a game event to be fired later.
    93  *
    94  * @param name			Name of event.
    95  * @param force			If set to true, this forces the event to be created even if it's not being hooked.
    96  *						Note that this will not force it if the event doesn't exist at all.
    97  * @return				Handle to event. INVALID_HANDLE is returned if the event doesn't exist or isn't 
    98 						being hooked (unless force is true).
    99  */
   100 native Handle:CreateEvent(const String:name[], bool:force=false);
   101 
   102 /**
   103  * Fires a game event.
   104  *
   105  * @param event			Handle to the event.
   106  * @param dontBroadcast	Optional boolean that determines if event should be broadcast to clients.
   107  * @noreturn
   108  * @error				Invalid or corrupt Handle.
   109  */
   110 native FireEvent(Handle:event, bool:dontBroadcast=false);
   111 
   112 /**
   113  * Cancels a previously created game event that has not been fired.
   114  *
   115  * @param event			Handled to the event.
   116  * @noreturn
   117  * @error				Invalid or corrupt Handle.
   118  */
   119 native CancelCreatedEvent(Handle:event);
   120 
   121 /**
   122  * Returns the boolean value of a game event's key.
   123  *
   124  * @param event			Handle to the event.
   125  * @param key			Name of event key.
   126  * @return				The boolean value of the specfied event key.
   127  * @error				Invalid or corrupt Handle.
   128  */
   129 native bool:GetEventBool(Handle:event, const String:key[]);
   130 
   131 /**
   132  * Sets the boolean value of a game event's key.
   133  *
   134  * @param event			Handle to the event.
   135  * @param key			Name of event key.
   136  * @param value			New boolean value.
   137  * @noreturn
   138  * @error				Invalid or corrupt Handle.
   139  */
   140 native SetEventBool(Handle:event, const String:key[], bool:value);
   141 
   142 /**
   143  * Returns the integer value of a game event's key.
   144  *
   145  * @param event			Handle to the event.
   146  * @param key			Name of event key.
   147  * @return				The integer value of the specfied event key.
   148  * @error				Invalid or corrupt Handle.
   149  */
   150 native GetEventInt(Handle:event, const String:key[]);
   151 
   152 /**
   153  * Sets the integer value of a game event's key.
   154  *
   155  * @param event			Handle to the event.
   156  * @param key			Name of event key.
   157  * @param value			New integer value.
   158  * @noreturn
   159  * @error				Invalid or corrupt Handle.
   160  */
   161 native SetEventInt(Handle:event, const String:key[], value);
   162 
   163 /**
   164  * Returns the floating point value of a game event's key.
   165  *
   166  * @param event			Handle to the event.
   167  * @param key			Name of event key.
   168  * @return				The floating point value of the specfied event key.
   169  * @error				Invalid or corrupt Handle.
   170  */
   171 native Float:GetEventFloat(Handle:event, const String:key[]);
   172 
   173 /**
   174  * Sets the floating point value of a game event's key.
   175  *
   176  * @param event			Handle to the event.
   177  * @param key			Name of event key.
   178  * @param value			New floating point value.
   179  * @noreturn
   180  * @error				Invalid or corrupt Handle.
   181  */
   182 native SetEventFloat(Handle:event, const String:key[], Float:value);
   183 
   184 /**
   185  * Retrieves the string value of a game event's key.
   186  *
   187  * @param event			Handle to the event.
   188  * @param key			Name of event key.
   189  * @param value			Buffer to store the value of the specified event key.
   190  * @param maxlength		Maximum length of string buffer.
   191  * @noreturn
   192  * @error				Invalid or corrupt Handle.
   193  */
   194 native GetEventString(Handle:event, const String:key[], String:value[], maxlength);
   195 
   196 /**
   197  * Sets the string value of a game event's key.
   198  *
   199  * @param event			Handle to the event.
   200  * @param key			Name of event key.
   201  * @param value			New string value.
   202  * @noreturn
   203  * @error				Invalid or corrupt Handle.
   204  */
   205 native SetEventString(Handle:event, const String:key[], const String:value[]);
   206 
   207 /**
   208  * Retrieves the name of a game event.
   209  *
   210  * @param event			Handle to the event.
   211  * @param value			Buffer to store the name of the event.
   212  * @param maxlength		Maximum length of string buffer.
   213  * @noreturn
   214  * @error				Invalid or corrupt Handle.     
   215  */
   216 native GetEventName(Handle:event, String:name[], maxlength);