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