plugins/include/halflife.inc
author Powerlord <rbemrose@gmail.com>
Tue Aug 21 00:44:44 2012 -0400 (2012-08-21)
changeset 3620 bb36770ded54
parent 3613 b0740093756d
child 3853 3c8f57923db5
permissions -rw-r--r--
Updated TFHoliday enum (bug 5436, r=asherkin).
     1 /**
     2  * vim: set ts=4 :
     3  * =============================================================================
     4  * SourceMod (C)2004-2008 AlliedModders LLC.  All rights reserved.
     5  * =============================================================================
     6  *
     7  * This file is part of the SourceMod/SourcePawn SDK.
     8  *
     9  * This program is free software; you can redistribute it and/or modify it under
    10  * the terms of the GNU General Public License, version 3.0, as published by the
    11  * Free Software Foundation.
    12  * 
    13  * This program is distributed in the hope that it will be useful, but WITHOUT
    14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    15  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
    16  * details.
    17  *
    18  * You should have received a copy of the GNU General Public License along with
    19  * this program.  If not, see <http://www.gnu.org/licenses/>.
    20  *
    21  * As a special exception, AlliedModders LLC gives you permission to link the
    22  * code of this program (as well as its derivative works) to "Half-Life 2," the
    23  * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
    24  * by the Valve Corporation.  You must obey the GNU General Public License in
    25  * all respects for all other code used.  Additionally, AlliedModders LLC grants
    26  * this exception to all derivative works.  AlliedModders LLC defines further
    27  * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
    28  * or <http://www.sourcemod.net/license.php>.
    29  *
    30  * Version: $Id$
    31  */
    32 
    33 #if defined _halflife_included
    34  #endinput
    35 #endif
    36 #define _halflife_included
    37 
    38 #define SOURCE_SDK_UNKNOWN			0		/**< Could not determine the engine version */
    39 #define SOURCE_SDK_ORIGINAL			10		/**< Original Source engine (still used by "The Ship") */
    40 #define SOURCE_SDK_DARKMESSIAH		15		/**< Modified version of original engine used by Dark Messiah (no SDK) */
    41 #define SOURCE_SDK_EPISODE1			20		/**< SDK+Engine released after Episode 1 */
    42 #define SOURCE_SDK_EPISODE2			30		/**< SDK+Engine released after Episode 2/Orange Box */
    43 #define SOURCE_SDK_BLOODYGOODTIME	32		/**< Modified version of ep2 engine used by Bloody Good Time (no SDK) */
    44 #define SOURCE_SDK_EYE				33		/**< Modified version of ep2 engine used by E.Y.E Divine Cybermancy (no SDK) */
    45 #define SOURCE_SDK_CSS				34		/**< Sometime-older version of Source 2009 SDK+Engine, used for Counter-Strike: Source */
    46 #define SOURCE_SDK_EPISODE2VALVE	35		/**< SDK+Engine released after Episode 2/Orange Box, "Source 2009" or "Source MP" */
    47 #define SOURCE_SDK_LEFT4DEAD		40		/**< Engine released after Left 4 Dead (no SDK yet) */
    48 #define SOURCE_SDK_LEFT4DEAD2		50		/**< Engine released after Left 4 Dead 2 (no SDK yet) */
    49 #define SOURCE_SDK_ALIENSWARM		60		/**< SDK+Engine released after Alien Swarm */
    50 #define SOURCE_SDK_CSGO				80		/**< Engine released after CS:GO (no SDK yet) */
    51 
    52 #define MOTDPANEL_TYPE_TEXT		0	/**< Treat msg as plain text */
    53 #define MOTDPANEL_TYPE_INDEX	1	/**< Msg is auto determined by the engine */
    54 #define MOTDPANEL_TYPE_URL		2	/**< Treat msg as an URL link */
    55 #define MOTDPANEL_TYPE_FILE		3	/**< Treat msg as a filename to be openned */
    56 
    57 enum DialogType
    58 {
    59 	DialogType_Msg = 0,		/**< just an on screen message */
    60 	DialogType_Menu, 		/**< an options menu */
    61 	DialogType_Text, 		/**< a richtext dialog */
    62 	DialogType_Entry, 		/**< an entry box */
    63 	DialogType_AskConnect	/**< ask the client to connect to a specified IP */
    64 };
    65 
    66 #define INVALID_ENT_REFERENCE 0xFFFFFFFF
    67 
    68 /**
    69  * Logs a generic message to the HL2 logs.
    70  *
    71  * @param format		String format.
    72  * @param ...			Format arguments.
    73  * @noreturn
    74  */
    75 native LogToGame(const String:format[], any:...);
    76 
    77 /**
    78  * Sets the seed value for the global Half-Life 2 Random Stream.
    79  *
    80  * @param seed			Seed value.
    81  * @noreturn	
    82  */
    83 native SetRandomSeed(seed);
    84 
    85 /**
    86  * Returns a random floating point number from the Half-Life 2 Random Stream.
    87  *
    88  * @param fMin			Minimum random bound.
    89  * @param fMax			Maximum random bound.
    90  * @return				A random number between (inclusive) fMin and fMax.
    91  */
    92 native Float:GetRandomFloat(Float:fMin=0.0, Float:fMax=1.0);
    93 
    94 /**
    95  * Returns a random number from the Half-Life 2 Random Stream.
    96  *
    97  * @param nmin			Minimum random bound.
    98  * @param nmax			Maximum random bound.
    99  * @return				A random number between (inclusive) nmin and nmax.
   100  */
   101 native GetRandomInt(nmin, nmax);
   102 
   103 /**
   104  * Returns whether a map is valid or not.
   105  * 
   106  * @param 				Map name, excluding .bsp extension.
   107  * @return				True if valid, false otherwise.
   108  */
   109 native bool:IsMapValid(const String:map[]);
   110 
   111 /**
   112  * Returns whether the server is dedicated.
   113  *
   114  * @return				True if dedicated, false otherwise.
   115  */
   116 native bool:IsDedicatedServer();
   117 
   118 /**
   119  * Returns a high-precision time value for profiling the engine.
   120  *
   121  * @return				A floating point time value.
   122  */
   123 native Float:GetEngineTime();
   124 
   125 /** 
   126  * Returns the game time based on the game tick.
   127  *
   128  * @return				Game tick time.
   129  */
   130 native Float:GetGameTime();
   131 
   132 /** 
   133  * Returns the game's internal tick count.
   134  *
   135  * @return				Game tick count.
   136  */
   137 native GetGameTickCount();
   138 
   139 /**
   140  * Returns the game description from the mod.
   141  *
   142  * @param buffer		Buffer to store the description.
   143  * @param maxlength		Maximum size of the buffer.
   144  * @param original		If true, retrieves the original game description,
   145  *						ignoring any potential hooks from plugins.
   146  * @return				Number of bytes written to the buffer (UTF-8 safe).
   147  */
   148 native GetGameDescription(String:buffer[], maxlength, bool:original=false);
   149 
   150 /**
   151  * Returns the name of the game's directory.
   152  *
   153  * @param buffer		Buffer to store the directory name.
   154  * @param maxlength		Maximum size of the buffer.
   155  *
   156  * return				Number of bytes written to the buffer (UTF-8 safe).
   157  */
   158 native GetGameFolderName(String:buffer[], maxlength);
   159 
   160 /**
   161  * Returns the current map name.
   162  *
   163  * @param buffer		Buffer to store map name.
   164  * @param maxlength		Maximum length of buffer.
   165  * @return				Number of bytes written (UTF-8 safe).
   166  */
   167 native GetCurrentMap(String:buffer[], maxlength);
   168 
   169 /**
   170  * Precaches a given model.
   171  *
   172  * @param model			Name of the model to precache.
   173  * @param preload		If preload is true the file will be precached before level startup.
   174  * @return				Returns the model index, 0 for error.
   175  */
   176 native PrecacheModel(const String:model[], bool:preload=false);
   177 
   178 /**
   179  * Precaches a given sentence file.
   180  *
   181  * @param file			Name of the sentence file to precache.
   182  * @param preload		If preload is true the file will be precached before level startup.
   183  * @return				Returns a sentence file index.
   184  */
   185 native PrecacheSentenceFile(const String:file[], bool:preload=false);
   186 
   187 /**
   188  * Precaches a given decal.
   189  *
   190  * @param decal			Name of the decal to precache.
   191  * @param preload		If preload is true the file will be precached before level startup.
   192  * @return				Returns a decal index.
   193  */
   194 native PrecacheDecal(const String:decal[], bool:preload=false);
   195 
   196 /**
   197  * Precaches a given generic file.
   198  *
   199  * @param generic		Name of the generic file to precache.
   200  * @param preload		If preload is true the file will be precached before level startup.
   201  * @return				Returns a generic file index.
   202  */
   203 native PrecacheGeneric(const String:generic[], bool:preload=false);
   204 
   205 /**
   206  * Returns if a given model is precached.
   207  *
   208  * @param model			Name of the model to check.
   209  * @return				True if precached, false otherwise.
   210  */
   211 native bool:IsModelPrecached(const String:model[]);
   212 
   213 /**
   214  * Returns if a given decal is precached.
   215  *
   216  * @param decal			Name of the decal to check.
   217  * @return				True if precached, false otherwise.
   218  */
   219 native bool:IsDecalPrecached(const String:decal[]);
   220 
   221 /**
   222  * Returns if a given generic file is precached.
   223  *
   224  * @param decal			Name of the generic file to check.
   225  * @return				True if precached, false otherwise.
   226  */
   227 native bool:IsGenericPrecached(const String:generic[]);
   228 
   229 /**
   230  * Precaches a given sound.
   231  *
   232  * @param sound			Name of the sound to precache.
   233  * @param preload		If preload is true the file will be precached before level startup.
   234  * @return				True if successfully precached, false otherwise.
   235  */
   236 native bool:PrecacheSound(const String:sound[], bool:preload=false);
   237 
   238 /**
   239  * Returns if a given sound is precached.
   240  *
   241  * @param sound			Name of the sound to check.
   242  * @return				True if precached, false otherwise.
   243  */
   244 native bool:IsSoundPrecached(const String:sound[]);
   245 
   246 /**
   247  * Creates different types of ingame messages.
   248  *
   249  * @param client		Index of the client.
   250  * @param kv			KeyValues handle to set the menu keys and options. (Check iserverplugin.h for more information).
   251  * @param type			Message type to display ingame.
   252  * @noreturn
   253  * @error				Invalid client index, or client not connected.
   254  */
   255 native CreateDialog(client, Handle:kv, DialogType:type);
   256 
   257 /**
   258  * Guesses the SDK version a mod was compiled against.  If nothing 
   259  * specific is known about the game, the engine version is used instead.
   260  *
   261  * The return values are guaranteed to increase chronologically (that is, 
   262  * a later release will have a higher value).
   263  *
   264  * @return				SOURCE_SDK version code.
   265  */
   266 native GuessSDKVersion();
   267 
   268 /**
   269  * Prints a message to a specific client in the chat area.
   270  *
   271  * @param client		Client index.
   272  * @param format		Formatting rules.
   273  * @param ...			Variable number of format parameters.
   274  * @noreturn
   275  * @error				If the client is not connected an error will be thrown.
   276  */
   277 native PrintToChat(client, const String:format[], any:...);
   278 
   279 /**
   280  * Prints a message to all clients in the chat area.
   281  *
   282  * @param format		Formatting rules.
   283  * @param ...			Variable number of format parameters.
   284  * @noreturn
   285  */
   286 stock PrintToChatAll(const String:format[], any:...)
   287 {
   288 	decl String:buffer[192];
   289 	
   290 	for (new i = 1; i <= MaxClients; i++)
   291 	{
   292 		if (IsClientInGame(i))
   293 		{
   294 			SetGlobalTransTarget(i);
   295 			VFormat(buffer, sizeof(buffer), format, 2);
   296 			PrintToChat(i, "%s", buffer);
   297 		}
   298 	}
   299 }
   300 
   301 /**
   302  * Prints a message to a specific client in the center of the screen.
   303  *
   304  * @param client		Client index.
   305  * @param format		Formatting rules.
   306  * @param ...			Variable number of format parameters.
   307  * @noreturn
   308  * @error				If the client is not connected an error will be thrown.
   309  */
   310 native PrintCenterText(client, const String:format[], any:...);
   311 
   312 /**
   313  * Prints a message to all clients in the center of the screen.
   314  *
   315  * @param format		Formatting rules.
   316  * @param ...			Variable number of format parameters.
   317  * @noreturn
   318  */
   319 stock PrintCenterTextAll(const String:format[], any:...)
   320 {
   321 	decl String:buffer[192];
   322 
   323 	for (new i = 1; i <= MaxClients; i++)
   324 	{
   325 		if (IsClientInGame(i))
   326 		{
   327 			SetGlobalTransTarget(i);
   328 			VFormat(buffer, sizeof(buffer), format, 2);
   329 			PrintCenterText(i, "%s", buffer);
   330 		}
   331 	}
   332 }
   333 
   334 /**
   335  * Prints a message to a specific client with a hint box.
   336  *
   337  * @param client		Client index.
   338  * @param format		Formatting rules.
   339  * @param ...			Variable number of format parameters.
   340  * @noreturn
   341  * @error				If the client is not connected an error will be thrown.
   342  */
   343 native PrintHintText(client, const String:format[], any:...);
   344 
   345 /**
   346  * Prints a message to all clients with a hint box.
   347  *
   348  * @param format		Formatting rules.
   349  * @param ...			Variable number of format parameters.
   350  * @noreturn
   351  */
   352 stock PrintHintTextToAll(const String:format[], any:...)
   353 {
   354 	decl String:buffer[192];
   355 	
   356 	for (new i = 1; i <= MaxClients; i++)
   357 	{
   358 		if (IsClientInGame(i))
   359 		{
   360 			SetGlobalTransTarget(i);
   361 			VFormat(buffer, sizeof(buffer), format, 2);
   362 			PrintHintText(i, "%s", buffer);
   363 		}
   364 	}
   365 }
   366 
   367 /**
   368  * Shows a VGUI panel to a specific client.
   369  *
   370  * @param client		Client index.
   371  * @param name			Panel type name (Check viewport_panel_names.h to see a list of 
   372  *						some panel names).
   373  * @param Kv			KeyValues handle with all the data for the panel setup (Depends 
   374  *						on the panel type and may be unused).
   375  * @param show			True to show the panel, or false to remove it from the client screen.
   376  * @noreturn
   377  * @error				If the client is not connected an error will be thrown.
   378  */
   379 native ShowVGUIPanel(client, const String:name[], Handle:Kv=INVALID_HANDLE, bool:show=true);
   380 
   381 /**
   382  * Creates a HUD synchronization object.  This object is used to automatically assign and 
   383  * re-use channels for a set of messages.  
   384  *
   385  * The HUD has a hardcoded number of channels (usually 6) for displaying 
   386  * text.  You can use any channel for any area of the screen.  Text on 
   387  * different channels can overlap, but text on the same channel will 
   388  * erase the old text first.  This overlapping and overwriting gets problematic.
   389  *
   390  * A HUD synchronization object automatically selects channels for you based on 
   391  * the following heuristics:
   392  *  - If channel X was last used by the object, and hasn't been modified again, 
   393  *    channel X gets re-used.
   394  *  - Otherwise, a new channel is chosen based on the least-recently-used channel.
   395  *
   396  * This ensures that if you display text on a sync object, that the previous text 
   397  * displayed on it will always be cleared first.  This is because your new text 
   398  * will either overwrite the old text on the same channel, or because another 
   399  * channel has already erased your text.
   400  *
   401  * Note that messages can still overlap if they are on different synchronization 
   402  * objects, or they are displayed to manual channels.
   403  *
   404  * These are particularly useful for displaying repeating or refreshing HUD text, in 
   405  * addition to displaying multiple message sets in one area of the screen (for example, 
   406  * center-say messages that may pop up randomly that you don't want to overlap each 
   407  * other).
   408  *
   409  * @return				New HUD synchronization object.
   410  *						The Handle can be closed with CloseHandle().
   411  *						If HUD text is not supported on this mod, then 
   412  *						INVALID_HANDLE is returned.
   413  */
   414 native Handle:CreateHudSynchronizer();
   415 
   416 /**
   417  * Sets the HUD parameters for drawing text.  These parameters are stored 
   418  * globally, although nothing other than this function and SetHudTextParamsEx 
   419  * modify them.
   420  *
   421  * You must call this function before drawing text.  If you are drawing 
   422  * text to multiple clients, you can set the parameters once, since 
   423  * they won't be modified.  However, as soon as you pass control back 
   424  * to other plugins, you must reset the parameters next time you draw.
   425  *
   426  * @param x				x coordinate, from 0 to 1.  -1.0 is the center.
   427  * @param y				y coordinate, from 0 to 1.  -1.0 is the center.
   428  * @param holdTime		Number of seconds to hold the text.
   429  * @param r				Red color value.
   430  * @param g				Green color value.
   431  * @param b				Blue color value.
   432  * @param a				Alpha transparency value.
   433  * @param effect 		0/1 causes the text to fade in and fade out.
   434  *						2 causes the text to flash[?].
   435  * @param fxTime		Duration of chosen effect (may not apply to all effects).
   436  * @param fadeIn		Number of seconds to spend fading in.
   437  * @param fadeOut		Number of seconds to spend fading out.
   438  * @noreturn
   439  */
   440 native SetHudTextParams(Float:x, Float:y, Float:holdTime, r, g, b, a, effect = 0,
   441 						Float:fxTime=6.0, Float:fadeIn=0.1, Float:fadeOut=0.2);
   442 						
   443 /**
   444  * Sets the HUD parameters for drawing text.  These parameters are stored 
   445  * globally, although nothing other than this function and SetHudTextParams
   446  * modify them.
   447  *
   448  * This is the same as SetHudTextParams(), except it lets you set the alternate 
   449  * color for when effects require it.  
   450  *
   451  * @param x				x coordinate, from 0 to 1.  -1.0 is the center.
   452  * @param y				y coordinate, from 0 to 1.  -1.0 is the center.
   453  * @param holdTime		Number of seconds to hold the text.
   454  * @param color1		First color set, array values being [red, green, blue, alpha]
   455  * @param color2		Second color set, array values being [red, green, blue, alpha]
   456  * @param effect 		0/1 causes the text to fade in and fade out.
   457  *						2 causes the text to flash[?].
   458  * @param fxTime		Duration of chosen effect (may not apply to all effects).
   459  * @param fadeIn		Number of seconds to spend fading in.
   460  * @param fadeOut		Number of seconds to spend fading out.
   461  * @noreturn
   462  */
   463 native SetHudTextParamsEx(Float:x, Float:y, Float:holdTime, color1[4], 
   464 						  color2[4]={255,255,255,0}, effect = 0, Float:fxTime=6.0, 
   465 						  Float:fadeIn=0.1, Float:fadeOut=0.2);
   466 
   467 /**
   468  * Shows a synchronized HUD message to a client.  
   469  *
   470  * As of this writing, only TF, HL2MP, and SourceForts support HUD Text.
   471  *
   472  * @param client		Client index to send the message to.
   473  * @param sync			Synchronization object.
   474  * @param message		Message text or formatting rules.
   475  * @param ...			Message formatting parameters.
   476  * @return				-1 on failure, anything else on success.
   477  *						This function fails if the mod does not support it.
   478  * @error				Client not in-game, or sync object not valid.
   479  */
   480 native ShowSyncHudText(client, Handle:sync, const String:message[], any:...);
   481 
   482 /**
   483  * Clears the text on a synchronized HUD channel. 
   484  *
   485  * This is not the same as sending "" because it guarantees that it won't 
   486  * overwrite text on another channel.  For example, consider the scenario: 
   487  *
   488  * 1. Your synchronized message goes to channel 3.
   489  * 2. Someone else's non-synchronized message goes to channel 3.
   490  *
   491  * If you were to simply send "" on your synchronized message, 
   492  * then someone else's text could be overwritten.
   493  *
   494  * @param client		Client index to send the message to.
   495  * @param sync			Synchronization object.
   496  * @noreturn
   497  * @error				Client not in-game, or sync object not valid.
   498  */
   499 native ClearSyncHud(client, Handle:sync);
   500 
   501 /**
   502  * Shows a HUD message to a client on the given channel.
   503  *
   504  * As of this writing, only TF, HL2MP, and SourceForts support HUD Text.
   505  * 
   506  * @param client		Client index to send the message to.
   507  * @param channel		A channel number.
   508  *						If -1, then a channel will automatically be selected 
   509  *						based on the least-recently-used channel.  If the 
   510  *						channel is any other number, it will be modulo'd with 
   511  *						the channel count to get a final channel number.
   512  * @param message		Message text or formatting rules.
   513  * @param ...			Message formatting parameters.
   514  * @return				-1 on failure (lack of mod support).
   515  *						Any other return value is the channel number that was 
   516  *						used to render the text.
   517  */
   518 native ShowHudText(client, channel, const String:message[], any:...);
   519 
   520 /**
   521  * Shows a MOTD panel to a specific client.
   522  *
   523  * @param client		Client index.
   524  * @param title			Title of the panel (printed on the top border of the window).
   525  * @param msg			Contents of the panel, it can be treated as an url, filename or plain text
   526  *				 		depending on the type parameter (WARNING: msg has to be 192 bytes maximum!)
   527  * @param type			Determines the way to treat the message body of the panel.
   528  * @noreturn
   529  * @error				If the client is not connected an error will be thrown.
   530  */
   531 stock ShowMOTDPanel(client, const String:title[], const String:msg[], type=MOTDPANEL_TYPE_INDEX)
   532 {
   533 	decl String:num[3];
   534 	new Handle:Kv = CreateKeyValues("data");
   535 	IntToString(type, num, sizeof(num));
   536 
   537 	KvSetString(Kv, "title", title);
   538 	KvSetString(Kv, "type", num);
   539 	KvSetString(Kv, "msg", msg);
   540 	ShowVGUIPanel(client, "info", Kv);
   541 	CloseHandle(Kv);
   542 }
   543 
   544 /**
   545  * Displays a panel asking the client to connect to a specified IP.
   546  *
   547  * @param client		Client index.
   548  * @param time			Duration to hold the panel on the client's screen.
   549  * @param ip			Destionation IP.
   550  * @noreturn
   551  */
   552 stock DisplayAskConnectBox(client, Float:time, const String:ip[])
   553 {
   554 	new Handle:Kv = CreateKeyValues("data");
   555 	KvSetFloat(Kv, "time", time);
   556 	KvSetString(Kv, "title", ip);
   557 	CreateDialog(client, Kv, DialogType_AskConnect);
   558 	CloseHandle(Kv);
   559 }
   560 
   561 /**
   562  * Converts an entity index into a serial encoded entity reference.
   563  *
   564  * @param entity		Entity index.
   565  * @return				Entity reference.
   566  */
   567 native EntIndexToEntRef(entity);
   568 
   569 /**
   570  * Retrieves the entity index from a reference.
   571  *
   572  * @param ref			Entity reference.
   573  * @return				Entity index.
   574  */
   575 native EntRefToEntIndex(ref);
   576 
   577 /**
   578  * Converts a reference into a backwards compatible version.
   579  *
   580  * @param ref			Entity reference.
   581  * @return				Bcompat reference.
   582  */
   583 native MakeCompatEntRef(ref);
   584