plugins/include/halflife.inc
author Phong Dang <teame06@gmail.com>
Wed Aug 01 18:22:53 2007 +0000 (2007-08-01)
changeset 1245 bb0611ab4bed
parent 1218 a4e82ef4e7ef
child 1330 ab94316bb52b
permissions -rw-r--r--
Updated license header.
     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 _halflife_included
    17  #endinput
    18 #endif
    19 #define _halflife_included
    20 
    21 #define MOTDPANEL_TYPE_TEXT		0	/**< Treat msg as plain text */
    22 #define MOTDPANEL_TYPE_INDEX		1	/**< Msg is auto determined by the engine */
    23 #define MOTDPANEL_TYPE_URL		2	/**< Treat msg as an URL link */
    24 #define MOTDPANEL_TYPE_FILE		3	/**< Treat msg as a filename to be openned */
    25 
    26 enum DialogType
    27 {
    28 	DialogType_Msg = 0,		/**< just an on screen message */
    29 	DialogType_Menu, 		/**< an options menu */
    30 	DialogType_Text, 		/**< a richtext dialog */
    31 	DialogType_Entry 		/**< an entry box */
    32 };
    33 
    34 /**
    35  * Logs a generic message to the HL2 logs.
    36  *
    37  * @param format		String format.
    38  * @param ...			Format arguments.
    39  * @noreturn
    40  */
    41 native LogToGame(const String:format[], any:...);
    42 
    43 /**
    44  * Sets the seed value for the global Half-Life 2 Random Stream.
    45  *
    46  * @param seed			Seed value.
    47  * @noreturn	
    48  */
    49 native SetRandomSeed(seed);
    50 
    51 /**
    52  * Returns a random floating point number from the Half-Life 2 Random Stream.
    53  *
    54  * @param fMin			Minimum random bound.
    55  * @param fMax			Maximum random bound.
    56  * @return				A random number between (inclusive) fMin and fMax.
    57  */
    58 native Float:GetRandomFloat(Float:fMin=0.0, Float:fMax=1.0);
    59 
    60 /**
    61  * Returns a random number from the Half-Life 2 Random Stream.
    62  *
    63  * @param nmin			Minimum random bound.
    64  * @param nmax			Maximum random bound.
    65  * @return				A random number between (inclusive) nmin and nmax.
    66  */
    67 native GetRandomInt(nmin, nmax);
    68 
    69 /**
    70  * Returns whether a map is valid or not.
    71  * 
    72  * @param 				Map name, excluding .bsp extension.
    73  * @return				True if valid, false otherwise.
    74  */
    75 native bool:IsMapValid(const String:map[]);
    76 
    77 /**
    78  * Returns whether the server is dedicated.
    79  *
    80  * @return				True if dedicated, false otherwise.
    81  */
    82 native bool:IsDedicatedServer();
    83 
    84 /**
    85  * Returns a high-precision time value for profiling the engine.
    86  *
    87  * @return				A floating point time value.
    88  */
    89 native Float:GetEngineTime();
    90 
    91 /** 
    92  * Returns the game time based on the game tick.
    93  *
    94  * @return				Game tick time.
    95  */
    96 native Float:GetGameTime();
    97 
    98 /**
    99  * Returns the game description from the mod.
   100  *
   101  * @param buffer		Buffer to store the description.
   102  * @param maxlength		Maximum size of the buffer.
   103  * @param original		If true, retrieves the original game description,
   104  *						ignoring any potential hooks from plugins.
   105  * @return				Number of bytes written to the buffer (UTF-8 safe).
   106  */
   107 native GetGameDescription(String:buffer[], maxlength, bool:original=false);
   108 
   109 /**
   110  * Returns the name of the game's directory.
   111  *
   112  * @param buffer		Buffer to store the directory name.
   113  * @param maxlength		Maximum size of the buffer.
   114  *
   115  * return				Number of bytes written to the buffer (UTF-8 safe).
   116  */
   117 native GetGameFolderName(String:buffer[], maxlength);
   118 
   119 /**
   120  * Returns the current map name.
   121  *
   122  * @param buffer		Buffer to store map name.
   123  * @param maxlength		Maximum length of buffer.
   124  * @return				Number of bytes written (UTF-8 safe).
   125  */
   126 native GetCurrentMap(String:buffer[], maxlength);
   127 
   128 /**
   129  * Precaches a given model.
   130  *
   131  * @param model			Name of the model to precache.
   132  * @param preload		If preload is true the file will be precached before level startup.
   133  * @return				Returns the model index, 0 for error.
   134  */
   135 native PrecacheModel(const String:model[], bool:preload=false);
   136 
   137 /**
   138  * Precaches a given sentence file.
   139  *
   140  * @param file			Name of the sentence file to precache.
   141  * @param preload		If preload is true the file will be precached before level startup.
   142  * @return				Returns a sentence file index.
   143  */
   144 native PrecacheSentenceFile(const String:file[], bool:preload=false);
   145 
   146 /**
   147  * Precaches a given decal.
   148  *
   149  * @param decal			Name of the decal to precache.
   150  * @param preload		If preload is true the file will be precached before level startup.
   151  * @return				Returns a decal index.
   152  */
   153 native PrecacheDecal(const String:decal[], bool:preload=false);
   154 
   155 /**
   156  * Precaches a given generic file.
   157  *
   158  * @param generic		Name of the generic file to precache.
   159  * @param preload		If preload is true the file will be precached before level startup.
   160  * @return				Returns a generic file index.
   161  */
   162 native PrecacheGeneric(const String:generic[], bool:preload=false);
   163 
   164 /**
   165  * Returns if a given model is precached.
   166  *
   167  * @param model			Name of the model to check.
   168  * @return				True if precached, false otherwise.
   169  */
   170 native bool:IsModelPrecached(const String:model[]);
   171 
   172 /**
   173  * Returns if a given decal is precached.
   174  *
   175  * @param decal			Name of the decal to check.
   176  * @return				True if precached, false otherwise.
   177  */
   178 native bool:IsDecalPrecached(const String:decal[]);
   179 
   180 /**
   181  * Returns if a given generic file is precached.
   182  *
   183  * @param decal			Name of the generic file to check.
   184  * @return				True if precached, false otherwise.
   185  */
   186 native bool:IsGenericPrecached(const String:generic[]);
   187 
   188 /**
   189  * Precaches a given sound.
   190  *
   191  * @param sound			Name of the sound to precache.
   192  * @param preload		If preload is true the file will be precached before level startup.
   193  * @return				True if successfully precached, false otherwise.
   194  */
   195 native bool:PrecacheSound(const String:sound[], bool:preload=false);
   196 
   197 /**
   198  * Returns if a given sound is precached.
   199  *
   200  * @param sound			Name of the sound to check.
   201  * @return				True if precached, false otherwise.
   202  */
   203 native bool:IsSoundPrecached(const String:sound[]);
   204 
   205 /**
   206  * Creates different types of ingame messages.
   207  *
   208  * @param client		Index of the client.
   209  * @param kv			KeyValues handle to set the menu keys and options. (Check iserverplugin.h for more information).
   210  * @param type			Message type to display ingame.
   211  * @noreturn
   212  * @error				Invalid client index, or client not connected.
   213  */
   214 native CreateDialog(client, Handle:kv, DialogType:type);
   215 
   216 /**
   217  * Prints a message to a specific client in the chat area.
   218  *
   219  * @param client		Client index.
   220  * @param format		Formatting rules.
   221  * @param ...			Variable number of format parameters.
   222  * @noreturn
   223  * @error				If the client is not connected an error will be thrown.
   224  */
   225 native PrintToChat(client, const String:format[], any:...);
   226 
   227 /**
   228  * Prints a message to all clients in the chat area.
   229  *
   230  * @param format		Formatting rules.
   231  * @param ...			Variable number of format parameters.
   232  * @noreturn
   233  */
   234 stock PrintToChatAll(const String:format[], any:...)
   235 {
   236 	new maxClients = GetMaxClients();
   237 	decl String:buffer[192];
   238 	
   239 	for (new i = 1; i <= maxClients; i++)
   240 	{
   241 		if (IsClientInGame(i))
   242 		{
   243 			SetGlobalTransTarget(i);
   244 			VFormat(buffer, sizeof(buffer), format, 2);
   245 			PrintToChat(i, "%s", buffer);
   246 		}
   247 	}
   248 }
   249 
   250 /**
   251  * Prints a message to a specific client in the center of the screen.
   252  *
   253  * @param client		Client index.
   254  * @param format		Formatting rules.
   255  * @param ...			Variable number of format parameters.
   256  * @noreturn
   257  * @error				If the client is not connected an error will be thrown.
   258  */
   259 native PrintCenterText(client, const String:format[], any:...);
   260 
   261 /**
   262  * Prints a message to all clients in the center of the screen.
   263  *
   264  * @param format		Formatting rules.
   265  * @param ...			Variable number of format parameters.
   266  * @noreturn
   267  */
   268 stock PrintCenterTextAll(const String:format[], any:...)
   269 {
   270 	new maxClients = GetMaxClients();
   271 	decl String:buffer[192];
   272 
   273 	for (new i = 1; i <= maxClients; i++)
   274 	{
   275 		if (IsClientInGame(i))
   276 		{
   277 			SetGlobalTransTarget(i);
   278 			VFormat(buffer, sizeof(buffer), format, 2);
   279 			PrintCenterText(i, "%s", buffer);
   280 		}
   281 	}
   282 }
   283 
   284 /**
   285  * Prints a message to a specific client with a hint box.
   286  *
   287  * @param client		Client index.
   288  * @param format		Formatting rules.
   289  * @param ...			Variable number of format parameters.
   290  * @noreturn
   291  * @error				If the client is not connected an error will be thrown.
   292  */
   293 native PrintHintText(client, const String:format[], any:...);
   294 
   295 /**
   296  * Prints a message to all clients with a hint box.
   297  *
   298  * @param format		Formatting rules.
   299  * @param ...			Variable number of format parameters.
   300  * @noreturn
   301  */
   302 stock PrintHintTextToAll(const String:format[], any:...)
   303 {
   304 	new maxClients = GetMaxClients();
   305 	decl String:buffer[192];
   306 	
   307 	for (new i = 1; i <= maxClients; i++)
   308 	{
   309 		if (IsClientInGame(i))
   310 		{
   311 			SetGlobalTransTarget(i);
   312 			VFormat(buffer, sizeof(buffer), format, 2);
   313 			PrintHintText(i, "%s", buffer);
   314 		}
   315 	}
   316 }
   317 
   318 /**
   319  * Shows a VGUI panel to a specific client.
   320  *
   321  * @param client		Client index.
   322  * @param name			Panel type name (Check viewport_panel_names.h to see a list of some panel names).
   323  * @param Kv			KeyValues handle with all the data for the panel setup (Depends on the panel type and may be unused).
   324  * @param show			True to show the panel, or false to remove it from the client screen.
   325  * @noreturn
   326  * @error				If the client is not connected an error will be thrown.
   327  */
   328 native ShowVGUIPanel(client, const String:name[], Handle:Kv=INVALID_HANDLE, bool:show=true);
   329 
   330 /**
   331  * Shows a MOTD panel to a specific client.
   332  *
   333  * @param client		Client index.
   334  * @param title			Title of the panel (printed on the top border of the window).
   335  * @param msg			Contents of the panel, it can be treated as an url, filename or plain text
   336  *				  depending on the type parameter (WARNING: msg has to be 192 bytes maximum!)
   337  * @param type			Determines the way to treat the message body of the panel.
   338  * @noreturn
   339  * @error				If the client is not connected an error will be thrown.
   340  */
   341 stock ShowMOTDPanel(client, const String:title[], const String:msg[], type=MOTDPANEL_TYPE_INDEX)
   342 {
   343 	decl String:num[3];
   344 	new Handle:Kv = CreateKeyValues("data");
   345 	IntToString(type, num, sizeof(num));
   346 
   347 	KvSetString(Kv, "title", title);
   348 	KvSetString(Kv, "type", num);
   349 	KvSetString(Kv, "msg", msg);
   350 	ShowVGUIPanel(client, "info", Kv);
   351 	CloseHandle(Kv);
   352 }