plugins/include/halflife.inc
author David Anderson <dvander@alliedmods.net>
Wed Feb 27 13:46:41 2008 +0000 (2008-02-27)
changeset 1899 65e152e87873
parent 1837 652038bb27e6
child 1915 ab031366cfd1
permissions -rw-r--r--
fixed amb1487 (sm_slap for negative damage)
ds@873
     1
/**
ds@873
     2
 * vim: set ts=4 :
ds@1330
     3
 * =============================================================================
ds@873
     4
 * SourceMod (C)2004-2007 AlliedModders LLC.  All rights reserved.
ds@1330
     5
 * =============================================================================
ds@1330
     6
 *
ds@1330
     7
 * This file is part of the SourceMod/SourcePawn SDK.
ds@873
     8
 *
ds@1330
     9
 * This program is free software; you can redistribute it and/or modify it under
ds@1330
    10
 * the terms of the GNU General Public License, version 3.0, as published by the
ds@1330
    11
 * Free Software Foundation.
ds@1330
    12
 * 
ds@1330
    13
 * This program is distributed in the hope that it will be useful, but WITHOUT
ds@1330
    14
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
ds@1330
    15
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
ds@1330
    16
 * details.
ds@1330
    17
 *
ds@1330
    18
 * You should have received a copy of the GNU General Public License along with
ds@1330
    19
 * this program.  If not, see <http://www.gnu.org/licenses/>.
ds@1330
    20
 *
ds@1330
    21
 * As a special exception, AlliedModders LLC gives you permission to link the
ds@1330
    22
 * code of this program (as well as its derivative works) to "Half-Life 2," the
ds@1330
    23
 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
ds@1330
    24
 * by the Valve Corporation.  You must obey the GNU General Public License in
ds@1330
    25
 * all respects for all other code used.  Additionally, AlliedModders LLC grants
ds@1330
    26
 * this exception to all derivative works.  AlliedModders LLC defines further
ds@1330
    27
 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
ds@1330
    28
 * or <http://www.sourcemod.net/license.php>.
ds@873
    29
 *
ds@873
    30
 * Version: $Id$
ds@873
    31
 */
ds@873
    32
ds@873
    33
#if defined _halflife_included
ds@873
    34
 #endinput
ds@873
    35
#endif
ds@873
    36
#define _halflife_included
ds@873
    37
dvander@1837
    38
#define SOURCE_SDK_UNKNOWN			0		/**< Could not determine the engine version */
dvander@1837
    39
#define SOURCE_SDK_ORIGINAL			10		/**< Original Source engine (still used by "The Ship") */
dvander@1837
    40
#define SOURCE_SDK_EPISODE1			20		/**< SDK+Engine released after Episode 1 */
dvander@1837
    41
#define SOURCE_SDK_EPISODE2			30		/**< Engine released after Episode 2 (no SDK yet) */
dvander@1837
    42
faluco@1218
    43
#define MOTDPANEL_TYPE_TEXT		0	/**< Treat msg as plain text */
dvander@1837
    44
#define MOTDPANEL_TYPE_INDEX	1	/**< Msg is auto determined by the engine */
faluco@1218
    45
#define MOTDPANEL_TYPE_URL		2	/**< Treat msg as an URL link */
faluco@1218
    46
#define MOTDPANEL_TYPE_FILE		3	/**< Treat msg as a filename to be openned */
faluco@1218
    47
ds@873
    48
enum DialogType
ds@873
    49
{
ds@873
    50
	DialogType_Msg = 0,		/**< just an on screen message */
ds@873
    51
	DialogType_Menu, 		/**< an options menu */
ds@873
    52
	DialogType_Text, 		/**< a richtext dialog */
faluco@1413
    53
	DialogType_Entry, 		/**< an entry box */
faluco@1413
    54
	DialogType_AskConnect		/**< ask the client to connect to a specified IP */
ds@873
    55
};
ds@873
    56
ds@873
    57
/**
ds@873
    58
 * Logs a generic message to the HL2 logs.
ds@873
    59
 *
ds@873
    60
 * @param format		String format.
ds@873
    61
 * @param ...			Format arguments.
ds@873
    62
 * @noreturn
ds@873
    63
 */
ds@873
    64
native LogToGame(const String:format[], any:...);
ds@873
    65
ds@873
    66
