plugins/include/sourcemod.inc
author David Anderson <dvander@alliedmods.net>
Tue Jul 24 01:18:28 2007 +0000 (2007-07-24)
changeset 1156 a80f4ebe389f
parent 1124 a397d51fb986
child 1221 f2dc55c0ab6f
permissions -rw-r--r--
initial import of adt array natives for amb576
     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 <vector>
    36 #include <string>
    37 #include <handles>
    38 #include <functions>
    39 #include <files>
    40 #include <timers>
    41 #include <admin>
    42 #include <dbi>
    43 #include <lang>
    44 #include <sorting>
    45 #include <textparse>
    46 #include <clients>
    47 #include <console>
    48 #include <events>
    49 #include <bitbuffer>
    50 #include <usermessages>
    51 #include <keyvalues>
    52 #include <menus>
    53 #include <halflife>
    54 #include <adt>
    55 
    56 /**
    57  * Declare this as a struct in your plugin to expose its information.
    58  * Example:
    59  *
    60  * public Plugin:myinfo =
    61  * {
    62  *    name = "My Plugin",
    63  *    //etc
    64  * };
    65  */
    66 public Plugin:myinfo;
    67  
    68 /**
    69  * Called when the plugin is fully initialized and all known external references are resolved.
    70  * This is called even if the plugin type is "private."
    71  * @note Errors in this function will cause the plugin to stop running.
    72  *
    73  * @noreturn
    74  */
    75 forward OnPluginStart();
    76  
    77 /**
    78  * Called before OnPluginStart, in case the plugin wants to check for load failure.
    79  * This is called even if the plugin type is "private."  Any natives from modules are 
    80  * not available at this point.  Thus, this forward should only be used for explicit 
    81  * pre-emptive things, such as adding dynamic natives, or setting certain types of load filters.
    82  * 
    83  * @note It is not safe to call externally resolved natives until OnPluginStart().
    84  * @note Any sort of RTE in this function will cause the plugin to fail loading.
    85  *
    86  * @param myself	Handle to the plugin.
    87  * @param late		Whether or not the plugin was loaded "late" (after map load).
    88  * @param error		Error message buffer in case load failed.
    89  * @param err_max	Maximum number of characters for error message buffer.
    90  * @return			True if load success, false otherwise.
    91  */
    92 forward bool:AskPluginLoad(Handle:myself, bool:late, String:error[], err_max);
    93 
    94 /**
    95  * Called when the plugin is about to be unloaded.
    96  *
    97  * @noreturn
    98  */
    99 forward OnPluginEnd();
   100 
   101 /**
   102  * Called when the plugin's pause status is changing.
   103  *
   104  * @param pause			True if the plugin is being paused, false otherwise.
   105  * @noreturn
   106  */
   107 forward OnPluginPauseChange(bool:pause);
   108 
   109 /**
   110  * Called before every server frame.  Note that you should avoid
   111  * doing expensive computations here, and you should declare large
   112  * local arrays using 'decl' instead of 'new'.
   113  */
   114 forward OnGameFrame();
   115 
   116 /**
   117  * Called when the map is loaded.
   118  *
   119  * @note This used to be OnServerLoad(), which is now deprecated.
   120  * Plugins still using the old forward will work.
   121  */
   122 forward OnMapStart();
   123 
   124 /**
   125  * Called right before a map ends.
   126  */
   127 forward OnMapEnd();
   128 
   129 /**
   130  * Called when the map has loaded, servercfgfile (server.cfg) has been 
   131  * executed, and all plugin configs are done executing.  This is the best
   132  * place to inialize plugin functions which are based on cvar data.  
   133  *
   134  * @note This will always be called once and only once per map.  It will be 
   135  * called after OnMapStart().
   136  *
   137  * @noreturn
   138  */
   139 forward OnConfigsExecuted();
   140 
   141 /**
   142  * @deprecated Use OnConfigsExecuted() instead.
   143  */
   144 forward OnServerCfg();
   145 
   146 /**
   147  * Returns the calling plugin's Handle.
   148  *
   149  * @return				Handle of the calling plugin.
   150  */
   151 native Handle:GetMyHandle();
   152 
   153 /**
   154  * Returns an iterator that can be used to search through plugins.
   155  *
   156  * @return				Handle to iterate with.  Must be closed via 
   157  * 						CloseHandle().
   158  * @error				Invalid Handle.
   159  */
   160 native Handle:GetPluginIterator();
   161 
   162 /**
   163  * Returns whether there are more plugins available in the iterator.
   164  *
   165  * @param iter			Handle to the plugin iterator.
   166  * @return				True on more plugins, false otherwise.
   167  * @error				Invalid Handle.
   168  */
   169 native bool:MorePlugins(Handle:iter);
   170 
   171 /**
   172  * Returns the current plugin in the iterator and advances the iterator.
   173  *
   174  * @param iter			Handle to the plugin iterator.
   175  * @return				Current plugin the iterator is at, before
   176  *						the iterator is advanced.
   177  * @error				Invalid Handle.
   178  */
   179 native Handle:ReadPlugin(Handle:iter);
   180 
   181 /**
   182  * Returns a plugin's status.
   183  *
   184  * @param plugin		Plugin Handle (INVALID_HANDLE uses the calling plugin).
   185  * @return				Status code for the plugin.
   186  * @error				Invalid Handle.
   187  */
   188 native PluginStatus:GetPluginStatus(Handle:plugin);
   189 
   190 /**
   191  * Retrieves a plugin's file name relative to the plugins folder.
   192  *
   193  * @param plugin		Plugin Handle (INVALID_HANDLE uses the calling plugin).
   194  * @param buffer		Buffer to the store the file name.
   195  * @param maxlength		Maximum length of the name buffer.
   196  * @noreturn
   197  * @error				Invalid Handle.
   198  */
   199 native GetPluginFilename(Handle:plugin, String:buffer[], maxlength);
   200 
   201 /**
   202  * Retrieves whether or not a plugin is being debugged.
   203  *
   204  * @param plugin		Plugin Handle (INVALID_HANDLE uses the calling plugin).
   205  * @return				True if being debugged, false otherwise.
   206  * @error				Invalid Handle.
   207  */
   208 native bool:IsPluginDebugging(Handle:hndl);
   209 
   210 /**
   211  * Retrieves a plugin's public info.
   212  *
   213  * @param plugin		Plugin Handle (INVALID_HANDLE uses the calling plugin).
   214  * @param info			Plugin info property to retrieve.
   215  * @param buffer		Buffer to store info in.
   216  * @param maxlength		Maximum length of buffer.
   217  * @return				True on success, false if property is not available.
   218  * @error				Invalid Handle.
   219  */
   220 native bool:GetPluginInfo(Handle:plugin, PluginInfo:info, String:buffer[], maxlength);
   221 
   222 /**
   223  * Causes the plugin to enter a failed state.  An error will be thrown and
   224  * the plugin will be paused until it is unloaded or reloaded.
   225  *
   226  * @param string		Message to print.
   227  * @noreturn
   228  * @error				Always throws SP_ERROR_ABORT.
   229  */
   230 native SetFailState(const String:string[]);
   231 
   232 /**
   233  * Aborts the current callback and throws an error.  This function
   234  * does not return in that no code is executed following it.
   235  *
   236  * @param format		String format.
   237  * @param ...			Format arguments.
   238  * @noreturn
   239  * @error				Always!
   240  */
   241 native ThrowError(const String:fmt[], any:...);
   242 
   243 /**
   244  * Logs a plugin message to the SourceMod logs.
   245  *
   246  * @param format		String format.
   247  * @param ...			Format arguments.
   248  * @noreturn
   249  */
   250 native LogMessage(const String:format[], any:...);
   251 
   252 /**
   253  * Logs a plugin error message to the SourceMod logs.
   254  *
   255  * @param format		String format.
   256  * @param ...			Format arguments.
   257  * @noreturn
   258  */
   259 native LogError(const String:format[], any:...);
   260 
   261 /**
   262  * Gets the system time as a unix timestamp.
   263  *
   264  * @param bigStamp		Optional array to store the 64bit timestamp in.
   265  * @return				32bit timestamp (number of seconds since unix epoch).
   266  */
   267 native GetTime(bigStamp[2]={0,0});
   268 
   269 /**
   270  * Format date and time.
   271  *
   272  * @param buffer		Destination string buffer.
   273  * @param maxlength		Maximum length of output string buffer.
   274  * @param format		Formatting rules.
   275  * @param stamp			Optional time stamp.
   276  * @noreturn
   277  */
   278 native FormatTime(String:buffer[], maxlength, const String:format[], stamp=-1);
   279 
   280 /**
   281  * Loads a game config file.
   282  *
   283  * @param file			File to load.  The path must be relative to the 'gamedata' folder under the config folder 
   284  *					and the extension should be omitted.
   285  * @return			A handle to the game config file or INVALID_HANDLE in failure.
   286  */
   287 native Handle:LoadGameConfigFile(const String:file[]);
   288 
   289 /**
   290  * Returns an offset value.
   291  *
   292  * @param gc			Game config handle.
   293  * @param key			Key to retrieve from the offset section.
   294  * @return			An offset, or -1 on failure.
   295  */
   296 native GameConfGetOffset(Handle:gc, const String:key[]);
   297 
   298 /**
   299  * Gets the value of a key from the "Keys" section.
   300  *
   301  * @param gc			Game config handle.
   302  * @param key			Key to retrieve from the Keys section.
   303  * @param buffer		Destination string buffer.
   304  * @param maxlen		Maximum length of output string buffer.
   305  * @return				True if key existed, false otherwise.
   306  */
   307 native bool:GameConfGetKeyValue(Handle:gc, const String:key[], String:buffer[], maxlen);
   308 
   309 /**
   310  * Returns the operating system's "tick count," which is a number of 
   311  * milliseconds since the operating system loaded.  This can be used
   312  * for basic benchmarks.
   313  *
   314  * @return				Tick count in milliseconds.
   315  */
   316 native GetSysTickCount();
   317 
   318 /**
   319  * Specifies that the given config file should be executed after plugin load.
   320  * OnConfigsExecuted() will not be called until the config file has executed, 
   321  * but it will be called if the execution fails.
   322  *
   323  * @param autoCreate	If true, and the config file does not exist, such a config
   324  *						file will be automatically created and populated with
   325  *						information from the plugin's registered cvars.
   326  * @param name			Name of the config file, excluding the .cfg extension.
   327  *						If empty, <plugin.filename.cfg> is assumed.
   328  * @param folder		Folder under cfg/ to use.  By default this is "sourcemod."
   329  * @noreturn
   330  */
   331 native AutoExecConfig(bool:autoCreate=true, const String:name[]="", const String:folder[]="sourcemod");
   332 
   333 /**
   334  * Sets a native as optional, such that if it is unloaded, removed,
   335  * or otherwise non-existent, the plugin will still work.  Calling
   336  * removed natives results in a run-time error.
   337  *
   338  * @param name			Native name.
   339  * @noreturn
   340  */
   341 native MarkNativeAsOptional(const String:name[]);
   342 
   343 /**
   344  * Registers a library name for identifying as a dependency to 
   345  * other plugins.
   346  *
   347  * @param name			Library name.
   348  * @noreturn
   349  */
   350 native RegPluginLibrary(const String:name[]);
   351 
   352 /**
   353  * Returns whether a library exists.
   354  *
   355  * @param name			Library name.
   356  * @return				True if exists, false otherwise.
   357  */
   358 native bool:LibraryExists(const String:name[]);
   359 
   360 /**
   361  * Called after a library (plugin) is added that the 
   362  * current plugin references optionally.
   363  *
   364  * @param name			Library name.
   365  */
   366 forward OnLibraryAdded(const String:name[]);
   367 
   368 /**
   369  * Called right before a library (plugin) is removed that the 
   370  * current plugin references optionally.
   371  *
   372  * @param name			Library name.
   373  */
   374 forward OnLibraryRemoved(const String:name[]);
   375 
   376 #include <helpers>
   377 #include <entity>