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