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