plugins/include/sourcemod.inc
author Scott Ehlert <ds@alliedmods.net>
Thu Apr 05 10:55:40 2007 +0000 (2007-04-05)
changeset 669 ce01c2eb020c
parent 659 edd2ead1f13e
child 682 a70055d6d3b3
permissions -rw-r--r--
Various things:
- Fixed inline translations when using %T
- "Improved" caching of server language
- Renamed Translator::GetServerLanguageCode() to GetServerLanguage()
- Added some more comments to sm_globals.h
- Natives folder in project file mysteriously was moved inside Interfaces, so moved it back o_O
- DS hates empty if statements :o
     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  * This function will be called on each mapchange.
   113  */
   114 forward OnServerLoad();
   115 
   116 /**
   117  * Returns the calling plugin's Handle.
   118  *
   119  * @return				Handle of the calling plugin.
   120  */
   121 native Handle:GetMyHandle();
   122 
   123 /**
   124  * Returns an iterator that can be used to search through plugins.
   125  *
   126  * @return				Handle to iterate with.  Must be closed via 
   127  * 						CloseHandle().
   128  * @error				Invalid Handle.
   129  */
   130 native Handle:GetPluginIterator();
   131 
   132 /**
   133  * Returns whether there are more plugins available in the iterator.
   134  *
   135  * @param iter			Handle to the plugin iterator.
   136  * @return				True on more plugins, false otherwise.
   137  * @error				Invalid Handle.
   138  */
   139 native bool:MorePlugins(Handle:iter);
   140 
   141 /**
   142  * Returns the current plugin in the iterator and advances the iterator.
   143  *
   144  * @param iter			Handle to the plugin iterator.
   145  * @return				Current plugin the iterator is at, before
   146  *						the iterator is advanced.
   147  * @error				Invalid Handle.
   148  */
   149 native Handle:ReadPlugin(Handle:iter);
   150 
   151 /**
   152  * Returns a plugin's status.
   153  *
   154  * @param plugin		Plugin Handle (INVALID_HANDLE uses the calling plugin).
   155  * @return				Status code for the plugin.
   156  * @error				Invalid Handle.
   157  */
   158 native PluginStatus:GetPluginStatus(Handle:plugin);
   159 
   160 /**
   161  * Retrieves a plugin's file name relative to the plugins folder.
   162  *
   163  * @param plugin		Plugin Handle (INVALID_HANDLE uses the calling plugin).
   164  * @param buffer		Buffer to the store the file name.
   165  * @param maxlength		Maximum length of the name buffer.
   166  * @noreturn
   167  * @error				Invalid Handle.
   168  */
   169 native GetPluginFilename(Handle:plugin, String:buffer[], maxlength);
   170 
   171 /**
   172  * Retrieves whether or not a plugin is being debugged.
   173  *
   174  * @param plugin		Plugin Handle (INVALID_HANDLE uses the calling plugin).
   175  * @return				True if being debugged, false otherwise.
   176  * @error				Invalid Handle.
   177  */
   178 native bool:IsPluginDebugging(Handle:hndl);
   179 
   180 /**
   181  * Retrieves a plugin's public info.
   182  *
   183  * @param plugin		Plugin Handle (INVALID_HANDLE uses the calling plugin).
   184  * @param info			Plugin info property to retrieve.
   185  * @param buffer		Buffer to store info in.
   186  * @param maxlength		Maximum length of buffer.
   187  * @return				True on success, false if property is not available.
   188  * @error				Invalid Handle.
   189  */
   190 native bool:GetPluginInfo(Handle:plugin, PluginInfo:info, String:buffer[], maxlength);
   191 
   192 /**
   193  * Aborts the current callback and throws an error.  This function
   194  * does not return in that no code is executed following it.
   195  *
   196  * @param format		String format.
   197  * @param ...			Format arguments.
   198  * @noreturn
   199  * @error				Always!
   200  */
   201 native ThrowError(const String:fmt[], any:...);
   202 
   203 /**
   204  * Logs a generic message to the HL2 logs.
   205  *
   206  * @param format		String format.
   207  * @param ...			Format arguments.
   208  * @noreturn
   209  */
   210 native LogToGame(const String:format[], any:...);
   211 
   212 /**
   213  * Logs a plugin message to the SourceMod logs.
   214  *
   215  * @param format		String format.
   216  * @param ...			Format arguments.
   217  * @noreturn
   218  */
   219 native LogMessage(const String:format[], any:...);
   220 
   221 /**
   222  * Logs a plugin error message to the SourceMod logs.
   223  *
   224  * @param format		String format.
   225  * @param ...			Format arguments.
   226  * @noreturn
   227  */
   228 native LogError(const String:format[], any:...);
   229 
   230 /**
   231  * Gets the system time as a unix timestamp.
   232  *
   233  * @param bigStamp		Optional array to store the 64bit timestamp in.
   234  * @return				32bit timestamp (number of seconds since unix epoch).
   235  */
   236 native GetTime(bigStamp[2]={0,0});
   237 
   238 /**
   239  * Sets the seed value for the global Half-Life 2 Random Stream
   240  *
   241  * @param seed			Seed value.
   242  * @noreturn	
   243  */
   244 native SetRandomSeed(seed);
   245 
   246 /**
   247  * Returns a random floating point number from the Half-Life 2 Random Stream
   248  *
   249  * @param fMin			Minimum random bound.
   250  * @param fMax			Maximum random bound.
   251  * @return				A random number between (inclusive) fMin and fMax.
   252  */
   253 native Float:GetRandomFloat(Float:fMin=0.0, Float:fMax=1.0);
   254 
   255 /**
   256  * Returns a random number from the Half-Life 2 Random Stream
   257  *
   258  * @param nmin			Minimum random bound.
   259  * @param nmax			Maximum random bound.
   260  * @return				A random number between (inclusive) nmin and nmax.
   261  */
   262 native GetRandomInt(nmin, nmax);
   263 
   264 /**
   265  * Returns whether a map is valid or not.
   266  * 
   267  * @param 				Map name, excluding .bsp extension.
   268  * @return				True if valid, false otherwise.
   269  */
   270 native bool:IsMapValid(const String:map[]);
   271 
   272 /**
   273  * Returns whether the server is dedicated.
   274  *
   275  * @return				True if dedicated, false otherwise.
   276  */
   277 native bool:IsDedicatedServer();
   278 
   279 /**
   280  * Returns a high-precision time value for profiling the engine.
   281  *
   282  * @return				A floating point time value.
   283  */
   284 native Float:GetEngineTime();
   285 
   286 /** 
   287  * Returns the game time based on the game tick.
   288  *
   289  * @return				Game tick time.
   290  */
   291 native Float:GetGameTime();
   292 
   293 /**
   294  * Returns the game description from the mod.
   295  *
   296  * @param buffer		Buffer to store the description.
   297  * @param maxlength		Maximum size of the buffer.
   298  * @param original		If true, retrieves the original game description,
   299  *						ignoring any potential hooks from plugins.
   300  * @return				Number of bytes written to the buffer (UTF-8 safe).
   301  */
   302 native GetGameDescription(String:buffer[], maxlength, bool:original=false);
   303 
   304 /**
   305  * Returns the current map name.
   306  *
   307  * @param buffer		Buffer to store map name.
   308  * @param maxlength		Maximum length of buffer.
   309  * @return				Number of bytes written (UTF-8 safe).
   310  */
   311 native GetCurrentMap(String:buffer[], maxlength);
   312 
   313 /**
   314  * Precaches a given model.
   315  *
   316  * @param model			Name of the model to precache.
   317  * @param preload		If preload is true the file will be precached before level startup.
   318  * @return			Returns the model index, 0 for error.
   319  */
   320 native PrecacheModel(const String:model[], bool:preload=false);
   321 
   322 /**
   323  * Precaches a given sentence file.
   324  *
   325  * @param file			Name of the sentence file to precache.
   326  * @param preload		If preload is true the file will be precached before level startup.
   327  * @return			Returns a sentence file index.
   328  */
   329 native PrecacheSentenceFile(const String:file[], bool:preload=false);
   330 
   331 /**
   332  * Precaches a given decal.
   333  *
   334  * @param decal			Name of the decal to precache.
   335  * @param preload		If preload is true the file will be precached before level startup.
   336  * @return			Returns a decal index.
   337  */
   338 native PrecacheDecal(const String:decal[], bool:preload=false);
   339 
   340 /**
   341  * Precaches a given generic file.
   342  *
   343  * @param generic		Name of the generic file to precache.
   344  * @param preload		If preload is true the file will be precached before level startup.
   345  * @return			Returns a generic file index.
   346  */
   347 native PrecacheGeneric(const String:generic[], bool:preload=false);
   348 
   349 /**
   350  * Returns if a given model is precached.
   351  *
   352  * @param model			Name of the model to check.
   353  * @return			True if precached, false otherwise.
   354  */
   355 native bool:IsModelPrecached(const String:model[]);
   356 
   357 /**
   358  * Returns if a given decal is precached.
   359  *
   360  * @param decal			Name of the decal to check.
   361  * @return			True if precached, false otherwise.
   362  */
   363 native bool:IsDecalPrecached(const String:decal[]);
   364 
   365 /**
   366  * Returns if a given generic file is precached.
   367  *
   368  * @param decal			Name of the generic file to check.
   369  * @return			True if precached, false otherwise.
   370  */
   371 native bool:IsGenericPrecached(const String:generic[]);
   372 
   373 /**
   374  * Precaches a given sound.
   375  *
   376  * @param sound			Name of the sound to precache.
   377  * @param preload		If preload is true the file will be precached before level startup.
   378  * @return			True if successfully precached, false otherwise.
   379  */
   380 native bool:PrecacheSound(const String:sound[], bool:preload=false);
   381 
   382 /**
   383  * Returns if a given sound is precached.
   384  *
   385  * @param sound			Name of the sound to check.
   386  * @return			True if precached, false otherwise.
   387  */
   388 native bool:IsSoundPrecached(const String:sound[]);
   389 
   390 /**
   391  * Executes a client command on the server without being networked.
   392  *
   393  * @param client		Index of the client.
   394  * @param fmt			Format of the client command.
   395  * @param ...			Format parameters
   396  * @noreturn
   397  * @error				Invalid client index, or client not connected.
   398  */
   399 native FakeClientCommand(client, const String:fmt[], any:...);
   400 
   401 #include <helpers>
   402 #include <entity>