plugins/include/events.inc
author David Anderson <dvander@alliedmods.net>
Mon May 07 02:58:58 2007 +0000 (2007-05-07)
changeset 753 41f5156d0e63
parent 713 7a8ac1106ace
child 801 712a6e20b3e1
permissions -rw-r--r--
small rewrite of how keyvalues iterator and get deleted. phew!
     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  * Removes 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  * @noreturn
    76  * @error				Invalid callback function or no active hook for specified event.
    77  */
    78 native UnhookEvent(const String:name[], EventHook:callback, EventHookMode:mode=EventHookMode_Post);
    79 
    80 /**
    81  * Creates a game event to be fired later.
    82  *
    83  * @param name			Name of event.
    84  * @param force			If set to true, this forces the event to be created even if it's not being hooked.
    85  *						Note that this will not force it if the event doesn't exist at all.
    86  * @return				Handle to event. INVALID_HANDLE is returned if the event doesn't exist or isn't 
    87 						being hooked (unless force is true).
    88  */
    89 native Handle:CreateEvent(const String:name[], bool:force=false);
    90 
    91 /**
    92  * Fires a game event.
    93  *
    94  * @param event			Handle to the event.
    95  * @param dontBroadcast	Optional boolean that determines if event should be broadcast to clients.
    96  * @noreturn
    97  * @error				Invalid or corrupt Handle.
    98  */
    99 native FireEvent(Handle:event, bool:dontBroadcast=false);
   100 
   101 /**
   102  * Cancels a previously created game event that has not been fired.
   103  *
   104  * @param event			Handled to the event.
   105  * @noreturn
   106  * @error				Invalid or corrupt Handle.
   107  */
   108 native CancelCreatedEvent(Handle:event);
   109 
   110 /**
   111  * Returns the boolean value of a game event's key.
   112  *
   113  * @param event			Handle to the event.
   114  * @param key			Name of event key.
   115  * @return				The boolean value of the specfied event key.
   116  * @error				Invalid or corrupt Handle.
   117  */
   118 native bool:GetEventBool(Handle:event, const String:key[]);
   119 
   120 /**
   121  * Sets the boolean value of a game event's key.
   122  *
   123  * @param event			Handle to the event.
   124  * @param key			Name of event key.
   125  * @param value			New boolean value.
   126  * @noreturn
   127  * @error				Invalid or corrupt Handle.
   128  */
   129 native SetEventBool(Handle:event, const String:key[], bool:value);
   130 
   131 /**
   132  * Returns the integer value of a game event's key.
   133  *
   134  * @param event			Handle to the event.
   135  * @param key			Name of event key.
   136  * @return				The integer value of the specfied event key.
   137  * @error				Invalid or corrupt Handle.
   138  */
   139 native GetEventInt(Handle:event, const String:key[]);
   140 
   141 /**
   142  * Sets the integer value of a game event's key.
   143  *
   144  * @param event			Handle to the event.
   145  * @param key			Name of event key.
   146  * @param value			New integer value.
   147  * @noreturn
   148  * @error				Invalid or corrupt Handle.
   149  */
   150 native SetEventInt(Handle:event, const String:key[], value);
   151 
   152 /**
   153  * Returns the floating point value of a game event's key.
   154  *
   155  * @param event			Handle to the event.
   156  * @param key			Name of event key.
   157  * @return				The floating point value of the specfied event key.
   158  * @error				Invalid or corrupt Handle.
   159  */
   160 native Float:GetEventFloat(Handle:event, const String:key[]);
   161 
   162 /**
   163  * Sets the floating point value of a game event's key.
   164  *
   165  * @param event			Handle to the event.
   166  * @param key			Name of event key.
   167  * @param value			New floating point value.
   168  * @noreturn
   169  * @error				Invalid or corrupt Handle.
   170  */
   171 native SetEventFloat(Handle:event, const String:key[], Float:value);
   172 
   173 /**
   174  * Retrieves the string 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			Buffer to store the value of the specified event key.
   179  * @param maxlength		Maximum length of string buffer.
   180  * @noreturn
   181  * @error				Invalid or corrupt Handle.
   182  */
   183 native GetEventString(Handle:event, const String:key[], String:value[], maxlength);
   184 
   185 /**
   186  * Sets the string value of a game event's key.
   187  *
   188  * @param event			Handle to the event.
   189  * @param key			Name of event key.
   190  * @param value			New string value.
   191  * @noreturn
   192  * @error				Invalid or corrupt Handle.
   193  */
   194 native SetEventString(Handle:event, const String:key[], const String:value[]);
   195 
   196 /**
   197  * Retrieves the name of a game event.
   198  *
   199  * @param event			Handle to the event.
   200  * @param value			Buffer to store the name of the event.
   201  * @param maxlength		Maximum length of string buffer.
   202  * @noreturn
   203  * @error				Invalid or corrupt Handle.     
   204  */
   205 native GetEventName(Handle:event, String:name[], maxlength);