plugins/include/events.inc
author David Anderson <dvander@alliedmods.net>
Sun Nov 25 18:50:13 2007 +0000 (2007-11-25)
changeset 1725 ea875bcbc286
parent 1330 ab94316bb52b
child 1851 d5054314db8e
permissions -rw-r--r--
small clarification to param2 in MenuAction_End
     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.
     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  * @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).
   116  */
   117 native Handle:CreateEvent(const String:name[], bool:force=false);
   118 
   119 /**
   120  * Fires a game event.
   121  *
   122  * @param event			Handle to the event.
   123  * @param dontBroadcast	Optional boolean that determines if event should be broadcast to clients.
   124  * @noreturn
   125  * @error				Invalid or corrupt Handle.
   126  */
   127 native FireEvent(Handle:event, bool:dontBroadcast=false);
   128 
   129 /**
   130  * Cancels a previously created game event that has not been fired.
   131  *
   132  * @param event			Handled to the event.
   133  * @noreturn
   134  * @error				Invalid or corrupt Handle.
   135  */
   136 native CancelCreatedEvent(Handle:event);
   137 
   138 /**
   139  * Returns the boolean value of a game event's key.
   140  *
   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.
   145  */
   146 native bool:GetEventBool(Handle:event, const String:key[]);
   147 
   148 /**
   149  * Sets the boolean value of a game event's key.
   150  *
   151  * @param event			Handle to the event.
   152  * @param key			Name of event key.
   153  * @param value			New boolean value.
   154  * @noreturn
   155  * @error				Invalid or corrupt Handle.
   156  */
   157 native SetEventBool(Handle:event, const String:key[], bool:value);
   158 
   159 /**
   160  * Returns the integer value of a game event's key.
   161  *
   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.
   166  */
   167 native GetEventInt(Handle:event, const String:key[]);
   168 
   169 /**
   170  * Sets the integer value of a game event's key.
   171  *
   172  * @param event			Handle to the event.
   173  * @param key			Name of event key.
   174  * @param value			New integer value.
   175  * @noreturn
   176  * @error				Invalid or corrupt Handle.
   177  */
   178 native SetEventInt(Handle:event, const String:key[], value);
   179 
   180 /**
   181  * Returns the floating point value of a game event's key.
   182  *
   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.
   187  */
   188 native Float:GetEventFloat(Handle:event, const String:key[]);
   189 
   190 /**
   191  * Sets 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  * @param value			New floating point value.
   196  * @noreturn
   197  * @error				Invalid or corrupt Handle.
   198  */
   199 native SetEventFloat(Handle:event, const String:key[], Float:value);
   200 
   201 /**
   202  * Retrieves the string value of a game event's key.
   203  *
   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.
   208  * @noreturn
   209  * @error				Invalid or corrupt Handle.
   210  */
   211 native GetEventString(Handle:event, const String:key[], String:value[], maxlength);
   212 
   213 /**
   214  * Sets the string value of a game event's key.
   215  *
   216  * @param event			Handle to the event.
   217  * @param key			Name of event key.
   218  * @param value			New string value.
   219  * @noreturn
   220  * @error				Invalid or corrupt Handle.
   221  */
   222 native SetEventString(Handle:event, const String:key[], const String:value[]);
   223 
   224 /**
   225  * Retrieves the name of a game event.
   226  *
   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.
   230  * @noreturn
   231  * @error				Invalid or corrupt Handle.     
   232  */
   233 native GetEventName(Handle:event, String:name[], maxlength);