/**
dvander@1003
    67
 * Sets the seed value for the global Half-Life 2 Random Stream.
ds@873
    68
 *
ds@873
    69
 * @param seed			Seed value.
ds@873
    70
 * @noreturn	
ds@873
    71
 */
ds@873
    72
native SetRandomSeed(seed);
ds@873
    73
ds@873
    74
/**
dvander@1003
    75
 * Returns a random floating point number from the Half-Life 2 Random Stream.
ds@873
    76
 *
ds@873
    77
 * @param fMin			Minimum random bound.
ds@873
    78
 * @param fMax			Maximum random bound.
ds@873
    79
 * @return				A random number between (inclusive) fMin and fMax.
ds@873
    80
 */
ds@873
    81
native Float:GetRandomFloat(Float:fMin=0.0, Float:fMax=1.0);
ds@873
    82
ds@873
    83
/**
dvander@1003
    84
 * Returns a random number from the Half-Life 2 Random Stream.
ds@873
    85
 *
ds@873
    86
 * @param nmin			Minimum random bound.
ds@873
    87
 * @param nmax			Maximum random bound.
ds@873
    88
 * @return				A random number between (inclusive) nmin and nmax.
ds@873
    89
 */
ds@873
    90
native GetRandomInt(nmin, nmax);
ds@873
    91
ds@873
    92
/**
ds@873
    93
 * Returns whether a map is valid or not.
ds@873
    94
 * 
ds@873
    95
 * @param 				Map name, excluding .bsp extension.
ds@873
    96
 * @return				True if valid, false otherwise.
ds@873
    97
 */
ds@873
    98
native bool:IsMapValid(const String:map[]);
ds@873
    99
ds@873
   100
/**
ds@873
   101
 * Returns whether the server is dedicated.
ds@873
   102
 *
ds@873
   103
 * @return				True if dedicated, false otherwise.
ds@873
   104
 */
ds@873
   105
native bool:IsDedicatedServer();
ds@873
   106
ds@873
   107
/**
ds@873
   108
 * Returns a high-precision time value for profiling the engine.
ds@873
   109
 *
ds@873
   110
 * @return				A floating point time value.
ds@873
   111
 */
ds@873
   112
native Float:GetEngineTime();
ds@873
   113
ds@873
   114
/** 
ds@873
   115
 * Returns the game time based on the game tick.
ds@873
   116
 *
ds@873
   117
 * @return				Game tick time.
ds@873
   118
 */
ds@873
   119
native Float:GetGameTime();
ds@873
   120
ds@873
   121
/**
ds@873
   122
 * Returns the game description from the mod.
ds@873
   123
 *
ds@873
   124
 * @param buffer		Buffer to store the description.
ds@873
   125
 * @param maxlength		Maximum size of the buffer.
ds@873
   126
 * @param original		If true, retrieves the original game description,
ds@873
   127
 *						ignoring any potential hooks from plugins.
ds@873
   128
 * @return				Number of bytes written to the buffer (UTF-8 safe).
ds@873
   129
 */
ds@873
   130
native GetGameDescription(String:buffer[], maxlength, bool:original=false);
ds@873
   131
ds@873
   132
/**
ds@873
   133
 * Returns the name of the game's directory.
ds@873
   134
 *
ds@873
   135
 * @param buffer		Buffer to store the directory name.
ds@873
   136
 * @param maxlength		Maximum size of the buffer.
ds@873
   137
 *
ds@873
   138
 * return				Number of bytes written to the buffer (UTF-8 safe).
ds@873
   139
 */
ds@873
   140
native GetGameFolderName(String:buffer[], maxlength);
ds@873
   141
ds@873
   142
/**
ds@873
   143
 * Returns the current map name.
ds@873
   144
 *
ds@873
   145
 * @param buffer		Buffer to store map name.
ds@873
   146
 * @param maxlength		Maximum length of buffer.
ds@873
   147
 * @return				Number of bytes written (UTF-8 safe).
ds@873
   148
 */
ds@873
   149
native GetCurrentMap(String:buffer[], maxlength);
ds@873
   150
ds@873
   151
/**
ds@873
   152
 * Precaches a given model.
ds@873
   153
 *
ds@873
   154
 * @param model			Name of the model to precache.
ds@873
   155
 * @param preload		If preload is true the file will be precached before level startup.
ds@892
   156
 * @return				Returns the model index, 0 for error.
ds@873
   157
 */
