ds@873: /** ds@873: * vim: set ts=4 : ds@873: * =============================================================== ds@873: * SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved. ds@873: * =============================================================== ds@873: * ds@873: * This file is part of the SourceMod/SourcePawn SDK. This file may only be used ds@873: * or modified under the Terms and Conditions of its License Agreement, which is found ds@873: * in LICENSE.txt. The Terms and Conditions for making SourceMod extensions/plugins ds@873: * may change at any time. To view the latest information, see: ds@873: * http://www.sourcemod.net/license.php 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: faluco@1218: #define MOTDPANEL_TYPE_TEXT 0 /**< Treat msg as plain text */ faluco@1218: #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 */ ds@873: DialogType_Entry /**< an entry box */ 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: /** 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. faluco@1218: * @param name Panel type name (Check viewport_panel_names.h to see a list of some panel names). faluco@1218: * @param Kv KeyValues handle with all the data for the panel setup (Depends 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: /** 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 faluco@1218: * 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: }