3 * =============================================================================
4 * SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved.
5 * =============================================================================
7 * This file is part of the SourceMod/SourcePawn SDK.
9 * This program is free software; you can redistribute it and/or modify it under
10 * the terms of the GNU General Public License, version 3.0, as published by the
11 * Free Software Foundation.
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
18 * You should have received a copy of the GNU General Public License along with
19 * this program. If not, see <http://www.gnu.org/licenses/>.
21 * As a special exception, AlliedModders LLC gives you permission to link the
22 * code of this program (as well as its derivative works) to "Half-Life 2," the
23 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
24 * by the Valve Corporation. You must obey the GNU General Public License in
25 * all respects for all other code used. Additionally, AlliedModders LLC grants
26 * this exception to all derivative works. AlliedModders LLC defines further
27 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
28 * or <http://www.sourcemod.net/license.php>.
33 #if defined _halflife_included
36 #define _halflife_included
38 #define MOTDPANEL_TYPE_TEXT 0 /**< Treat msg as plain text */
39 #define MOTDPANEL_TYPE_INDEX 1 /**< Msg is auto determined by the engine */
40 #define MOTDPANEL_TYPE_URL 2 /**< Treat msg as an URL link */
41 #define MOTDPANEL_TYPE_FILE 3 /**< Treat msg as a filename to be openned */
45 DialogType_Msg = 0, /**< just an on screen message */
46 DialogType_Menu, /**< an options menu */
47 DialogType_Text, /**< a richtext dialog */
48 DialogType_Entry, /**< an entry box */
49 DialogType_AskConnect /**< ask the client to connect to a specified IP */
53 * Logs a generic message to the HL2 logs.
55 * @param format String format.
56 * @param ... Format arguments.
59 native LogToGame(const String:format[], any:...);
62 * Sets the seed value for the global Half-Life 2 Random Stream.
64 * @param seed Seed value.
67 native SetRandomSeed(seed);
70 * Returns a random floating point number from the Half-Life 2 Random Stream.
72 * @param fMin Minimum random bound.
73 * @param fMax Maximum random bound.
74 * @return A random number between (inclusive) fMin and fMax.
76 native Float:GetRandomFloat(Float:fMin=0.0, Float:fMax=1.0);
79 * Returns a random number from the Half-Life 2 Random Stream.
81 * @param nmin Minimum random bound.
82 * @param nmax Maximum random bound.
83 * @return A random number between (inclusive) nmin and nmax.
85 native GetRandomInt(nmin, nmax);
88 * Returns whether a map is valid or not.
90 * @param Map name, excluding .bsp extension.
91 * @return True if valid, false otherwise.
93 native bool:IsMapValid(const String:map[]);
96 * Returns whether the server is dedicated.
98 * @return True if dedicated, false otherwise.
100 native bool:IsDedicatedServer();
103 * Returns a high-precision time value for profiling the engine.
105 * @return A floating point time value.
107 native Float:GetEngineTime();
110 * Returns the game time based on the game tick.
112 * @return Game tick time.
114 native Float:GetGameTime();
117 * Returns the game description from the mod.
119 * @param buffer Buffer to store the description.
120 * @param maxlength Maximum size of the buffer.
121 * @param original If true, retrieves the original game description,
122 * ignoring any potential hooks from plugins.
123 * @return Number of bytes written to the buffer (UTF-8 safe).
125 native GetGameDescription(String:buffer[], maxlength, bool:original=false);
128 * Returns the name of the game's directory.
130 * @param buffer Buffer to store the directory name.
131 * @param maxlength Maximum size of the buffer.
133 * return Number of bytes written to the buffer (UTF-8 safe).
135 native GetGameFolderName(String:buffer[], maxlength);
138 * Returns the current map name.
140 * @param buffer Buffer to store map name.
141 * @param maxlength Maximum length of buffer.
142 * @return Number of bytes written (UTF-8 safe).
144 native GetCurrentMap(String:buffer[], maxlength);
147 * Precaches a given model.
149 * @param model Name of the model to precache.
150 * @param preload If preload is true the file will be precached before level startup.
151 * @return Returns the model index, 0 for error.
153 native PrecacheModel(const String:model[], bool:preload=false);
156 * Precaches a given sentence file.
158 * @param file Name of the sentence file to precache.
159 * @param preload If preload is true the file will be precached before level startup.
160 * @return Returns a sentence file index.
162 native PrecacheSentenceFile(const String:file[], bool:preload=false);
165 * Precaches a given decal.
167 * @param decal Name of the decal to precache.
168 * @param preload If preload is true the file will be precached before level startup.
169 * @return Returns a decal index.
171 native PrecacheDecal(const String:decal[], bool:preload=false);
174 * Precaches a given generic file.
176 * @param generic Name of the generic file to precache.
177 * @param preload If preload is true the file will be precached before level startup.
178 * @return Returns a generic file index.
180 native PrecacheGeneric(const String:generic[], bool:preload=false);
183 * Returns if a given model is precached.
185 * @param model Name of the model to check.
186 * @return True if precached, false otherwise.
188 native bool:IsModelPrecached(const String:model[]);
191 * Returns if a given decal is precached.
193 * @param decal Name of the decal to check.
194 * @return True if precached, false otherwise.
196 native bool:IsDecalPrecached(const String:decal[]);
199 * Returns if a given generic file is precached.
201 * @param decal Name of the generic file to check.
202 * @return True if precached, false otherwise.
204 native bool:IsGenericPrecached(const String:generic[]);
207 * Precaches a given sound.
209 * @param sound Name of the sound to precache.
210 * @param preload If preload is true the file will be precached before level startup.
211 * @return True if successfully precached, false otherwise.
213 native bool:PrecacheSound(const String:sound[], bool:preload=false);
216 * Returns if a given sound is precached.
218 * @param sound Name of the sound to check.
219 * @return True if precached, false otherwise.
221 native bool:IsSoundPrecached(const String:sound[]);
224 * Creates different types of ingame messages.
226 * @param client Index of the client.
227 * @param kv KeyValues handle to set the menu keys and options. (Check iserverplugin.h for more information).
228 * @param type Message type to display ingame.
230 * @error Invalid client index, or client not connected.
232 native CreateDialog(client, Handle:kv, DialogType:type);
235 * Prints a message to a specific client in the chat area.
237 * @param client Client index.
238 * @param format Formatting rules.
239 * @param ... Variable number of format parameters.
241 * @error If the client is not connected an error will be thrown.
243 native PrintToChat(client, const String:format[], any:...);
246 * Prints a message to all clients in the chat area.
248 * @param format Formatting rules.
249 * @param ... Variable number of format parameters.
252 stock PrintToChatAll(const String:format[], any:...)
254 new maxClients = GetMaxClients();
255 decl String:buffer[192];
257 for (new i = 1; i <= maxClients; i++)
259 if (IsClientInGame(i))
261 SetGlobalTransTarget(i);
262 VFormat(buffer, sizeof(buffer), format, 2);
263 PrintToChat(i, "%s", buffer);
269 * Prints a message to a specific client in the center of the screen.
271 * @param client Client index.
272 * @param format Formatting rules.
273 * @param ... Variable number of format parameters.
275 * @error If the client is not connected an error will be thrown.
277 native PrintCenterText(client, const String:format[], any:...);
280 * Prints a message to all clients in the center of the screen.
282 * @param format Formatting rules.
283 * @param ... Variable number of format parameters.
286 stock PrintCenterTextAll(const String:format[], any:...)
288 new maxClients = GetMaxClients();
289 decl String:buffer[192];
291 for (new i = 1; i <= maxClients; i++)
293 if (IsClientInGame(i))
295 SetGlobalTransTarget(i);
296 VFormat(buffer, sizeof(buffer), format, 2);
297 PrintCenterText(i, "%s", buffer);
303 * Prints a message to a specific client with a hint box.
305 * @param client Client index.
306 * @param format Formatting rules.
307 * @param ... Variable number of format parameters.
309 * @error If the client is not connected an error will be thrown.
311 native PrintHintText(client, const String:format[], any:...);
314 * Prints a message to all clients with a hint box.
316 * @param format Formatting rules.
317 * @param ... Variable number of format parameters.
320 stock PrintHintTextToAll(const String:format[], any:...)
322 new maxClients = GetMaxClients();
323 decl String:buffer[192];
325 for (new i = 1; i <= maxClients; i++)
327 if (IsClientInGame(i))
329 SetGlobalTransTarget(i);
330 VFormat(buffer, sizeof(buffer), format, 2);
331 PrintHintText(i, "%s", buffer);
337 * Shows a VGUI panel to a specific client.
339 * @param client Client index.
340 * @param name Panel type name (Check viewport_panel_names.h to see a list of some panel names).
341 * @param Kv KeyValues handle with all the data for the panel setup (Depends on the panel type and may be unused).
342 * @param show True to show the panel, or false to remove it from the client screen.
344 * @error If the client is not connected an error will be thrown.
346 native ShowVGUIPanel(client, const String:name[], Handle:Kv=INVALID_HANDLE, bool:show=true);
349 * Shows a MOTD panel to a specific client.
351 * @param client Client index.
352 * @param title Title of the panel (printed on the top border of the window).
353 * @param msg Contents of the panel, it can be treated as an url, filename or plain text
354 * depending on the type parameter (WARNING: msg has to be 192 bytes maximum!)
355 * @param type Determines the way to treat the message body of the panel.
357 * @error If the client is not connected an error will be thrown.
359 stock ShowMOTDPanel(client, const String:title[], const String:msg[], type=MOTDPANEL_TYPE_INDEX)
362 new Handle:Kv = CreateKeyValues("data");
363 IntToString(type, num, sizeof(num));
365 KvSetString(Kv, "title", title);
366 KvSetString(Kv, "type", num);
367 KvSetString(Kv, "msg", msg);
368 ShowVGUIPanel(client, "info", Kv);
373 * Displays a panel asking the client to connect to a specified IP.
375 * @param client Client index.
376 * @param time Duration to hold the panel on the client's screen.
377 * @param ip Destionation IP.
380 stock DisplayAskConnectBox(client, Float:time, const String:ip[])
382 new Handle:Kv = CreateKeyValues("data");
383 KvSetFloat(Kv, "time", time);
384 KvSetString(Kv, "title", ip);
385 CreateDialog(client, Kv, DialogType_AskConnect);