ds@873
   158
native PrecacheModel(const String:model[], bool:preload=false);
ds@873
   159
ds@873
   160
/**
ds@873
   161
 * Precaches a given sentence file.
ds@873
   162
 *
ds@873
   163
 * @param file			Name of the sentence file to precache.
ds@873
   164
 * @param preload		If preload is true the file will be precached before level startup.
ds@892
   165
 * @return				Returns a sentence file index.
ds@873
   166
 */
ds@873
   167
native PrecacheSentenceFile(const String:file[], bool:preload=false);
ds@873
   168
ds@873
   169
/**
ds@873
   170
 * Precaches a given decal.
ds@873
   171
 *
ds@873
   172
 * @param decal			Name of the decal to precache.
ds@873
   173
 * @param preload		If preload is true the file will be precached before level startup.
ds@892
   174
 * @return				Returns a decal index.
ds@873
   175
 */
ds@873
   176
native PrecacheDecal(const String:decal[], bool:preload=false);
ds@873
   177
ds@873
   178
/**
ds@873
   179
 * Precaches a given generic file.
ds@873
   180
 *
ds@873
   181
 * @param generic		Name of the generic file to precache.
ds@873
   182
 * @param preload		If preload is true the file will be precached before level startup.
ds@892
   183
 * @return				Returns a generic file index.
ds@873
   184
 */
ds@873
   185
native PrecacheGeneric(const String:generic[], bool:preload=false);
ds@873
   186
ds@873
   187
/**
ds@873
   188
 * Returns if a given model is precached.
ds@873
   189
 *
ds@873
   190
 * @param model			Name of the model to check.
ds@892
   191
 * @return				True if precached, false otherwise.
ds@873
   192
 */
ds@873
   193
native bool:IsModelPrecached(const String:model[]);
ds@873
   194
ds@873
   195
/**
ds@873
   196
 * Returns if a given decal is precached.
ds@873
   197
 *
ds@873
   198
 * @param decal			Name of the decal to check.
ds@892
   199
 * @return				True if precached, false otherwise.
ds@873
   200
 */
ds@873
   201
native bool:IsDecalPrecached(const String:decal[]);
ds@873
   202
ds@873
   203
/**
ds@873
   204
 * Returns if a given generic file is precached.
ds@873
   205
 *
ds@873
   206
 * @param decal			Name of the generic file to check.
ds@892
   207
 * @return				True if precached, false otherwise.
ds@873
   208
 */
ds@873
   209
native bool:IsGenericPrecached(const String:generic[]);
ds@873
   210
ds@873
   211
/**
ds@873
   212
 * Precaches a given sound.
ds@873
   213
 *
ds@873
   214
 * @param sound			Name of the sound to precache.
ds@873
   215
 * @param preload		If preload is true the file will be precached before level startup.
ds@892
   216
 * @return				True if successfully precached, false otherwise.
ds@873
   217
 */
ds@873
   218
native bool:PrecacheSound(const String:sound[], bool:preload=false);
ds@873
   219
ds@873
   220
/**
ds@873
   221
 * Returns if a given sound is precached.
ds@873
   222
 *
ds@873
   223
 * @param sound			Name of the sound to check.
ds@892
   224
 * @return				True if precached, false otherwise.
ds@873
   225
 */
ds@873
   226
native bool:IsSoundPrecached(const String:sound[]);
ds@873
   227
ds@873
   228
/**
ds@873
   229
 * Creates different types of ingame messages.
ds@873
   230
 *
ds@873
   231
 * @param client		Index of the client.
ds@873
   232
 * @param kv			KeyValues handle to set the menu keys and options. (Check iserverplugin.h for more information).
ds@873
   233
 * @param type			Message type to display ingame.
ds@873
   234
 * @noreturn
ds@873
   235
 * @error				Invalid client index, or client not connected.
ds@873
   236
 */
ds@873
   237
native CreateDialog(client, Handle:kv, DialogType:type);
ds@873
   238
ds@873
   239
