ds@873: /**
ds@873: * vim: set ts=4 :
ds@1330: * =============================================================================
ds@1947: * SourceMod (C)2004-2008 AlliedModders LLC. All rights reserved.
ds@1330: * =============================================================================
ds@1330: *
ds@1330: * This file is part of the SourceMod/SourcePawn SDK.
ds@873: *
ds@1330: * This program is free software; you can redistribute it and/or modify it under
ds@1330: * the terms of the GNU General Public License, version 3.0, as published by the
ds@1330: * Free Software Foundation.
ds@1330: *
ds@1330: * This program is distributed in the hope that it will be useful, but WITHOUT
ds@1330: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
ds@1330: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
ds@1330: * details.
ds@1330: *
ds@1330: * You should have received a copy of the GNU General Public License along with
ds@1330: * this program. If not, see .
ds@1330: *
ds@1330: * As a special exception, AlliedModders LLC gives you permission to link the
ds@1330: * code of this program (as well as its derivative works) to "Half-Life 2," the
ds@1330: * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
ds@1330: * by the Valve Corporation. You must obey the GNU General Public License in
ds@1330: * all respects for all other code used. Additionally, AlliedModders LLC grants
ds@1330: * this exception to all derivative works. AlliedModders LLC defines further
ds@1330: * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
ds@1330: * or .
ds@873: *
ds@873: * Version: $Id$
ds@873: */
ds@873:
ds@873: #if defined _halflife_included
ds@873: #endinput
ds@873: #endif
ds@873: #define _halflife_included
ds@873:
dvander@1837: #define SOURCE_SDK_UNKNOWN 0 /**< Could not determine the engine version */
dvander@1837: #define SOURCE_SDK_ORIGINAL 10 /**< Original Source engine (still used by "The Ship") */
dvander@1837: #define SOURCE_SDK_EPISODE1 20 /**< SDK+Engine released after Episode 1 */
dvander@1837: #define SOURCE_SDK_EPISODE2 30 /**< Engine released after Episode 2 (no SDK yet) */
dvander@1837:
faluco@1218: #define MOTDPANEL_TYPE_TEXT 0 /**< Treat msg as plain text */
dvander@1837: #define MOTDPANEL_TYPE_INDEX 1 /**< Msg is auto determined by the engine */
faluco@1218: #define MOTDPANEL_TYPE_URL 2 /**< Treat msg as an URL link */
faluco@1218: #define MOTDPANEL_TYPE_FILE 3 /**< Treat msg as a filename to be openned */
faluco@1218:
ds@873: enum DialogType
ds@873: {
ds@873: DialogType_Msg = 0, /**< just an on screen message */
ds@873: DialogType_Menu, /**< an options menu */
ds@873: DialogType_Text, /**< a richtext dialog */
faluco@1413: DialogType_Entry, /**< an entry box */
faluco@1413: DialogType_AskConnect /**< ask the client to connect to a specified IP */
ds@873: };
ds@873:
ds@873: /**
ds@873: * Logs a generic message to the HL2 logs.
ds@873: *
ds@873: * @param format String format.
ds@873: * @param ... Format arguments.
ds@873: * @noreturn
ds@873: */
ds@873: native LogToGame(const String:format[], any:...);
ds@873:
ds@873: /**
dvander@1003: * Sets the seed value for the global Half-Life 2 Random Stream.
ds@873: *
ds@873: * @param seed Seed value.
ds@873: * @noreturn
ds@873: */
ds@873: native SetRandomSeed(seed);
ds@873:
ds@873: /**
dvander@1003: * Returns a random floating point number from the Half-Life 2 Random Stream.
ds@873: *
ds@873: * @param fMin Minimum random bound.
ds@873: * @param fMax Maximum random bound.
ds@873: * @return A random number between (inclusive) fMin and fMax.
ds@873: */
ds@873: native Float:GetRandomFloat(Float:fMin=0.0, Float:fMax=1.0);
ds@873:
ds@873: /**
dvander@1003: * Returns a random number from the Half-Life 2 Random Stream.
ds@873: *
ds@873: * @param nmin Minimum random bound.
ds@873: * @param nmax Maximum random bound.
ds@873: * @return A random number between (inclusive) nmin and nmax.
ds@873: */
ds@873: native GetRandomInt(nmin, nmax);
ds@873:
ds@873: /**
ds@873: * Returns whether a map is valid or not.
ds@873: *
ds@873: * @param Map name, excluding .bsp extension.
ds@873: * @return True if valid, false otherwise.
ds@873: */
ds@873: native bool:IsMapValid(const String:map[]);
ds@873:
ds@873: /**
ds@873: * Returns whether the server is dedicated.
ds@873: *
ds@873: * @return True if dedicated, false otherwise.
ds@873: */
ds@873: native bool:IsDedicatedServer();
ds@873:
ds@873: /**
ds@873: * Returns a high-precision time value for profiling the engine.
ds@873: *
ds@873: * @return A floating point time value.
ds@873: */
ds@873: native Float:GetEngineTime();
ds@873:
ds@873: /**
ds@873: * Returns the game time based on the game tick.
ds@873: *
ds@873: * @return Game tick time.
ds@873: */
ds@873: native Float:GetGameTime();
ds@873:
ds@873: /**
ds@873: * Returns the game description from the mod.
ds@873: *
ds@873: * @param buffer Buffer to store the description.
ds@873: * @param maxlength Maximum size of the buffer.
ds@873: * @param original If true, retrieves the original game description,
ds@873: * ignoring any potential hooks from plugins.
ds@873: * @return Number of bytes written to the buffer (UTF-8 safe).
ds@873: */
ds@873: native GetGameDescription(String:buffer[], maxlength, bool:original=false);
ds@873:
ds@873: /**
ds@873: * Returns the name of the game's directory.
ds@873: *
ds@873: * @param buffer Buffer to store the directory name.
ds@873: * @param maxlength Maximum size of the buffer.
ds@873: *
ds@873: * return Number of bytes written to the buffer (UTF-8 safe).
ds@873: */
ds@873: native GetGameFolderName(String:buffer[], maxlength);
ds@873:
ds@873: /**
ds@873: * Returns the current map name.
ds@873: *
ds@873: * @param buffer Buffer to store map name.
ds@873: * @param maxlength Maximum length of buffer.
ds@873: * @return Number of bytes written (UTF-8 safe).
ds@873: */
ds@873: native GetCurrentMap(String:buffer[], maxlength);
ds@873:
ds@873: /**
ds@873: * Precaches a given model.
ds@873: *
ds@873: * @param model Name of the model to precache.
ds@873: * @param preload If preload is true the file will be precached before level startup.
ds@892: * @return Returns the model index, 0 for error.
ds@873: */
ds@873: native PrecacheModel(const String:model[], bool:preload=false);
ds@873:
ds@873: /**
ds@873: * Precaches a given sentence file.
ds@873: *
ds@873: * @param file Name of the sentence file to precache.
ds@873: * @param preload If preload is true the file will be precached before level startup.
ds@892: * @return Returns a sentence file index.
ds@873: */
ds@873: native PrecacheSentenceFile(const String:file[], bool:preload=false);
ds@873:
ds@873: /**
ds@873: * Precaches a given decal.
ds@873: *
ds@873: * @param decal Name of the decal to precache.
ds@873: * @param preload If preload is true the file will be precached before level startup.
ds@892: * @return Returns a decal index.
ds@873: */
ds@873: native PrecacheDecal(const String:decal[], bool:preload=false);
ds@873:
ds@873: /**
ds@873: * Precaches a given generic file.
ds@873: *
ds@873: * @param generic Name of the generic file to precache.
ds@873: * @param preload If preload is true the file will be precached before level startup.
ds@892: * @return Returns a generic file index.
ds@873: */
ds@873: native PrecacheGeneric(const String:generic[], bool:preload=false);
ds@873:
ds@873: /**
ds@873: * Returns if a given model is precached.
ds@873: *
ds@873: * @param model Name of the model to check.
ds@892: * @return True if precached, false otherwise.
ds@873: */
ds@873: native bool:IsModelPrecached(const String:model[]);
ds@873:
ds@873: /**
ds@873: * Returns if a given decal is precached.
ds@873: *
ds@873: * @param decal Name of the decal to check.
ds@892: * @return True if precached, false otherwise.
ds@873: */
ds@873: native bool:IsDecalPrecached(const String:decal[]);
ds@873:
ds@873: /**
ds@873: * Returns if a given generic file is precached.
ds@873: *
ds@873: * @param decal Name of the generic file to check.
ds@892: * @return True if precached, false otherwise.
ds@873: */
ds@873: native bool:IsGenericPrecached(const String:generic[]);
ds@873:
ds@873: /**
ds@873: * Precaches a given sound.
ds@873: *
ds@873: * @param sound Name of the sound to precache.
ds@873: * @param preload If preload is true the file will be precached before level startup.
ds@892: * @return True if successfully precached, false otherwise.
ds@873: */
ds@873: native bool:PrecacheSound(const String:sound[], bool:preload=false);
ds@873:
ds@873: /**
ds@873: * Returns if a given sound is precached.
ds@873: *
ds@873: * @param sound Name of the sound to check.
ds@892: * @return True if precached, false otherwise.
ds@873: */
ds@873: native bool:IsSoundPrecached(const String:sound[]);
ds@873:
ds@873: /**
ds@873: * Creates different types of ingame messages.
ds@873: *
ds@873: * @param client Index of the client.
ds@873: * @param kv KeyValues handle to set the menu keys and options. (Check iserverplugin.h for more information).
ds@873: * @param type Message type to display ingame.
ds@873: * @noreturn
ds@873: * @error Invalid client index, or client not connected.
ds@873: */
ds@873: native CreateDialog(client, Handle:kv, DialogType:type);
ds@873:
ds@873: /**
dvander@1837: * Guesses the SDK version a mod was compiled against. If nothing
dvander@1837: * specific is known about the game, the engine version is used instead.
dvander@1837: *
dvander@1837: * The return values are guaranteed to increase chronologically (that is,
dvander@1837: * a later release will have a higher value).
dvander@1837: *
dvander@1837: * @return SOURCE_SDK version code.
dvander@1837: */
dvander@1837: native GuessSDKVersion();
dvander@1837:
dvander@1837: /**
ds@892: * Prints a message to a specific client in the chat area.
ds@873: *
ds@892: * @param client Client index.
ds@873: * @param format Formatting rules.
ds@873: * @param ... Variable number of format parameters.
ds@873: * @noreturn
ds@873: * @error If the client is not connected an error will be thrown.
ds@873: */
ds@873: native PrintToChat(client, const String:format[], any:...);
ds@873:
ds@873: /**
ds@892: * Prints a message to all clients in the chat area.
ds@873: *
ds@892: * @param format Formatting rules.
ds@892: * @param ... Variable number of format parameters.
ds@892: * @noreturn
ds@892: */
ds@892: stock PrintToChatAll(const String:format[], any:...)
ds@892: {
ds@915: new maxClients = GetMaxClients();
ds@898: decl String:buffer[192];
ds@892:
ds@915: for (new i = 1; i <= maxClients; i++)
ds@892: {
ds@892: if (IsClientInGame(i))
ds@892: {
dvander@1034: SetGlobalTransTarget(i);
dvander@1034: VFormat(buffer, sizeof(buffer), format, 2);
ds@892: PrintToChat(i, "%s", buffer);
ds@892: }
ds@892: }
ds@892: }
ds@892:
ds@892: /**
ds@892: * Prints a message to a specific client in the center of the screen.
ds@892: *
ds@892: * @param client Client index.
ds@873: * @param format Formatting rules.
ds@873: * @param ... Variable number of format parameters.
ds@873: * @noreturn
ds@873: * @error If the client is not connected an error will be thrown.
ds@873: */
ds@873: native PrintCenterText(client, const String:format[], any:...);
ds@892:
ds@892: /**
ds@892: * Prints a message to all clients in the center of the screen.
ds@892: *
ds@892: * @param format Formatting rules.
ds@892: * @param ... Variable number of format parameters.
ds@892: * @noreturn
ds@892: */
ds@892: stock PrintCenterTextAll(const String:format[], any:...)
ds@892: {
ds@915: new maxClients = GetMaxClients();
ds@898: decl String:buffer[192];
teame06@1217:
ds@915: for (new i = 1; i <= maxClients; i++)
ds@892: {
ds@892: if (IsClientInGame(i))
ds@892: {
teame06@1217: SetGlobalTransTarget(i);
teame06@1217: VFormat(buffer, sizeof(buffer), format, 2);
ds@892: PrintCenterText(i, "%s", buffer);
ds@892: }
ds@892: }
ds@892: }
faluco@1218:
faluco@1218: /**
faluco@1218: * Prints a message to a specific client with a hint box.
faluco@1218: *
faluco@1218: * @param client Client index.
faluco@1218: * @param format Formatting rules.
faluco@1218: * @param ... Variable number of format parameters.
faluco@1218: * @noreturn
faluco@1218: * @error If the client is not connected an error will be thrown.
faluco@1218: */
faluco@1218: native PrintHintText(client, const String:format[], any:...);
faluco@1218:
faluco@1218: /**
faluco@1218: * Prints a message to all clients with a hint box.
faluco@1218: *
faluco@1218: * @param format Formatting rules.
faluco@1218: * @param ... Variable number of format parameters.
faluco@1218: * @noreturn
faluco@1218: */
faluco@1218: stock PrintHintTextToAll(const String:format[], any:...)
faluco@1218: {
faluco@1218: new maxClients = GetMaxClients();
faluco@1218: decl String:buffer[192];
faluco@1218:
faluco@1218: for (new i = 1; i <= maxClients; i++)
faluco@1218: {
faluco@1218: if (IsClientInGame(i))
faluco@1218: {
faluco@1218: SetGlobalTransTarget(i);
faluco@1218: VFormat(buffer, sizeof(buffer), format, 2);
faluco@1218: PrintHintText(i, "%s", buffer);
faluco@1218: }
faluco@1218: }
faluco@1218: }
faluco@1218:
faluco@1218: /**
faluco@1218: * Shows a VGUI panel to a specific client.
faluco@1218: *
faluco@1218: * @param client Client index.
dvander@1915: * @param name Panel type name (Check viewport_panel_names.h to see a list of
dvander@1915: * some panel names).
dvander@1915: * @param Kv KeyValues handle with all the data for the panel setup (Depends
dvander@1915: * on the panel type and may be unused).
faluco@1218: * @param show True to show the panel, or false to remove it from the client screen.
faluco@1218: * @noreturn
faluco@1218: * @error If the client is not connected an error will be thrown.
faluco@1218: */
faluco@1218: native ShowVGUIPanel(client, const String:name[], Handle:Kv=INVALID_HANDLE, bool:show=true);
faluco@1218:
faluco@1218: /**
dvander@1915: * Creates a HUD synchronization object. This object is used to automatically assign and
dvander@1915: * re-use channels for a set of messages.
dvander@1915: *
dvander@1915: * The HUD has a hardcoded number of channels (usually 6) for displaying
dvander@1915: * text. You can use any channel for any area of the screen. Text on
dvander@1915: * different channels can overlap, but text on the same channel will
dvander@1915: * erase the old text first. This overlapping and overwriting gets problematic.
dvander@1915: *
dvander@1915: * A HUD synchronization object automatically selects channels for you based on
dvander@1915: * the following heuristics:
dvander@1915: * - If channel X was last used by the object, and hasn't been modified again,
dvander@1915: * channel X gets re-used.
dvander@1915: * - Otherwise, a new channel is chosen based on the least-recently-used channel.
dvander@1915: *
dvander@1915: * This ensures that if you display text on a sync object, that the previous text
dvander@1915: * displayed on it will always be cleared first. This is because your new text
dvander@1915: * will either overwrite the old text on the same channel, or because another
dvander@1915: * channel has already erased your text.
dvander@1915: *
dvander@1915: * Note that messages can still overlap if they are on different synchronization
dvander@1915: * objects, or they are displayed to manual channels.
dvander@1915: *
dvander@1915: * These are particularly useful for displaying repeating or refreshing HUD text, in
dvander@1915: * addition to displaying multiple message sets in one area of the screen (for example,
dvander@1915: * center-say messages that may pop up randomly that you don't want to overlap each
dvander@1915: * other).
dvander@1915: *
dvander@1915: * @return New HUD synchronization object.
dvander@1915: * The Handle can be closed with CloseHandle().
dvander@1915: * If HUD text is not supported on this mod, then
dvander@1915: * INVALID_HANDLE is returned.
dvander@1915: */
dvander@1915: native Handle:CreateHudSynchronizer();
dvander@1915:
dvander@1915: /**
dvander@1915: * Sets the HUD parameters for drawing text. These parameters are stored
dvander@1915: * globally, although nothing other than this function and SetHudTextParamsEx
dvander@1915: * modify them.
dvander@1915: *
dvander@1915: * You must call this function before drawing text. If you are drawing
dvander@1915: * text to multiple clients, you can set the parameters once, since
dvander@1915: * they won't be modified. However, as soon as you pass control back
dvander@1915: * to other plugins, you must reset the parameters next time you draw.
dvander@1915: *
dvander@1915: * @param x x coordinate, from 0 to 1. -1.0 is the center.
dvander@1915: * @param y y coordinate, from 0 to 1. -1.0 is the center.
dvander@1915: * @param holdTime Number of seconds to hold the text.
dvander@1915: * @param r Red color value.
dvander@1915: * @param g Green color value.
dvander@1915: * @param b Blue color value.
dvander@1915: * @param a Alpha transparency value.
dvander@1915: * @param effect 0/1 causes the text to fade in and fade out.
dvander@1915: * 2 causes the text to flash[?].
dvander@1915: * @param fxTime Duration of chosen effect (may not apply to all effects).
dvander@1915: * @param fadeIn Number of seconds to spend fading in.
dvander@1915: * @param fadeOut Number of seconds to spend fading out.
dvander@1915: * @noreturn
dvander@1915: */
dvander@1915: native SetHudTextParams(Float:x, Float:y, Float:holdTime, r, g, b, a, effect = 0,
dvander@1915: Float:fxTime=6.0, Float:fadeIn=0.1, Float:fadeOut=0.2);
dvander@1915:
dvander@1915: /**
dvander@1915: * Sets the HUD parameters for drawing text. These parameters are stored
dvander@1915: * globally, although nothing other than this function and SetHudTextParams
dvander@1915: * modify them.
dvander@1915: *
dvander@1915: * This is the same as SetHudTextParams(), except it lets you set the alternate
dvander@1915: * color for when effects require it.
dvander@1915: *
dvander@1915: * @param x x coordinate, from 0 to 1. -1.0 is the center.
dvander@1915: * @param y y coordinate, from 0 to 1. -1.0 is the center.
dvander@1915: * @param holdTime Number of seconds to hold the text.
dvander@1915: * @param color1 First color set, array values being [red, green, blue, alpha]
dvander@1915: * @param color2 Second color set, array values being [red, green, blue, alpha]
dvander@1915: * @param effect 0/1 causes the text to fade in and fade out.
dvander@1915: * 2 causes the text to flash[?].
dvander@1915: * @param fxTime Duration of chosen effect (may not apply to all effects).
dvander@1915: * @param fadeIn Number of seconds to spend fading in.
dvander@1915: * @param fadeOut Number of seconds to spend fading out.
dvander@1915: * @noreturn
dvander@1915: */
dvander@1915: native SetHudTextParamsEx(Float:x, Float:y, Float:holdTime, color1[4],
dvander@1915: color2[4]={255,255,255,0}, effect = 0, Float:fxTime=6.0,
dvander@1915: Float:fadeIn=0.1, Float:fadeOut=0.2);
dvander@1915:
dvander@1915: /**
dvander@1915: * Shows a synchronized HUD message to a client.
dvander@1915: *
dvander@1915: * As of this writing, only TF, HL2MP, and SourceForts support HUD Text.
dvander@1915: *
dvander@1915: * @param client Client index to send the message to.
dvander@1915: * @param sync Synchronization object.
dvander@1915: * @param message Message text or formatting rules.
dvander@1915: * @param ... Message formatting parameters.
dvander@1915: * @return -1 on failure, anything else on success.
dvander@1915: * This function fails if the mod does not support it.
dvander@1915: * @error Client not in-game, or sync object not valid.
dvander@1915: */
dvander@1915: native ShowSyncHudText(client, Handle:sync, const String:message[], any:...);
dvander@1915:
dvander@1915: /**
dvander@1915: * Clears the text on a synchronized HUD channel.
dvander@1915: *
dvander@1915: * This is not the same as sending "" because it guarantees that it won't
dvander@1915: * overwrite text on another channel. For example, consider the scenario:
dvander@1915: *
dvander@1915: * 1. Your synchronized message goes to channel 3.
dvander@1915: * 2. Someone else's non-synchronized message goes to channel 3.
dvander@1915: *
dvander@1915: * If you were to simply send "" on your synchronized message,
dvander@1915: * then someone else's text could be overwritten.
dvander@1915: *
dvander@1915: * @param client Client index to send the message to.
dvander@1915: * @param sync Synchronization object.
dvander@1915: * @noreturn
dvander@1915: * @error Client not in-game, or sync object not valid.
dvander@1915: */
dvander@1915: native ClearSyncHud(client, Handle:sync);
dvander@1915:
dvander@1915: /**
dvander@1915: * Shows a HUD message to a client on the given channel.
dvander@1915: *
dvander@1915: * As of this writing, only TF, HL2MP, and SourceForts support HUD Text.
dvander@1915: *
dvander@1915: * @param client Client index to send the message to.
dvander@1915: * @param channel A channel number.
dvander@1915: * If -1, then a channel will automatically be selected
dvander@1915: * based on the least-recently-used channel. If the
dvander@1915: * channel is any other number, it will be modulo'd with
dvander@1915: * the channel count to get a final channel number.
dvander@1915: * @param message Message text or formatting rules.
dvander@1915: * @param ... Message formatting parameters.
dvander@1915: * @return -1 on failure (lack of mod support).
dvander@1915: * Any other return value is the channel number that was
dvander@1915: * used to render the text.
dvander@1915: */
dvander@1915: native ShowHudText(client, channel, const String:message[], any:...);
dvander@1915:
dvander@1915: /**
faluco@1218: * Shows a MOTD panel to a specific client.
faluco@1218: *
faluco@1218: * @param client Client index.
faluco@1218: * @param title Title of the panel (printed on the top border of the window).
faluco@1218: * @param msg Contents of the panel, it can be treated as an url, filename or plain text
dvander@1915: * depending on the type parameter (WARNING: msg has to be 192 bytes maximum!)
faluco@1218: * @param type Determines the way to treat the message body of the panel.
faluco@1218: * @noreturn
faluco@1218: * @error If the client is not connected an error will be thrown.
faluco@1218: */
faluco@1218: stock ShowMOTDPanel(client, const String:title[], const String:msg[], type=MOTDPANEL_TYPE_INDEX)
faluco@1218: {
faluco@1218: decl String:num[3];
faluco@1218: new Handle:Kv = CreateKeyValues("data");
faluco@1218: IntToString(type, num, sizeof(num));
faluco@1218:
faluco@1218: KvSetString(Kv, "title", title);
faluco@1218: KvSetString(Kv, "type", num);
faluco@1218: KvSetString(Kv, "msg", msg);
faluco@1218: ShowVGUIPanel(client, "info", Kv);
faluco@1218: CloseHandle(Kv);
faluco@1218: }
faluco@1413:
faluco@1413: /**
faluco@1413: * Displays a panel asking the client to connect to a specified IP.
faluco@1413: *
faluco@1413: * @param client Client index.
faluco@1413: * @param time Duration to hold the panel on the client's screen.
faluco@1413: * @param ip Destionation IP.
faluco@1413: * @noreturn
faluco@1413: */
faluco@1413: stock DisplayAskConnectBox(client, Float:time, const String:ip[])
faluco@1413: {
faluco@1413: new Handle:Kv = CreateKeyValues("data");
faluco@1413: KvSetFloat(Kv, "time", time);
faluco@1413: KvSetString(Kv, "title", ip);
faluco@1413: CreateDialog(client, Kv, DialogType_AskConnect);
faluco@1413: CloseHandle(Kv);
faluco@1413: }