1.1 --- a/plugins/include/halflife.inc Fri Jul 11 06:51:21 2008 +0000
1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,544 +0,0 @@
1.4 -/**
1.5 - * vim: set ts=4 :
1.6 - * =============================================================================
1.7 - * SourceMod (C)2004-2008 AlliedModders LLC. All rights reserved.
1.8 - * =============================================================================
1.9 - *
1.10 - * This file is part of the SourceMod/SourcePawn SDK.
1.11 - *
1.12 - * This program is free software; you can redistribute it and/or modify it under
1.13 - * the terms of the GNU General Public License, version 3.0, as published by the
1.14 - * Free Software Foundation.
1.15 - *
1.16 - * This program is distributed in the hope that it will be useful, but WITHOUT
1.17 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
1.18 - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
1.19 - * details.
1.20 - *
1.21 - * You should have received a copy of the GNU General Public License along with
1.22 - * this program. If not, see <http://www.gnu.org/licenses/>.
1.23 - *
1.24 - * As a special exception, AlliedModders LLC gives you permission to link the
1.25 - * code of this program (as well as its derivative works) to "Half-Life 2," the
1.26 - * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
1.27 - * by the Valve Corporation. You must obey the GNU General Public License in
1.28 - * all respects for all other code used. Additionally, AlliedModders LLC grants
1.29 - * this exception to all derivative works. AlliedModders LLC defines further
1.30 - * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
1.31 - * or <http://www.sourcemod.net/license.php>.
1.32 - *
1.33 - * Version: $Id$
1.34 - */
1.35 -
1.36 -#if defined _halflife_included
1.37 - #endinput
1.38 -#endif
1.39 -#define _halflife_included
1.40 -
1.41 -#define SOURCE_SDK_UNKNOWN 0 /**< Could not determine the engine version */
1.42 -#define SOURCE_SDK_ORIGINAL 10 /**< Original Source engine (still used by "The Ship") */
1.43 -#define SOURCE_SDK_EPISODE1 20 /**< SDK+Engine released after Episode 1 */
1.44 -#define SOURCE_SDK_EPISODE2 30 /**< Engine released after Episode 2 (no SDK yet) */
1.45 -
1.46 -#define MOTDPANEL_TYPE_TEXT 0 /**< Treat msg as plain text */
1.47 -#define MOTDPANEL_TYPE_INDEX 1 /**< Msg is auto determined by the engine */
1.48 -#define MOTDPANEL_TYPE_URL 2 /**< Treat msg as an URL link */
1.49 -#define MOTDPANEL_TYPE_FILE 3 /**< Treat msg as a filename to be openned */
1.50 -
1.51 -enum DialogType
1.52 -{
1.53 - DialogType_Msg = 0, /**< just an on screen message */
1.54 - DialogType_Menu, /**< an options menu */
1.55 - DialogType_Text, /**< a richtext dialog */
1.56 - DialogType_Entry, /**< an entry box */
1.57 - DialogType_AskConnect /**< ask the client to connect to a specified IP */
1.58 -};
1.59 -
1.60 -/**
1.61 - * Logs a generic message to the HL2 logs.
1.62 - *
1.63 - * @param format String format.
1.64 - * @param ... Format arguments.
1.65 - * @noreturn
1.66 - */
1.67 -native LogToGame(const String:format[], any:...);
1.68 -
1.69 -/**
1.70 - * Sets the seed value for the global Half-Life 2 Random Stream.
1.71 - *
1.72 - * @param seed Seed value.
1.73 - * @noreturn
1.74 - */
1.75 -native SetRandomSeed(seed);
1.76 -
1.77 -/**
1.78 - * Returns a random floating point number from the Half-Life 2 Random Stream.
1.79 - *
1.80 - * @param fMin Minimum random bound.
1.81 - * @param fMax Maximum random bound.
1.82 - * @return A random number between (inclusive) fMin and fMax.
1.83 - */
1.84 -native Float:GetRandomFloat(Float:fMin=0.0, Float:fMax=1.0);
1.85 -
1.86 -/**
1.87 - * Returns a random number from the Half-Life 2 Random Stream.
1.88 - *
1.89 - * @param nmin Minimum random bound.
1.90 - * @param nmax Maximum random bound.
1.91 - * @return A random number between (inclusive) nmin and nmax.
1.92 - */
1.93 -native GetRandomInt(nmin, nmax);
1.94 -
1.95 -/**
1.96 - * Returns whether a map is valid or not.
1.97 - *
1.98 - * @param Map name, excluding .bsp extension.
1.99 - * @return True if valid, false otherwise.
1.100 - */
1.101 -native bool:IsMapValid(const String:map[]);
1.102 -
1.103 -/**
1.104 - * Returns whether the server is dedicated.
1.105 - *
1.106 - * @return True if dedicated, false otherwise.
1.107 - */
1.108 -native bool:IsDedicatedServer();
1.109 -
1.110 -/**
1.111 - * Returns a high-precision time value for profiling the engine.
1.112 - *
1.113 - * @return A floating point time value.
1.114 - */
1.115 -native Float:GetEngineTime();
1.116 -
1.117 -/**
1.118 - * Returns the game time based on the game tick.
1.119 - *
1.120 - * @return Game tick time.
1.121 - */
1.122 -native Float:GetGameTime();
1.123 -
1.124 -/**
1.125 - * Returns the game description from the mod.
1.126 - *
1.127 - * @param buffer Buffer to store the description.
1.128 - * @param maxlength Maximum size of the buffer.
1.129 - * @param original If true, retrieves the original game description,
1.130 - * ignoring any potential hooks from plugins.
1.131 - * @return Number of bytes written to the buffer (UTF-8 safe).
1.132 - */
1.133 -native GetGameDescription(String:buffer[], maxlength, bool:original=false);
1.134 -
1.135 -/**
1.136 - * Returns the name of the game's directory.
1.137 - *
1.138 - * @param buffer Buffer to store the directory name.
1.139 - * @param maxlength Maximum size of the buffer.
1.140 - *
1.141 - * return Number of bytes written to the buffer (UTF-8 safe).
1.142 - */
1.143 -native GetGameFolderName(String:buffer[], maxlength);
1.144 -
1.145 -/**
1.146 - * Returns the current map name.
1.147 - *
1.148 - * @param buffer Buffer to store map name.
1.149 - * @param maxlength Maximum length of buffer.
1.150 - * @return Number of bytes written (UTF-8 safe).
1.151 - */
1.152 -native GetCurrentMap(String:buffer[], maxlength);
1.153 -
1.154 -/**
1.155 - * Precaches a given model.
1.156 - *
1.157 - * @param model Name of the model to precache.
1.158 - * @param preload If preload is true the file will be precached before level startup.
1.159 - * @return Returns the model index, 0 for error.
1.160 - */
1.161 -native PrecacheModel(const String:model[], bool:preload=false);
1.162 -
1.163 -/**
1.164 - * Precaches a given sentence file.
1.165 - *
1.166 - * @param file Name of the sentence file to precache.
1.167 - * @param preload If preload is true the file will be precached before level startup.
1.168 - * @return Returns a sentence file index.
1.169 - */
1.170 -native PrecacheSentenceFile(const String:file[], bool:preload=false);
1.171 -
1.172 -/**
1.173 - * Precaches a given decal.
1.174 - *
1.175 - * @param decal Name of the decal to precache.
1.176 - * @param preload If preload is true the file will be precached before level startup.
1.177 - * @return Returns a decal index.
1.178 - */
1.179 -native PrecacheDecal(const String:decal[], bool:preload=false);
1.180 -
1.181 -/**
1.182 - * Precaches a given generic file.
1.183 - *
1.184 - * @param generic Name of the generic file to precache.
1.185 - * @param preload If preload is true the file will be precached before level startup.
1.186 - * @return Returns a generic file index.
1.187 - */
1.188 -native PrecacheGeneric(const String:generic[], bool:preload=false);
1.189 -
1.190 -/**
1.191 - * Returns if a given model is precached.
1.192 - *
1.193 - * @param model Name of the model to check.
1.194 - * @return True if precached, false otherwise.
1.195 - */
1.196 -native bool:IsModelPrecached(const String:model[]);
1.197 -
1.198 -/**
1.199 - * Returns if a given decal is precached.
1.200 - *
1.201 - * @param decal Name of the decal to check.
1.202 - * @return True if precached, false otherwise.
1.203 - */
1.204 -native bool:IsDecalPrecached(const String:decal[]);
1.205 -
1.206 -/**
1.207 - * Returns if a given generic file is precached.
1.208 - *
1.209 - * @param decal Name of the generic file to check.
1.210 - * @return True if precached, false otherwise.
1.211 - */
1.212 -native bool:IsGenericPrecached(const String:generic[]);
1.213 -
1.214 -/**
1.215 - * Precaches a given sound.
1.216 - *
1.217 - * @param sound Name of the sound to precache.
1.218 - * @param preload If preload is true the file will be precached before level startup.
1.219 - * @return True if successfully precached, false otherwise.
1.220 - */
1.221 -native bool:PrecacheSound(const String:sound[], bool:preload=false);
1.222 -
1.223 -/**
1.224 - * Returns if a given sound is precached.
1.225 - *
1.226 - * @param sound Name of the sound to check.
1.227 - * @return True if precached, false otherwise.
1.228 - */
1.229 -native bool:IsSoundPrecached(const String:sound[]);
1.230 -
1.231 -/**
1.232 - * Creates different types of ingame messages.
1.233 - *
1.234 - * @param client Index of the client.
1.235 - * @param kv KeyValues handle to set the menu keys and options. (Check iserverplugin.h for more information).
1.236 - * @param type Message type to display ingame.
1.237 - * @noreturn
1.238 - * @error Invalid client index, or client not connected.
1.239 - */
1.240 -native CreateDialog(client, Handle:kv, DialogType:type);
1.241 -
1.242 -/**
1.243 - * Guesses the SDK version a mod was compiled against. If nothing
1.244 - * specific is known about the game, the engine version is used instead.
1.245 - *
1.246 - * The return values are guaranteed to increase chronologically (that is,
1.247 - * a later release will have a higher value).
1.248 - *
1.249 - * @return SOURCE_SDK version code.
1.250 - */
1.251 -native GuessSDKVersion();
1.252 -
1.253 -/**
1.254 - * Prints a message to a specific client in the chat area.
1.255 - *
1.256 - * @param client Client index.
1.257 - * @param format Formatting rules.
1.258 - * @param ... Variable number of format parameters.
1.259 - * @noreturn
1.260 - * @error If the client is not connected an error will be thrown.
1.261 - */
1.262 -native PrintToChat(client, const String:format[], any:...);
1.263 -
1.264 -/**
1.265 - * Prints a message to all clients in the chat area.
1.266 - *
1.267 - * @param format Formatting rules.
1.268 - * @param ... Variable number of format parameters.
1.269 - * @noreturn
1.270 - */
1.271 -stock PrintToChatAll(const String:format[], any:...)
1.272 -{
1.273 - new maxClients = GetMaxClients();
1.274 - decl String:buffer[192];
1.275 -
1.276 - for (new i = 1; i <= maxClients; i++)
1.277 - {
1.278 - if (IsClientInGame(i))
1.279 - {
1.280 - SetGlobalTransTarget(i);
1.281 - VFormat(buffer, sizeof(buffer), format, 2);
1.282 - PrintToChat(i, "%s", buffer);
1.283 - }
1.284 - }
1.285 -}
1.286 -
1.287 -/**
1.288 - * Prints a message to a specific client in the center of the screen.
1.289 - *
1.290 - * @param client Client index.
1.291 - * @param format Formatting rules.
1.292 - * @param ... Variable number of format parameters.
1.293 - * @noreturn
1.294 - * @error If the client is not connected an error will be thrown.
1.295 - */
1.296 -native PrintCenterText(client, const String:format[], any:...);
1.297 -
1.298 -/**
1.299 - * Prints a message to all clients in the center of the screen.
1.300 - *
1.301 - * @param format Formatting rules.
1.302 - * @param ... Variable number of format parameters.
1.303 - * @noreturn
1.304 - */
1.305 -stock PrintCenterTextAll(const String:format[], any:...)
1.306 -{
1.307 - new maxClients = GetMaxClients();
1.308 - decl String:buffer[192];
1.309 -
1.310 - for (new i = 1; i <= maxClients; i++)
1.311 - {
1.312 - if (IsClientInGame(i))
1.313 - {
1.314 - SetGlobalTransTarget(i);
1.315 - VFormat(buffer, sizeof(buffer), format, 2);
1.316 - PrintCenterText(i, "%s", buffer);
1.317 - }
1.318 - }
1.319 -}
1.320 -
1.321 -/**
1.322 - * Prints a message to a specific client with a hint box.
1.323 - *
1.324 - * @param client Client index.
1.325 - * @param format Formatting rules.
1.326 - * @param ... Variable number of format parameters.
1.327 - * @noreturn
1.328 - * @error If the client is not connected an error will be thrown.
1.329 - */
1.330 -native PrintHintText(client, const String:format[], any:...);
1.331 -
1.332 -/**
1.333 - * Prints a message to all clients with a hint box.
1.334 - *
1.335 - * @param format Formatting rules.
1.336 - * @param ... Variable number of format parameters.
1.337 - * @noreturn
1.338 - */
1.339 -stock PrintHintTextToAll(const String:format[], any:...)
1.340 -{
1.341 - new maxClients = GetMaxClients();
1.342 - decl String:buffer[192];
1.343 -
1.344 - for (new i = 1; i <= maxClients; i++)
1.345 - {
1.346 - if (IsClientInGame(i))
1.347 - {
1.348 - SetGlobalTransTarget(i);
1.349 - VFormat(buffer, sizeof(buffer), format, 2);
1.350 - PrintHintText(i, "%s", buffer);
1.351 - }
1.352 - }
1.353 -}
1.354 -
1.355 -/**
1.356 - * Shows a VGUI panel to a specific client.
1.357 - *
1.358 - * @param client Client index.
1.359 - * @param name Panel type name (Check viewport_panel_names.h to see a list of
1.360 - * some panel names).
1.361 - * @param Kv KeyValues handle with all the data for the panel setup (Depends
1.362 - * on the panel type and may be unused).
1.363 - * @param show True to show the panel, or false to remove it from the client screen.
1.364 - * @noreturn
1.365 - * @error If the client is not connected an error will be thrown.
1.366 - */
1.367 -native ShowVGUIPanel(client, const String:name[], Handle:Kv=INVALID_HANDLE, bool:show=true);
1.368 -
1.369 -/**
1.370 - * Creates a HUD synchronization object. This object is used to automatically assign and
1.371 - * re-use channels for a set of messages.
1.372 - *
1.373 - * The HUD has a hardcoded number of channels (usually 6) for displaying
1.374 - * text. You can use any channel for any area of the screen. Text on
1.375 - * different channels can overlap, but text on the same channel will
1.376 - * erase the old text first. This overlapping and overwriting gets problematic.
1.377 - *
1.378 - * A HUD synchronization object automatically selects channels for you based on
1.379 - * the following heuristics:
1.380 - * - If channel X was last used by the object, and hasn't been modified again,
1.381 - * channel X gets re-used.
1.382 - * - Otherwise, a new channel is chosen based on the least-recently-used channel.
1.383 - *
1.384 - * This ensures that if you display text on a sync object, that the previous text
1.385 - * displayed on it will always be cleared first. This is because your new text
1.386 - * will either overwrite the old text on the same channel, or because another
1.387 - * channel has already erased your text.
1.388 - *
1.389 - * Note that messages can still overlap if they are on different synchronization
1.390 - * objects, or they are displayed to manual channels.
1.391 - *
1.392 - * These are particularly useful for displaying repeating or refreshing HUD text, in
1.393 - * addition to displaying multiple message sets in one area of the screen (for example,
1.394 - * center-say messages that may pop up randomly that you don't want to overlap each
1.395 - * other).
1.396 - *
1.397 - * @return New HUD synchronization object.
1.398 - * The Handle can be closed with CloseHandle().
1.399 - * If HUD text is not supported on this mod, then
1.400 - * INVALID_HANDLE is returned.
1.401 - */
1.402 -native Handle:CreateHudSynchronizer();
1.403 -
1.404 -/**
1.405 - * Sets the HUD parameters for drawing text. These parameters are stored
1.406 - * globally, although nothing other than this function and SetHudTextParamsEx
1.407 - * modify them.
1.408 - *
1.409 - * You must call this function before drawing text. If you are drawing
1.410 - * text to multiple clients, you can set the parameters once, since
1.411 - * they won't be modified. However, as soon as you pass control back
1.412 - * to other plugins, you must reset the parameters next time you draw.
1.413 - *
1.414 - * @param x x coordinate, from 0 to 1. -1.0 is the center.
1.415 - * @param y y coordinate, from 0 to 1. -1.0 is the center.
1.416 - * @param holdTime Number of seconds to hold the text.
1.417 - * @param r Red color value.
1.418 - * @param g Green color value.
1.419 - * @param b Blue color value.
1.420 - * @param a Alpha transparency value.
1.421 - * @param effect 0/1 causes the text to fade in and fade out.
1.422 - * 2 causes the text to flash[?].
1.423 - * @param fxTime Duration of chosen effect (may not apply to all effects).
1.424 - * @param fadeIn Number of seconds to spend fading in.
1.425 - * @param fadeOut Number of seconds to spend fading out.
1.426 - * @noreturn
1.427 - */
1.428 -native SetHudTextParams(Float:x, Float:y, Float:holdTime, r, g, b, a, effect = 0,
1.429 - Float:fxTime=6.0, Float:fadeIn=0.1, Float:fadeOut=0.2);
1.430 -
1.431 -/**
1.432 - * Sets the HUD parameters for drawing text. These parameters are stored
1.433 - * globally, although nothing other than this function and SetHudTextParams
1.434 - * modify them.
1.435 - *
1.436 - * This is the same as SetHudTextParams(), except it lets you set the alternate
1.437 - * color for when effects require it.
1.438 - *
1.439 - * @param x x coordinate, from 0 to 1. -1.0 is the center.
1.440 - * @param y y coordinate, from 0 to 1. -1.0 is the center.
1.441 - * @param holdTime Number of seconds to hold the text.
1.442 - * @param color1 First color set, array values being [red, green, blue, alpha]
1.443 - * @param color2 Second color set, array values being [red, green, blue, alpha]
1.444 - * @param effect 0/1 causes the text to fade in and fade out.
1.445 - * 2 causes the text to flash[?].
1.446 - * @param fxTime Duration of chosen effect (may not apply to all effects).
1.447 - * @param fadeIn Number of seconds to spend fading in.
1.448 - * @param fadeOut Number of seconds to spend fading out.
1.449 - * @noreturn
1.450 - */
1.451 -native SetHudTextParamsEx(Float:x, Float:y, Float:holdTime, color1[4],
1.452 - color2[4]={255,255,255,0}, effect = 0, Float:fxTime=6.0,
1.453 - Float:fadeIn=0.1, Float:fadeOut=0.2);
1.454 -
1.455 -/**
1.456 - * Shows a synchronized HUD message to a client.
1.457 - *
1.458 - * As of this writing, only TF, HL2MP, and SourceForts support HUD Text.
1.459 - *
1.460 - * @param client Client index to send the message to.
1.461 - * @param sync Synchronization object.
1.462 - * @param message Message text or formatting rules.
1.463 - * @param ... Message formatting parameters.
1.464 - * @return -1 on failure, anything else on success.
1.465 - * This function fails if the mod does not support it.
1.466 - * @error Client not in-game, or sync object not valid.
1.467 - */
1.468 -native ShowSyncHudText(client, Handle:sync, const String:message[], any:...);
1.469 -
1.470 -/**
1.471 - * Clears the text on a synchronized HUD channel.
1.472 - *
1.473 - * This is not the same as sending "" because it guarantees that it won't
1.474 - * overwrite text on another channel. For example, consider the scenario:
1.475 - *
1.476 - * 1. Your synchronized message goes to channel 3.
1.477 - * 2. Someone else's non-synchronized message goes to channel 3.
1.478 - *
1.479 - * If you were to simply send "" on your synchronized message,
1.480 - * then someone else's text could be overwritten.
1.481 - *
1.482 - * @param client Client index to send the message to.
1.483 - * @param sync Synchronization object.
1.484 - * @noreturn
1.485 - * @error Client not in-game, or sync object not valid.
1.486 - */
1.487 -native ClearSyncHud(client, Handle:sync);
1.488 -
1.489 -/**
1.490 - * Shows a HUD message to a client on the given channel.
1.491 - *
1.492 - * As of this writing, only TF, HL2MP, and SourceForts support HUD Text.
1.493 - *
1.494 - * @param client Client index to send the message to.
1.495 - * @param channel A channel number.
1.496 - * If -1, then a channel will automatically be selected
1.497 - * based on the least-recently-used channel. If the
1.498 - * channel is any other number, it will be modulo'd with
1.499 - * the channel count to get a final channel number.
1.500 - * @param message Message text or formatting rules.
1.501 - * @param ... Message formatting parameters.
1.502 - * @return -1 on failure (lack of mod support).
1.503 - * Any other return value is the channel number that was
1.504 - * used to render the text.
1.505 - */
1.506 -native ShowHudText(client, channel, const String:message[], any:...);
1.507 -
1.508 -/**
1.509 - * Shows a MOTD panel to a specific client.
1.510 - *
1.511 - * @param client Client index.
1.512 - * @param title Title of the panel (printed on the top border of the window).
1.513 - * @param msg Contents of the panel, it can be treated as an url, filename or plain text
1.514 - * depending on the type parameter (WARNING: msg has to be 192 bytes maximum!)
1.515 - * @param type Determines the way to treat the message body of the panel.
1.516 - * @noreturn
1.517 - * @error If the client is not connected an error will be thrown.
1.518 - */
1.519 -stock ShowMOTDPanel(client, const String:title[], const String:msg[], type=MOTDPANEL_TYPE_INDEX)
1.520 -{
1.521 - decl String:num[3];
1.522 - new Handle:Kv = CreateKeyValues("data");
1.523 - IntToString(type, num, sizeof(num));
1.524 -
1.525 - KvSetString(Kv, "title", title);
1.526 - KvSetString(Kv, "type", num);
1.527 - KvSetString(Kv, "msg", msg);
1.528 - ShowVGUIPanel(client, "info", Kv);
1.529 - CloseHandle(Kv);
1.530 -}
1.531 -
1.532 -/**
1.533 - * Displays a panel asking the client to connect to a specified IP.
1.534 - *
1.535 - * @param client Client index.
1.536 - * @param time Duration to hold the panel on the client's screen.
1.537 - * @param ip Destionation IP.
1.538 - * @noreturn
1.539 - */
1.540 -stock DisplayAskConnectBox(client, Float:time, const String:ip[])
1.541 -{
1.542 - new Handle:Kv = CreateKeyValues("data");
1.543 - KvSetFloat(Kv, "time", time);
1.544 - KvSetString(Kv, "title", ip);
1.545 - CreateDialog(client, Kv, DialogType_AskConnect);
1.546 - CloseHandle(Kv);
1.547 -}