plugins/include/sourcemod.inc
author David Anderson <dvander@alliedmods.net>
Mon Jun 18 03:39:15 2007 +0000 (2007-06-18)
changeset 977 1dd1a7659ad4
parent 913 7c62d3c5d829
child 978 54782a83a1ef
permissions -rw-r--r--
fixed a bug where menu handler used wrong variable for param2 bitmask in MenuVoteEnd
     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 _sourcemod_included
    17  #endinput
    18 #endif
    19 #define _sourcemod_included
    20 
    21 /**
    22  * Plugin public information.
    23  */
    24 struct Plugin
    25 {
    26    const String:name[],			/**< Plugin Name */
    27    const String:description[],	/**< Plugin Description */
    28    const String:author[],		/**< Plugin Author */
    29    const String:version[],		/**< Plugin Version */
    30    const String:url[],			/**< Plugin URL */
    31 };
    32 
    33 #include <core>
    34 #include <float>
    35 #include <string>
    36 #include <handles>
    37 #include <functions>
    38 #include <files>
    39 #include <timers>
    40 #include <admin>
    41 #include <dbi>
    42 #include <lang>
    43 #include <sorting>
    44 #include <textparse>
    45 #include <clients>
    46 #include <console>
    47 #include <events>
    48 #include <bitbuffer>
    49 #include <usermessages>
    50 #include <keyvalues>
    51 #include <menus>
    52 #include <halflife>
    53 
    54 /**
    55  * Declare this as a struct in your plugin to expose its information.
    56  * Example:
    57  *
    58  * public Plugin:myinfo =
    59  * {
    60  *    name = "My Plugin",
    61  *    //etc
    62  * };
    63  */
    64 public Plugin:myinfo;
    65  
    66 /**
    67  * Called when the plugin is fully initialized and all known external references are resolved.
    68  * This is called even if the plugin type is "private."
    69  * @note Errors in this function will cause the plugin to stop running.
    70  *
    71  * @noreturn
    72  */
    73 forward OnPluginStart();
    74  
    75 /**
    76  *   Called before OnPluginStart, in case the plugin wants to check for load failure.
    77  * This is called even if the plugin type is "private."  Any natives from modules are 
    78  * not available at this point.  Thus, this forward should only be used for explicit 
    79  * pre-emptive things, such as adding dynamic natives, or setting certain types of load filters.
    80  * 
    81  * @note It is not safe to call externally resolved natives until OnPluginStart().
    82  * @note Any sort of RTE in this function will cause the plugin to fail loading.
    83  *
    84  * @param myself	Handle to the plugin.
    85  * @param late		Whether or not the plugin was loaded "late" (after map load).
    86  * @param error		Error message buffer in case load failed.
    87  * @param err_max	Maximum number of characters for error message buffer.
    88  * @return			True if load success, false otherwise.
    89  */
    90 forward bool:AskPluginLoad(Handle:myself, bool:late, String:error[], err_max);
    91 
    92 /**
    93  * Called when the plugin is about to be unloaded.
    94  *
    95  * @noreturn
    96  */
    97 forward OnPluginEnd();
    98 
    99 /**
   100  * Called when the plugin's pause status is changing.
   101  *
   102  * @param pause			True if the plugin is being paused, false otherwise.
   103  * @noreturn
   104  */
   105 forward OnPluginPauseChange(bool:pause);
   106 
   107 /**
   108  * Called before every server frame.  Note that you should avoid
   109  * doing expensive computations here, and you should declare large
   110  * local arrays using 'decl' instead of 'new'.
   111  */
   112 forward OnGameFrame();
   113 
   114 /**
   115  * Called when the map is loaded.
   116  *
   117  * @note This used to be OnServerLoad(), which is now deprecated.
   118  * Plugins still using the old forward will work.
   119  */
   120 forward OnMapStart();
   121 
   122 /**
   123  * Called right before a map ends.
   124  */
   125 forward OnMapEnd();
   126 
   127 /**
   128  * Called when the map has loaded and the servercfgfile has finished
   129  * executing.  This is usually 'server.cfg' but most mods allow it to
   130  * be set via 'servercfgfile'.  
   131  *
   132  * @note If server.cfg is executed more than once per map, this forward
   133  * will only be called the first time (per map).
   134  * @note It is not guaranteed that this will be called on all mods. If
   135  * a mod does not appear to support it, please file a SourceMod bug report.
   136  */
   137 forward OnServerCfg();
   138 
   139 /**
   140  * Returns the calling plugin's Handle.
   141  *
   142  * @return				Handle of the calling plugin.
   143  */
   144 native Handle:GetMyHandle();
   145 
   146 /**
   147  * Returns an iterator that can be used to search through plugins.
   148  *
   149  * @return				Handle to iterate with.  Must be closed via 
   150  * 						CloseHandle().
   151  * @error				Invalid Handle.
   152  */
   153 native Handle:GetPluginIterator();
   154 
   155 /**
   156  * Returns whether there are more plugins available in the iterator.
   157  *
   158  * @param iter			Handle to the plugin iterator.
   159  * @return				True on more plugins, false otherwise.
   160  * @error				Invalid Handle.
   161  */
   162 native bool:MorePlugins(Handle:iter);
   163 
   164 /**
   165  * Returns the current plugin in the iterator and advances the iterator.
   166  *
   167  * @param iter			Handle to the plugin iterator.
   168  * @return				Current plugin the iterator is at, before
   169  *						the iterator is advanced.
   170  * @error				Invalid Handle.
   171  */
   172 native Handle:ReadPlugin(Handle:iter);
   173 
   174 /**
   175  * Returns a plugin's status.
   176  *
   177  * @param plugin		Plugin Handle (INVALID_HANDLE uses the calling plugin).
   178  * @return				Status code for the plugin.
   179  * @error				Invalid Handle.
   180  */
   181 native PluginStatus:GetPluginStatus(Handle:plugin);
   182 
   183 /**
   184  * Retrieves a plugin's file name relative to the plugins folder.
   185  *
   186  * @param plugin		Plugin Handle (INVALID_HANDLE uses the calling plugin).
   187  * @param buffer		Buffer to the store the file name.
   188  * @param maxlength		Maximum length of the name buffer.
   189  * @noreturn
   190  * @error				Invalid Handle.
   191  */
   192 native GetPluginFilename(Handle:plugin, String:buffer[], maxlength);
   193 
   194 /**
   195  * Retrieves whether or not a plugin is being debugged.
   196  *
   197  * @param plugin		Plugin Handle (INVALID_HANDLE uses the calling plugin).
   198  * @return				True if being debugged, false otherwise.
   199  * @error				Invalid Handle.
   200  */
   201 native bool:IsPluginDebugging(Handle:hndl);
   202 
   203 /**
   204  * Retrieves a plugin's public info.
   205  *
   206  * @param plugin		Plugin Handle (INVALID_HANDLE uses the calling plugin).
   207  * @param info			Plugin info property to retrieve.
   208  * @param buffer		Buffer to store info in.
   209  * @param maxlength		Maximum length of buffer.
   210  * @return				True on success, false if property is not available.
   211  * @error				Invalid Handle.
   212  */
   213 native bool:GetPluginInfo(Handle:plugin, PluginInfo:info, String:buffer[], maxlength);
   214 
   215 /**
   216  * Causes the plugin to enter a failed state.  An error will be thrown and
   217  * the plugin will be paused until it is unloaded or reloaded.
   218  *
   219  * @param string		Message to print.
   220  * @noreturn
   221  * @error				Always throws SP_ERROR_ABORT.
   222  */
   223 native SetFailState(const String:string[]);
   224 
   225 /**
   226  * Aborts the current callback and throws an error.  This function
   227  * does not return in that no code is executed following it.
   228  *
   229  * @param format		String format.
   230  * @param ...			Format arguments.
   231  * @noreturn
   232  * @error				Always!
   233  */
   234 native ThrowError(const String:fmt[], any:...);
   235 
   236 /**
   237  * Logs a plugin message to the SourceMod logs.
   238  *
   239  * @param format		String format.
   240  * @param ...			Format arguments.
   241  * @noreturn
   242  */
   243 native LogMessage(const String:format[], any:...);
   244 
   245 /**
   246  * Logs a plugin error message to the SourceMod logs.
   247  *
   248  * @param format		String format.
   249  * @param ...			Format arguments.
   250  * @noreturn
   251  */
   252 native LogError(const String:format[], any:...);
   253 
   254 /**
   255  * Gets the system time as a unix timestamp.
   256  *
   257  * @param bigStamp		Optional array to store the 64bit timestamp in.
   258  * @return				32bit timestamp (number of seconds since unix epoch).
   259  */
   260 native GetTime(bigStamp[2]={0,0});
   261 
   262 /**
   263  * Loads a game config file.
   264  *
   265  * @param file			File to load.  The path must be relative to the 'gamedata' folder under the config folder 
   266  *					and the extension should be omitted.
   267  * @return			A handle to the game config file or INVALID_HANDLE in failure.
   268  */
   269 native Handle:LoadGameConfigFile(const String:file[]);
   270 
   271 /**
   272  * Returns an offset value.
   273  *
   274  * @param gc			Game config handle.
   275  * @param key			Key to retrieve from the offset section.
   276  * @return			An offset, or -1 on failure.
   277  */
   278 native GameConfGetOffset(Handle:gc, const String:key[]);
   279 
   280 /**
   281  * Gets the value of a key from the "Keys" section.
   282  *
   283  * @param gc			Game config handle.
   284  * @param key			Key to retrieve from the Keys section.
   285  * @param buffer		Destination string buffer.
   286  * @param maxlen		Maximum length of output string buffer.
   287  * @return				True if key existed, false otherwise.
   288  */
   289 native bool:GameConfGetKeyValue(Handle:gc, const String:key[], String:buffer[], maxlen);
   290 
   291 /**
   292  * Returns the operating system's "tick count," which is a number of 
   293  * milliseconds since the operating system loaded.  This can be used
   294  * for basic benchmarks.
   295  *
   296  * @return				Tick count in milliseconds.
   297  */
   298 native GetSysTickCount();
   299 
   300 #include <helpers>
   301 #include <entity>