plugins/include/sourcemod.inc
author Scott Ehlert <ds@alliedmods.net>
Fri Jun 22 15:37:12 2007 +0000 (2007-06-22)
changeset 1001 8de56a71f200
parent 979 083adc349611
child 1037 86af3790fcb7
permissions -rw-r--r--
Implemented amb423 - Added IsClientObserver() native
     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, servercfgfile (server.cfg) has been 
   129  * executed, and all plugin configs are done executing.  This is the best
   130  * place to inialize plugin functions which are based on cvar data.  
   131  *
   132  * @note This will always be called once and only once per map.  It will be 
   133  * called after OnMapStart().
   134  *
   135  * @noreturn
   136  */
   137 forward OnConfigsExecuted();
   138 
   139 /**
   140  * @deprecated Use OnConfigsExecuted() instead.
   141  */
   142 forward OnServerCfg();
   143 
   144 /**
   145  * Returns the calling plugin's Handle.
   146  *
   147  * @return				Handle of the calling plugin.
   148  */
   149 native Handle:GetMyHandle();
   150 
   151 /**
   152  * Returns an iterator that can be used to search through plugins.
   153  *
   154  * @return				Handle to iterate with.  Must be closed via 
   155  * 						CloseHandle().
   156  * @error				Invalid Handle.
   157  */
   158 native Handle:GetPluginIterator();
   159 
   160 /**
   161  * Returns whether there are more plugins available in the iterator.
   162  *
   163  * @param iter			Handle to the plugin iterator.
   164  * @return				True on more plugins, false otherwise.
   165  * @error				Invalid Handle.
   166  */
   167 native bool:MorePlugins(Handle:iter);
   168 
   169 /**
   170  * Returns the current plugin in the iterator and advances the iterator.
   171  *
   172  * @param iter			Handle to the plugin iterator.
   173  * @return				Current plugin the iterator is at, before
   174  *						the iterator is advanced.
   175  * @error				Invalid Handle.
   176  */
   177 native Handle:ReadPlugin(Handle:iter);
   178 
   179 /**
   180  * Returns a plugin's status.
   181  *
   182  * @param plugin		Plugin Handle (INVALID_HANDLE uses the calling plugin).
   183  * @return				Status code for the plugin.
   184  * @error				Invalid Handle.
   185  */
   186 native PluginStatus:GetPluginStatus(Handle:plugin);
   187 
   188 /**
   189  * Retrieves a plugin's file name relative to the plugins folder.
   190  *
   191  * @param plugin		Plugin Handle (INVALID_HANDLE uses the calling plugin).
   192  * @param buffer		Buffer to the store the file name.
   193  * @param maxlength		Maximum length of the name buffer.
   194  * @noreturn
   195  * @error				Invalid Handle.
   196  */
   197 native GetPluginFilename(Handle:plugin, String:buffer[], maxlength);
   198 
   199 /**
   200  * Retrieves whether or not a plugin is being debugged.
   201  *
   202  * @param plugin		Plugin Handle (INVALID_HANDLE uses the calling plugin).
   203  * @return				True if being debugged, false otherwise.
   204  * @error				Invalid Handle.
   205  */
   206 native bool:IsPluginDebugging(Handle:hndl);
   207 
   208 /**
   209  * Retrieves a plugin's public info.
   210  *
   211  * @param plugin		Plugin Handle (INVALID_HANDLE uses the calling plugin).
   212  * @param info			Plugin info property to retrieve.
   213  * @param buffer		Buffer to store info in.
   214  * @param maxlength		Maximum length of buffer.
   215  * @return				True on success, false if property is not available.
   216  * @error				Invalid Handle.
   217  */
   218 native bool:GetPluginInfo(Handle:plugin, PluginInfo:info, String:buffer[], maxlength);
   219 
   220 /**
   221  * Causes the plugin to enter a failed state.  An error will be thrown and
   222  * the plugin will be paused until it is unloaded or reloaded.
   223  *
   224  * @param string		Message to print.
   225  * @noreturn
   226  * @error				Always throws SP_ERROR_ABORT.
   227  */
   228 native SetFailState(const String:string[]);
   229 
   230 /**
   231  * Aborts the current callback and throws an error.  This function
   232  * does not return in that no code is executed following it.
   233  *
   234  * @param format		String format.
   235  * @param ...			Format arguments.
   236  * @noreturn
   237  * @error				Always!
   238  */
   239 native ThrowError(const String:fmt[], any:...);
   240 
   241 /**
   242  * Logs a plugin message to the SourceMod logs.
   243  *
   244  * @param format		String format.
   245  * @param ...			Format arguments.
   246  * @noreturn
   247  */
   248 native LogMessage(const String:format[], any:...);
   249 
   250 /**
   251  * Logs a plugin error message to the SourceMod logs.
   252  *
   253  * @param format		String format.
   254  * @param ...			Format arguments.
   255  * @noreturn
   256  */
   257 native LogError(const String:format[], any:...);
   258 
   259 /**
   260  * Gets the system time as a unix timestamp.
   261  *
   262  * @param bigStamp		Optional array to store the 64bit timestamp in.
   263  * @return				32bit timestamp (number of seconds since unix epoch).
   264  */
   265 native GetTime(bigStamp[2]={0,0});
   266 
   267 /**
   268  * Loads a game config file.
   269  *
   270  * @param file			File to load.  The path must be relative to the 'gamedata' folder under the config folder 
   271  *					and the extension should be omitted.
   272  * @return			A handle to the game config file or INVALID_HANDLE in failure.
   273  */
   274 native Handle:LoadGameConfigFile(const String:file[]);
   275 
   276 /**
   277  * Returns an offset value.
   278  *
   279  * @param gc			Game config handle.
   280  * @param key			Key to retrieve from the offset section.
   281  * @return			An offset, or -1 on failure.
   282  */
   283 native GameConfGetOffset(Handle:gc, const String:key[]);
   284 
   285 /**
   286  * Gets the value of a key from the "Keys" section.
   287  *
   288  * @param gc			Game config handle.
   289  * @param key			Key to retrieve from the Keys section.
   290  * @param buffer		Destination string buffer.
   291  * @param maxlen		Maximum length of output string buffer.
   292  * @return				True if key existed, false otherwise.
   293  */
   294 native bool:GameConfGetKeyValue(Handle:gc, const String:key[], String:buffer[], maxlen);
   295 
   296 /**
   297  * Returns the operating system's "tick count," which is a number of 
   298  * milliseconds since the operating system loaded.  This can be used
   299  * for basic benchmarks.
   300  *
   301  * @return				Tick count in milliseconds.
   302  */
   303 native GetSysTickCount();
   304 
   305 /**
   306  * Specifies that the given config file should be executed after plugin load.
   307  * OnConfigsExecuted() will not be called until the config file has executed, 
   308  * but it will be called if the execution fails.
   309  *
   310  * @param autoCreate	If true, and the config file does not exist, such a config
   311  *						file will be automatically created and populated with
   312  *						information from the plugin's registered cvars.
   313  * @param name			Name of the config file, excluding the .cfg extension.
   314  *						If empty, <plugin.filename.cfg> is assumed.
   315  * @param folder		Folder under cfg/ to use.  By default this is "sourcemod."
   316  * @noreturn
   317  */
   318 native AutoExecConfig(bool:autoCreate=true, const String:name[]="", const String:folder[]="sourcemod");
   319 
   320 #include <helpers>
   321 #include <entity>