/**
dvander@1837
   240
 * Guesses the SDK version a mod was compiled against.  If nothing 
dvander@1837
   241
 * specific is known about the game, the engine version is used instead.
dvander@1837
   242
 *
dvander@1837
   243
 * The return values are guaranteed to increase chronologically (that is, 
dvander@1837
   244
 * a later release will have a higher value).
dvander@1837
   245
 *
dvander@1837
   246
 * @return				SOURCE_SDK version code.
dvander@1837
   247
 */
dvander@1837
   248
native GuessSDKVersion();
dvander@1837
   249
dvander@1837
   250
/**
ds@892
   251
 * Prints a message to a specific client in the chat area.
ds@873
   252
 *
ds@892
   253
 * @param client		Client index.
ds@873
   254
 * @param format		Formatting rules.
ds@873
   255
 * @param ...			Variable number of format parameters.
ds@873
   256
 * @noreturn
ds@873
   257
 * @error				If the client is not connected an error will be thrown.
ds@873
   258
 */
ds@873
   259
native PrintToChat(client, const String:format[], any:...);
ds@873
   260
ds@873
   261
/**
ds@892
   262
 * Prints a message to all clients in the chat area.
ds@873
   263
 *
ds@892
   264
 * @param format		Formatting rules.
ds@892
   265
 * @param ...			Variable number of format parameters.
ds@892
   266
 * @noreturn
ds@892
   267
 */
ds@892
   268
stock PrintToChatAll(const String:format[], any:...)
ds@892
   269
{
ds@915
   270
	new maxClients = GetMaxClients();
ds@898
   271
	decl String:buffer[192];
ds@892
   272
	
ds@915
   273
	for (new i = 1; i <= maxClients; i++)
ds@892
   274
	{
ds@892
   275
		if (IsClientInGame(i))
ds@892
   276
		{
dvander@1034
   277
			SetGlobalTransTarget(i);
dvander@1034
   278
			VFormat(buffer, sizeof(buffer), format, 2);
ds@892
   279
			PrintToChat(i, "%s", buffer);
ds@892
   280
		}
ds@892
   281
	}
ds@892
   282
}
ds@892
   283
ds@892
   284
/**
ds@892
   285
 * Prints a message to a specific client in the center of the screen.
ds@892
   286
 *
ds@892
   287
 * @param client		Client index.
ds@873
   288
 * @param format		Formatting rules.
ds@873
   289
 * @param ...			Variable number of format parameters.
ds@873
   290
 * @noreturn
ds@873
   291
 * @error				If the client is not connected an error will be thrown.
ds@873
   292
 */
ds@873
   293
native PrintCenterText(client, const String:format[], any:...);
ds@892
   294
ds@892
   295
/**
ds@892
   296
 * Prints a message to all clients in the center of the screen.
ds@892
   297
 *
ds@892
   298
 * @param format		Formatting rules.
ds@892
   299
 * @param ...			Variable number of format parameters.
ds@892
   300
 * @noreturn
ds@892
   301
 */
ds@892
   302
stock PrintCenterTextAll(const String:format[], any:...)
ds@892
   303
{
ds@915
   304
	new maxClients = GetMaxClients();
ds@898
   305
	decl String:buffer[192];
teame06@1217
   306
ds@915
   307
	for (new i = 1; i <= maxClients; i++)
ds@892
   308
	{
ds@892
   309
		if (IsClientInGame(i))
ds@892
   310
		{
teame06@1217
   311
			SetGlobalTransTarget(i);
teame06@1217
   312
			VFormat(buffer, sizeof(buffer), format, 2);
ds@892
   313
			PrintCenterText(i, "%s", buffer);
ds@892
   314
		}
ds@892
   315
	}
ds@892
   316
}
faluco@1218
   317
faluco@1218
   318
/**
faluco@1218
   319
 * Prints a message to a specific client with a hint box.
faluco@1218
   320
 *
faluco@1218
   321
 * @param client		Client index.
faluco@1218
   322
 * @param format		Formatting rules.
faluco@1218
   323
 * @param ...			Variable number of format parameters.
faluco@1218
   324
 * @noreturn
faluco@1218
   325
 * @error				If the client is not connected an error will be thrown.
faluco@1218
   326
 */
faluco@1218
   327
native PrintHintText(client, const String:format[], any:...);
faluco@1218
   328
faluco@1218
   329
/**
faluco@1218
   330
 * Prints a message to all clients with a hint box.
faluco@1218
   331
 *
faluco@1218
   332
 * @param format		Formatting rules.
faluco@1218
   333
 * @param ...			Variable number of format parameters.
faluco@1218
   334
 * @noreturn
faluco@1218
   335
 */
