ds@873: /** ds@873: * vim: set ts=4 : ds@1330: * ============================================================================= ds@873: * SourceMod (C)2004-2007 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. 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: } 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: }