plugins/include/sourcemod.inc
author Scott Ehlert <ds@alliedmods.net>
Sun May 13 07:48:36 2007 +0000 (2007-05-13)
changeset 784 0ff19a8bd981
parent 723 60395a16ddea
child 811 1b4893011b96
permissions -rw-r--r--
amb283 - Renamed IsPlayerInGame() to IsClientInGame()
     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 enum DialogType
    49 {
    50 	DialogType_Msg = 0,		/**< just an on screen message */
    51 	DialogType_Menu, 		/**< an options menu */
    52 	DialogType_Text, 		/**< a richtext dialog */
    53 	DialogType_Entry 		/**< an entry box */
    54 };
    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 and the servercfgfile has finished
   131  * executing.  This is usually 'server.cfg' but most mods allow it to
   132  * be set via 'servercfgfile'.  
   133  *
   134  * @note If server.cfg is executed more than once per map, this forward
   135  * will only be called the first time (per map).
   136  */
   137 forward OnServerCfg();
   138 
   139 /**
   140  * Returns the calling plugin's Handle.
   141  *
   142  * @return				Handle of the calling plugin.
   143  */
   144 native Handle:GetMyHandle();
   145 
   146 /**
   147  * Returns an iterator that can be used to search through plugins.
   148  *
   149  * @return				Handle to iterate with.  Must be closed via 
   150  * 						CloseHandle().
   151  * @error				Invalid Handle.
   152  */
   153 native Handle:GetPluginIterator();
   154 
   155 /**
   156  * Returns whether there are more plugins available in the iterator.
   157  *
   158  * @param iter			Handle to the plugin iterator.
   159  * @return				True on more plugins, false otherwise.
   160  * @error				Invalid Handle.
   161  */
   162 native bool:MorePlugins(Handle:iter);
   163 
   164 /**
   165  * Returns the current plugin in the iterator and advances the iterator.
   166  *
   167  * @param iter			Handle to the plugin iterator.
   168  * @return				Current plugin the iterator is at, before
   169  *						the iterator is advanced.
   170  * @error				Invalid Handle.
   171  */
   172 native Handle:ReadPlugin(Handle:iter);
   173 
   174 /**
   175  * Returns a plugin's status.
   176  *
   177  * @param plugin		Plugin Handle (INVALID_HANDLE uses the calling plugin).
   178  * @return				Status code for the plugin.
   179  * @error				Invalid Handle.
   180  */
   181 native PluginStatus:GetPluginStatus(Handle:plugin);
   182 
   183 /**
   184  * Retrieves a plugin's file name relative to the plugins folder.
   185  *
   186  * @param plugin		Plugin Handle (INVALID_HANDLE uses the calling plugin).
   187  * @param buffer		Buffer to the store the file name.
   188  * @param maxlength		Maximum length of the name buffer.
   189  * @noreturn
   190  * @error				Invalid Handle.
   191  */
   192 native GetPluginFilename(Handle:plugin, String:buffer[], maxlength);
   193 
   194 /**
   195  * Retrieves whether or not a plugin is being debugged.
   196  *
   197  * @param plugin		Plugin Handle (INVALID_HANDLE uses the calling plugin).
   198  * @return				True if being debugged, false otherwise.
   199  * @error				Invalid Handle.
   200  */
   201 native bool:IsPluginDebugging(Handle:hndl);
   202 
   203 /**
   204  * Retrieves a plugin's public info.
   205  *
   206  * @param plugin		Plugin Handle (INVALID_HANDLE uses the calling plugin).
   207  * @param info			Plugin info property to retrieve.
   208  * @param buffer		Buffer to store info in.
   209  * @param maxlength		Maximum length of buffer.
   210  * @return				True on success, false if property is not available.
   211  * @error				Invalid Handle.
   212  */
   213 native bool:GetPluginInfo(Handle:plugin, PluginInfo:info, String:buffer[], maxlength);
   214 
   215 /**
   216  * Aborts the current callback and throws an error.  This function
   217  * does not return in that no code is executed following it.
   218  *
   219  * @param format		String format.
   220  * @param ...			Format arguments.
   221  * @noreturn
   222  * @error				Always!
   223  */
   224 native ThrowError(const String:fmt[], any:...);
   225 
   226 /**
   227  * Logs a generic message to the HL2 logs.
   228  *
   229  * @param format		String format.
   230  * @param ...			Format arguments.
   231  * @noreturn
   232  */
   233 native LogToGame(const String:format[], any:...);
   234 
   235 /**
   236  * Logs a plugin message to the SourceMod logs.
   237  *
   238  * @param format		String format.
   239  * @param ...			Format arguments.
   240  * @noreturn
   241  */
   242 native LogMessage(const String:format[], any:...);
   243 
   244 /**
   245  * Logs a plugin error message to the SourceMod logs.
   246  *
   247  * @param format		String format.
   248  * @param ...			Format arguments.
   249  * @noreturn
   250  */
   251 native LogError(const String:format[], any:...);
   252 
   253 /**
   254  * Gets the system time as a unix timestamp.
   255  *
   256  * @param bigStamp		Optional array to store the 64bit timestamp in.
   257  * @return				32bit timestamp (number of seconds since unix epoch).
   258  */
   259 native GetTime(bigStamp[2]={0,0});
   260 
   261 /**
   262  * Sets the seed value for the global Half-Life 2 Random Stream
   263  *
   264  * @param seed			Seed value.
   265  * @noreturn	
   266  */
   267 native SetRandomSeed(seed);
   268 
   269 /**
   270  * Returns a random floating point number from the Half-Life 2 Random Stream
   271  *
   272  * @param fMin			Minimum random bound.
   273  * @param fMax			Maximum random bound.
   274  * @return				A random number between (inclusive) fMin and fMax.
   275  */
   276 native Float:GetRandomFloat(Float:fMin=0.0, Float:fMax=1.0);
   277 
   278 /**
   279  * Returns a random number from the Half-Life 2 Random Stream
   280  *
   281  * @param nmin			Minimum random bound.
   282  * @param nmax			Maximum random bound.
   283  * @return				A random number between (inclusive) nmin and nmax.
   284  */
   285 native GetRandomInt(nmin, nmax);
   286 
   287 /**
   288  * Returns whether a map is valid or not.
   289  * 
   290  * @param 				Map name, excluding .bsp extension.
   291  * @return				True if valid, false otherwise.
   292  */
   293 native bool:IsMapValid(const String:map[]);
   294 
   295 /**
   296  * Returns whether the server is dedicated.
   297  *
   298  * @return				True if dedicated, false otherwise.
   299  */
   300 native bool:IsDedicatedServer();
   301 
   302 /**
   303  * Returns a high-precision time value for profiling the engine.
   304  *
   305  * @return				A floating point time value.
   306  */
   307 native Float:GetEngineTime();
   308 
   309 /** 
   310  * Returns the game time based on the game tick.
   311  *
   312  * @return				Game tick time.
   313  */
   314 native Float:GetGameTime();
   315 
   316 /**
   317  * Returns the game description from the mod.
   318  *
   319  * @param buffer		Buffer to store the description.
   320  * @param maxlength		Maximum size of the buffer.
   321  * @param original		If true, retrieves the original game description,
   322  *						ignoring any potential hooks from plugins.
   323  * @return				Number of bytes written to the buffer (UTF-8 safe).
   324  */
   325 native GetGameDescription(String:buffer[], maxlength, bool:original=false);
   326 
   327 /**
   328  * Returns the name of the game's directory.
   329  *
   330  * @param buffer		Buffer to store the directory name.
   331  * @param maxlength		Maximum size of the buffer.
   332  *
   333  * return				Number of bytes written to the buffer (UTF-8 safe).
   334  */
   335 native GetGameFolderName(String:buffer[], maxlength);
   336 
   337 /**
   338  * Returns the current map name.
   339  *
   340  * @param buffer		Buffer to store map name.
   341  * @param maxlength		Maximum length of buffer.
   342  * @return				Number of bytes written (UTF-8 safe).
   343  */
   344 native GetCurrentMap(String:buffer[], maxlength);
   345 
   346 /**
   347  * Precaches a given model.
   348  *
   349  * @param model			Name of the model to precache.
   350  * @param preload		If preload is true the file will be precached before level startup.
   351  * @return			Returns the model index, 0 for error.
   352  */
   353 native PrecacheModel(const String:model[], bool:preload=false);
   354 
   355 /**
   356  * Precaches a given sentence file.
   357  *
   358  * @param file			Name of the sentence file to precache.
   359  * @param preload		If preload is true the file will be precached before level startup.
   360  * @return			Returns a sentence file index.
   361  */
   362 native PrecacheSentenceFile(const String:file[], bool:preload=false);
   363 
   364 /**
   365  * Precaches a given decal.
   366  *
   367  * @param decal			Name of the decal to precache.
   368  * @param preload		If preload is true the file will be precached before level startup.
   369  * @return			Returns a decal index.
   370  */
   371 native PrecacheDecal(const String:decal[], bool:preload=false);
   372 
   373 /**
   374  * Precaches a given generic file.
   375  *
   376  * @param generic		Name of the generic file to precache.
   377  * @param preload		If preload is true the file will be precached before level startup.
   378  * @return			Returns a generic file index.
   379  */
   380 native PrecacheGeneric(const String:generic[], bool:preload=false);
   381 
   382 /**
   383  * Returns if a given model is precached.
   384  *
   385  * @param model			Name of the model to check.
   386  * @return			True if precached, false otherwise.
   387  */
   388 native bool:IsModelPrecached(const String:model[]);
   389 
   390 /**
   391  * Returns if a given decal is precached.
   392  *
   393  * @param decal			Name of the decal to check.
   394  * @return			True if precached, false otherwise.
   395  */
   396 native bool:IsDecalPrecached(const String:decal[]);
   397 
   398 /**
   399  * Returns if a given generic file is precached.
   400  *
   401  * @param decal			Name of the generic file to check.
   402  * @return			True if precached, false otherwise.
   403  */
   404 native bool:IsGenericPrecached(const String:generic[]);
   405 
   406 /**
   407  * Precaches a given sound.
   408  *
   409  * @param sound			Name of the sound to precache.
   410  * @param preload		If preload is true the file will be precached before level startup.
   411  * @return			True if successfully precached, false otherwise.
   412  */
   413 native bool:PrecacheSound(const String:sound[], bool:preload=false);
   414 
   415 /**
   416  * Returns if a given sound is precached.
   417  *
   418  * @param sound			Name of the sound to check.
   419  * @return			True if precached, false otherwise.
   420  */
   421 native bool:IsSoundPrecached(const String:sound[]);
   422 
   423 /**
   424  * Creates different types of ingame messages.
   425  *
   426  * @param client		Index of the client.
   427  * @param kv			KeyValues handle to set the menu keys and options. (Check iserverplugin.h for more information).
   428  * @param type			Message type to display ingame.
   429  * @noreturn
   430  * @error				Invalid client index, or client not connected.
   431  */
   432 native CreateDialog(client, Handle:kv, DialogType:type);
   433 
   434 /**
   435  * Loads a game config file.
   436  *
   437  * @param file			File to load.  The path must be relative to the 'gamedata' folder under the config folder 
   438  *					and the extension should be omitted.
   439  * @return			A handle to the game config file or INVALID_HANDLE in failure.
   440  */
   441 native Handle:LoadGameConfigFile(const String:file[]);
   442 
   443 /**
   444  * Returns an offset value.
   445  *
   446  * @param gc			Game config handle.
   447  * @param key			Key to retrieve from the offset section.
   448  * @return			An offset, or -1 on failure.
   449  */
   450 native GameConfGetOffset(Handle:gc, const String:key[]);
   451 
   452 /**
   453  * Gets the value of a key from the "Keys" section.
   454  *
   455  * @param gc			Game config handle.
   456  * @param key			Key to retrieve from the Keys section.
   457  * @param buffer		Destination string buffer.
   458  * @param maxlen		Maximum length of output string buffer.
   459  * @return			True if key existed, false otherwise.
   460  */
   461 native bool:GameConfGetKeyValue(Handle:gc, const String:key[], String:buffer[], maxlen);
   462 
   463 #include <helpers>
   464 #include <entity>