plugins/include/sourcemod.inc
author Scott Ehlert <ds@alliedmods.net>
Mon Mar 19 18:07:15 2007 +0000 (2007-03-19)
changeset 650 ab919035c173
parent 643 f55b20bb1007
child 651 7129f1566129
permissions -rw-r--r--
Guess I forgot to close this.
     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 <handles>
    36 #include <string>
    37 #include <admin>
    38 #include <files>
    39 #include <console>
    40 #include <bitbuffer>
    41 #include <sorting>
    42 #include <clients>
    43 #include <usermessages>
    44 #include <events>
    45 #include <functions>
    46 #include <timers>
    47 
    48 /**
    49  * Declare this as a struct in your plugin to expose its information.
    50  * Example:
    51  *
    52  * public Plugin:myinfo =
    53  * {
    54  *    name = "My Plugin",
    55  *    //etc
    56  * };
    57  */
    58 public Plugin:myinfo;
    59  
    60 /**
    61  * Called when the plugin is fully initialized and all known external references are resolved.
    62  * This is called even if the plugin type is "private."
    63  * @note Errors in this function will cause the plugin to stop running.
    64  *
    65  * @noreturn
    66  */
    67 forward OnPluginStart();
    68  
    69 /**
    70  *   Called before OnPluginStart, in case the plugin wants to check for load failure.
    71  * This is called even if the plugin type is "private."  Any natives from modules are 
    72  * not available at this point.  Thus, this forward should only be used for explicit 
    73  * pre-emptive things, such as adding dynamic natives, or setting certain types of load filters.
    74  * 
    75  * @note It is not safe to call externally resolved natives until OnPluginStart().
    76  * @note Any sort of RTE in this function will cause the plugin to fail loading.
    77  *
    78  * @param myself	Handle to the plugin.
    79  * @param late		Whether or not the plugin was loaded "late" (after map load).
    80  * @param error		Error message buffer in case load failed.
    81  * @param err_max	Maximum number of characters for error message buffer.
    82  * @return			True if load success, false otherwise.
    83  */
    84 forward bool:AskPluginLoad(Handle:myself, bool:late, String:error[], err_max);
    85 
    86 /**
    87  * Called when the plugin is about to be unloaded.
    88  *
    89  * @noreturn
    90  */
    91 forward OnPluginEnd();
    92 
    93 /**
    94  * Called when the plugin's pause status is changing.
    95  *
    96  * @param pause			True if the plugin is being paused, false otherwise.
    97  * @noreturn
    98  */
    99 forward OnPluginPauseChange(bool:pause);
   100 
   101 /**
   102  * Called before every server frame.  Note that you should avoid
   103  * doing expensive computations here, and you should declare large
   104  * local arrays using 'decl' instead of 'new'.
   105  */
   106 forward OnGameFrame();
   107 
   108 /**
   109  * Called when the map is loaded and configs have been parsed.
   110  * Note that commands are processed per-frame, and thus config
   111  * files may not be fully loaded until a few seconds later.
   112  */
   113 forward OnServerLoad();
   114 
   115 /**
   116  * Returns the calling plugin's Handle.
   117  *
   118  * @return				Handle of the calling plugin.
   119  */
   120 native Handle:GetMyHandle();
   121 
   122 /**
   123  * Returns an iterator that can be used to search through plugins.
   124  *
   125  * @return				Handle to iterate with.  Must be closed via 
   126  * 						CloseHandle().
   127  * @error				Invalid Handle.
   128  */
   129 native Handle:GetPluginIterator();
   130 
   131 /**
   132  * Returns whether there are more plugins available in the iterator.
   133  *
   134  * @param iter			Handle to the plugin iterator.
   135  * @return				True on more plugins, false otherwise.
   136  * @error				Invalid Handle.
   137  */
   138 native bool:MorePlugins(Handle:iter);
   139 
   140 /**
   141  * Returns the current plugin in the iterator and advances the iterator.
   142  *
   143  * @param iter			Handle to the plugin iterator.
   144  * @return				Current plugin the iterator is at, before
   145  *						the iterator is advanced.
   146  * @error				Invalid Handle.
   147  */
   148 native Handle:ReadPlugin(Handle:iter);
   149 
   150 /**
   151  * Returns a plugin's status.
   152  *
   153  * @param plugin		Plugin Handle (INVALID_HANDLE uses the calling plugin).
   154  * @return				Status code for the plugin.
   155  * @error				Invalid Handle.
   156  */
   157 native PluginStatus:GetPluginStatus(Handle:plugin);
   158 
   159 /**
   160  * Retrieves a plugin's file name relative to the plugins folder.
   161  *
   162  * @param plugin		Plugin Handle (INVALID_HANDLE uses the calling plugin).
   163  * @param buffer		Buffer to the store the file name.
   164  * @param maxlength		Maximum length of the name buffer.
   165  * @noreturn
   166  * @error				Invalid Handle.
   167  */
   168 native GetPluginFilename(Handle:plugin, String:buffer[], maxlength);
   169 
   170 /**
   171  * Retrieves whether or not a plugin is being debugged.
   172  *
   173  * @param plugin		Plugin Handle (INVALID_HANDLE uses the calling plugin).
   174  * @return				True if being debugged, false otherwise.
   175  * @error				Invalid Handle.
   176  */
   177 native bool:IsPluginDebugging(Handle:hndl);
   178 
   179 /**
   180  * Retrieves a plugin's public info.
   181  *
   182  * @param plugin		Plugin Handle (INVALID_HANDLE uses the calling plugin).
   183  * @param info			Plugin info property to retrieve.
   184  * @param buffer		Buffer to store info in.
   185  * @param maxlength		Maximum length of buffer.
   186  * @return				True on success, false if property is not available.
   187  * @error				Invalid Handle.
   188  */
   189 native bool:GetPluginInfo(Handle:plugin, PluginInfo:info, String:buffer[], maxlength);
   190 
   191 /**
   192  * Aborts the current callback and throws an error.  This function
   193  * does not return in that no code is executed following it.
   194  *
   195  * @param format		String format.
   196  * @param ...			Format arguments.
   197  * @noreturn
   198  * @error				Always!
   199  */
   200 native ThrowError(const String:fmt[], any:...);
   201 
   202 /**
   203  * Logs a generic message to the HL2 logs.
   204  *
   205  * @param format		String format.
   206  * @param ...			Format arguments.
   207  * @noreturn
   208  */
   209 native LogToGame(const String:format[], any:...);
   210 
   211 /**
   212  * Logs a plugin message to the SourceMod logs.
   213  *
   214  * @param format		String format.
   215  * @param ...			Format arguments.
   216  * @noreturn
   217  */
   218 native LogMessage(const String:format[], any:...);
   219 
   220 /**
   221  * Logs a plugin error message to the SourceMod logs.
   222  *
   223  * @param format		String format.
   224  * @param ...			Format arguments.
   225  * @noreturn
   226  */
   227 native LogError(const String:format[], any:...);
   228 
   229 /**
   230  * Gets the system time as a unix timestamp.
   231  *
   232  * @param bigStamp		Optional array to store the 64bit timestamp in.
   233  * @return				32bit timestamp (number of seconds since unix epoch).
   234  */
   235 native GetTime(bigStamp[2]={0,0});
   236 
   237 /**
   238  * Sets the seed value for the global Half-Life 2 Random Stream
   239  *
   240  * @param seed			Seed value.
   241  * @noreturn	
   242  */
   243 native SetRandomSeed(seed);
   244 
   245 /**
   246  * Returns a random floating point number from the Half-Life 2 Random Stream
   247  *
   248  * @param fMin			Minimum random bound.
   249  * @param fMax			Maximum random bound.
   250  * @return				A random number between (inclusive) fMin and fMax.
   251  */
   252 native Float:GetRandomFloat(Float:fMin=0.0, Float:fMax=1.0);
   253 
   254 /**
   255  * Returns a random number from the Half-Life 2 Random Stream
   256  *
   257  * @param nmin			Minimum random bound.
   258  * @param nmax			Maximum random bound.
   259  * @return				A random number between (inclusive) nmin and nmax.
   260  */
   261 native GetRandomInt(nmin, nmax);
   262 
   263 /**
   264  * Returns whether a map is valid or not.
   265  * 
   266  * @param 				Map name, excluding .bsp extension.
   267  * @return				True if valid, false otherwise.
   268  */
   269 native bool:IsMapValid(const String:map[]);
   270 
   271 /**
   272  * Returns whether the server is dedicated.
   273  *
   274  * @return				True if dedicated, false otherwise.
   275  */
   276 native bool:IsDedicatedServer();
   277 
   278 /**
   279  * Returns a high-precision time value for profiling the engine.
   280  *
   281  * @return				A floating point time value.
   282  */
   283 native Float:GetEngineTime();
   284 
   285 /** 
   286  * Returns the game time based on the game tick.
   287  *
   288  * @return				Game tick time.
   289  */
   290 native Float:GetGameTime();
   291 
   292 /**
   293  * Returns the game description from the mod.
   294  *
   295  * @param buffer		Buffer to store the description.
   296  * @param maxlength		Maximum size of the buffer.
   297  * @param original		If true, retrieves the original game description,
   298  *						ignoring any potential hooks from plugins.
   299  * @return				Number of bytes written to the buffer (UTF-8 safe).
   300  */
   301 native GetGameDescription(String:buffer[], maxlength, bool:original=false);
   302 
   303 /**
   304  * Returns the current map name.
   305  *
   306  * @param buffer		Buffer to store map name.
   307  * @param maxlength		Maximum length of buffer.
   308  * @return				Number of bytes written (UTF-8 safe).
   309  */
   310 native GetCurrentMap(String:buffer[], maxlength);
   311 
   312 #include <helpers>
   313 #include <entity>