faluco@1218
   336
stock PrintHintTextToAll(const String:format[], any:...)
faluco@1218
   337
{
faluco@1218
   338
	new maxClients = GetMaxClients();
faluco@1218
   339
	decl String:buffer[192];
faluco@1218
   340
	
faluco@1218
   341
	for (new i = 1; i <= maxClients; i++)
faluco@1218
   342
	{
faluco@1218
   343
		if (IsClientInGame(i))
faluco@1218
   344
		{
faluco@1218
   345
			SetGlobalTransTarget(i);
faluco@1218
   346
			VFormat(buffer, sizeof(buffer), format, 2);
faluco@1218
   347
			PrintHintText(i, "%s", buffer);
faluco@1218
   348
		}
faluco@1218
   349
	}
faluco@1218
   350
}
faluco@1218
   351
faluco@1218
   352
/**
faluco@1218
   353
 * Shows a VGUI panel to a specific client.
faluco@1218
   354
 *
faluco@1218
   355
 * @param client		Client index.
faluco@1218
   356
 * @param name			Panel type name (Check viewport_panel_names.h to see a list of some panel names).
faluco@1218
   357
 * @param Kv			KeyValues handle with all the data for the panel setup (Depends on the panel type and may be unused).
faluco@1218
   358
 * @param show			True to show the panel, or false to remove it from the client screen.
faluco@1218
   359
 * @noreturn
faluco@1218
   360
 * @error				If the client is not connected an error will be thrown.
faluco@1218
   361
 */
faluco@1218
   362
native ShowVGUIPanel(client, const String:name[], Handle:Kv=INVALID_HANDLE, bool:show=true);
faluco@1218
   363
faluco@1218
   364
/**
faluco@1218
   365
 * Shows a MOTD panel to a specific client.
faluco@1218
   366
 *
faluco@1218
   367
 * @param client		Client index.
faluco@1218
   368
 * @param title			Title of the panel (printed on the top border of the window).
faluco@1218
   369
 * @param msg			Contents of the panel, it can be treated as an url, filename or plain text
faluco@1218
   370
 *				  depending on the type parameter (WARNING: msg has to be 192 bytes maximum!)
faluco@1218
   371
 * @param type			Determines the way to treat the message body of the panel.
faluco@1218
   372
 * @noreturn
faluco@1218
   373
 * @error				If the client is not connected an error will be thrown.
faluco@1218
   374
 */
faluco@1218
   375
stock ShowMOTDPanel(client, const String:title[], const String:msg[], type=MOTDPANEL_TYPE_INDEX)
faluco@1218
   376
{
faluco@1218
   377
	decl String:num[3];
faluco@1218
   378
	new Handle:Kv = CreateKeyValues("data");
faluco@1218
   379
	IntToString(type, num, sizeof(num));
faluco@1218
   380
faluco@1218
   381
	KvSetString(Kv, "title", title);
faluco@1218
   382
	KvSetString(Kv, "type", num);
faluco@1218
   383
	KvSetString(Kv, "msg", msg);
faluco@1218
   384
	ShowVGUIPanel(client, "info", Kv);
faluco@1218
   385
	CloseHandle(Kv);
faluco@1218
   386
}
faluco@1413
   387
faluco@1413
   388
/**
faluco@1413
   389
 * Displays a panel asking the client to connect to a specified IP.
faluco@1413
   390
 *
faluco@1413
   391
 * @param client		Client index.
faluco@1413
   392
 * @param time			Duration to hold the panel on the client's screen.
faluco@1413
   393
 * @param ip			Destionation IP.
faluco@1413
   394
 * @noreturn
faluco@1413
   395
 */
faluco@1413
   396
stock DisplayAskConnectBox(client, Float:time, const String:ip[])
faluco@1413
   397
{
faluco@1413
   398
	new Handle:Kv = CreateKeyValues("data");
faluco@1413
   399
	KvSetFloat(Kv, "time", time);
faluco@1413
   400
	KvSetString(Kv, "title", ip);
faluco@1413
   401
	CreateDialog(client, Kv, DialogType_AskConnect);
faluco@1413
   402
	CloseHandle(Kv);
faluco@1413
   403
}