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