3 * =============================================================================
4 * SourceMod (C)2004-2008 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 SOURCE_SDK_UNKNOWN 0 /**< Could not determine the engine version */
39 #define SOURCE_SDK_ORIGINAL 10 /**< Original Source engine (still used by "The Ship") */
40 #define SOURCE_SDK_DARKMESSIAH 15 /**< Modified version of original engine used by Dark Messiah (no SDK) */
41 #define SOURCE_SDK_EPISODE1 20 /**< SDK+Engine released after Episode 1 */
42 #define SOURCE_SDK_EPISODE2 30 /**< SDK+Engine released after Episode 2/Orange Box */
43 #define SOURCE_SDK_BLOODYGOODTIME 32 /**< Modified version of ep2 engine used by Bloody Good Time (no SDK) */
44 #define SOURCE_SDK_EYE 33 /**< Modified version of ep2 engine used by E.Y.E Divine Cybermancy (no SDK) */
45 #define SOURCE_SDK_CSS 34 /**< Sometime-older version of Source 2009 SDK+Engine, used for Counter-Strike: Source */
46 #define SOURCE_SDK_EPISODE2VALVE 35 /**< SDK+Engine released after Episode 2/Orange Box, "Source 2009" or "Source MP" */
47 #define SOURCE_SDK_LEFT4DEAD 40 /**< Engine released after Left 4 Dead (no SDK yet) */
48 #define SOURCE_SDK_LEFT4DEAD2 50 /**< Engine released after Left 4 Dead 2 (no SDK yet) */
49 #define SOURCE_SDK_ALIENSWARM 60 /**< SDK+Engine released after Alien Swarm */
50 #define SOURCE_SDK_CSGO 80 /**< Engine released after CS:GO (no SDK yet) */
51 #define SOURCE_SDK_DOTA 90 /**< Engine released after Dota 2 (no SDK) */
53 #define MOTDPANEL_TYPE_TEXT 0 /**< Treat msg as plain text */
54 #define MOTDPANEL_TYPE_INDEX 1 /**< Msg is auto determined by the engine */
55 #define MOTDPANEL_TYPE_URL 2 /**< Treat msg as an URL link */
56 #define MOTDPANEL_TYPE_FILE 3 /**< Treat msg as a filename to be openned */
60 DialogType_Msg = 0, /**< just an on screen message */
61 DialogType_Menu, /**< an options menu */
62 DialogType_Text, /**< a richtext dialog */
63 DialogType_Entry, /**< an entry box */
64 DialogType_AskConnect /**< ask the client to connect to a specified IP */
69 Engine_Unknown, /**< Could not determine the engine version */
70 Engine_Original, /**< Original Source Engine (used by The Ship) */
71 Engine_SourceSDK2006, /**< Episode 1 Source Engine (second major SDK) */
72 Engine_SourceSDK2007, /**< Orange Box Source Engine (third major SDK) */
73 Engine_Left4Dead, /**< Left 4 Dead */
74 Engine_DarkMessiah, /**< Dark Messiah Multiplayer (based on original engine) */
75 Engine_Left4Dead2 = 7, /**< Left 4 Dead 2 */
76 Engine_AlienSwarm, /**< Alien Swarm (and Alien Swarm SDK) */
77 Engine_BloodyGoodTime, /**< Bloody Good Time */
78 Engine_EYE, /**< E.Y.E Divine Cybermancy */
79 Engine_Portal2, /**< Portal 2 */
80 Engine_CSGO, /**< Counter-Strike: Global Offensive */
81 Engine_CSS, /**< Counter-Strike: Source */
82 Engine_DOTA, /**< Dota 2 */
83 Engine_HL2DM, /**< Half-Life 2 Deathmatch */
84 Engine_DODS, /**< Day of Defeat: Source */
85 Engine_TF2, /**< Team Fortress 2 */
86 Engine_NuclearDawn /**< Nuclear Dawn */
89 #define INVALID_ENT_REFERENCE 0xFFFFFFFF
92 * Logs a generic message to the HL2 logs.
94 * @param format String format.
95 * @param ... Format arguments.
98 native LogToGame(const String:format[], any:...);
101 * Sets the seed value for the global Half-Life 2 Random Stream.
103 * @param seed Seed value.
106 native SetRandomSeed(seed);
109 * Returns a random floating point number from the Half-Life 2 Random Stream.
111 * @param fMin Minimum random bound.
112 * @param fMax Maximum random bound.
113 * @return A random number between (inclusive) fMin and fMax.
115 native Float:GetRandomFloat(Float:fMin=0.0, Float:fMax=1.0);
118 * Returns a random number from the Half-Life 2 Random Stream.
120 * @param nmin Minimum random bound.
121 * @param nmax Maximum random bound.
122 * @return A random number between (inclusive) nmin and nmax.
124 native GetRandomInt(nmin, nmax);
127 * Returns whether a map is valid or not.
129 * @param Map name, excluding .bsp extension.
130 * @return True if valid, false otherwise.
132 native bool:IsMapValid(const String:map[]);
135 * Returns whether the server is dedicated.
137 * @return True if dedicated, false otherwise.
139 native bool:IsDedicatedServer();
142 * Returns a high-precision time value for profiling the engine.
144 * @return A floating point time value.
146 native Float:GetEngineTime();
149 * Returns the game time based on the game tick.
151 * @return Game tick time.
153 native Float:GetGameTime();
156 * Returns the game's internal tick count.
158 * @return Game tick count.
160 native GetGameTickCount();
163 * Returns the game description from the mod.
165 * @param buffer Buffer to store the description.
166 * @param maxlength Maximum size of the buffer.
167 * @param original If true, retrieves the original game description,
168 * ignoring any potential hooks from plugins.
169 * @return Number of bytes written to the buffer (UTF-8 safe).
171 native GetGameDescription(String:buffer[], maxlength, bool:original=false);
174 * Returns the name of the game's directory.
176 * @param buffer Buffer to store the directory name.
177 * @param maxlength Maximum size of the buffer.
179 * return Number of bytes written to the buffer (UTF-8 safe).
181 native GetGameFolderName(String:buffer[], maxlength);
184 * Returns the current map name.
186 * @param buffer Buffer to store map name.
187 * @param maxlength Maximum length of buffer.
188 * @return Number of bytes written (UTF-8 safe).
190 native GetCurrentMap(String:buffer[], maxlength);
193 * Precaches a given model.
195 * @param model Name of the model to precache.
196 * @param preload If preload is true the file will be precached before level startup.
197 * @return Returns the model index, 0 for error.
199 native PrecacheModel(const String:model[], bool:preload=false);
202 * Precaches a given sentence file.
204 * @param file Name of the sentence file to precache.
205 * @param preload If preload is true the file will be precached before level startup.
206 * @return Returns a sentence file index.
208 native PrecacheSentenceFile(const String:file[], bool:preload=false);
211 * Precaches a given decal.
213 * @param decal Name of the decal to precache.
214 * @param preload If preload is true the file will be precached before level startup.
215 * @return Returns a decal index.
217 native PrecacheDecal(const String:decal[], bool:preload=false);
220 * Precaches a given generic file.
222 * @param generic Name of the generic file to precache.
223 * @param preload If preload is true the file will be precached before level startup.
224 * @return Returns a generic file index.
226 native PrecacheGeneric(const String:generic[], bool:preload=false);
229 * Returns if a given model is precached.
231 * @param model Name of the model to check.
232 * @return True if precached, false otherwise.
234 native bool:IsModelPrecached(const String:model[]);
237 * Returns if a given decal is precached.
239 * @param decal Name of the decal to check.
240 * @return True if precached, false otherwise.
242 native bool:IsDecalPrecached(const String:decal[]);
245 * Returns if a given generic file is precached.
247 * @param decal Name of the generic file to check.
248 * @return True if precached, false otherwise.
250 native bool:IsGenericPrecached(const String:generic[]);
253 * Precaches a given sound.
255 * @param sound Name of the sound to precache.
256 * @param preload If preload is true the file will be precached before level startup.
257 * @return True if successfully precached, false otherwise.
259 native bool:PrecacheSound(const String:sound[], bool:preload=false);
262 * Returns if a given sound is precached.
264 * @param sound Name of the sound to check.
265 * @return True if precached, false otherwise.
267 native bool:IsSoundPrecached(const String:sound[]);
270 * Creates different types of ingame messages.
272 * @param client Index of the client.
273 * @param kv KeyValues handle to set the menu keys and options. (Check iserverplugin.h for more information).
274 * @param type Message type to display ingame.
276 * @error Invalid client index, or client not connected.
278 native CreateDialog(client, Handle:kv, DialogType:type);
281 * Guesses the SDK version a mod was compiled against. If nothing
282 * specific is known about the game, the engine version is used instead.
284 * The return values are guaranteed to increase chronologically (that is,
285 * a later release will have a higher value).
287 * @return SOURCE_SDK version code.
289 #pragma deprecated See GetEngineVersion()
290 native GuessSDKVersion();
293 * Gets the engine version that the currently-loaded SM core was compiled against.
295 * The engine version values are not guaranteed to be in any particular order,
296 * and should only be compared by (in)equality.
298 * @return An EngineVersion value.
300 native EngineVersion:GetEngineVersion();
303 * Prints a message to a specific client in the chat area.
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 PrintToChat(client, const String:format[], any:...);
314 * Prints a message to all clients in the chat area.
316 * @param format Formatting rules.
317 * @param ... Variable number of format parameters.
320 stock PrintToChatAll(const String:format[], any:...)
322 decl String:buffer[192];
324 for (new i = 1; i <= MaxClients; i++)
326 if (IsClientInGame(i))
328 SetGlobalTransTarget(i);
329 VFormat(buffer, sizeof(buffer), format, 2);
330 PrintToChat(i, "%s", buffer);
336 * Prints a message to a specific client in the center of the screen.
338 * @param client Client index.
339 * @param format Formatting rules.
340 * @param ... Variable number of format parameters.
342 * @error If the client is not connected an error will be thrown.
344 native PrintCenterText(client, const String:format[], any:...);
347 * Prints a message to all clients in the center of the screen.
349 * @param format Formatting rules.
350 * @param ... Variable number of format parameters.
353 stock PrintCenterTextAll(const String:format[], any:...)
355 decl String:buffer[192];
357 for (new i = 1; i <= MaxClients; i++)
359 if (IsClientInGame(i))
361 SetGlobalTransTarget(i);
362 VFormat(buffer, sizeof(buffer), format, 2);
363 PrintCenterText(i, "%s", buffer);
369 * Prints a message to a specific client with a hint box.
371 * @param client Client index.
372 * @param format Formatting rules.
373 * @param ... Variable number of format parameters.
375 * @error If the client is not connected an error will be thrown.
377 native PrintHintText(client, const String:format[], any:...);
380 * Prints a message to all clients with a hint box.
382 * @param format Formatting rules.
383 * @param ... Variable number of format parameters.
386 stock PrintHintTextToAll(const String:format[], any:...)
388 decl String:buffer[192];
390 for (new i = 1; i <= MaxClients; i++)
392 if (IsClientInGame(i))
394 SetGlobalTransTarget(i);
395 VFormat(buffer, sizeof(buffer), format, 2);
396 PrintHintText(i, "%s", buffer);
402 * Shows a VGUI panel to a specific client.
404 * @param client Client index.
405 * @param name Panel type name (Check viewport_panel_names.h to see a list of
407 * @param Kv KeyValues handle with all the data for the panel setup (Depends
408 * on the panel type and may be unused).
409 * @param show True to show the panel, or false to remove it from the client screen.
411 * @error If the client is not connected an error will be thrown.
413 native ShowVGUIPanel(client, const String:name[], Handle:Kv=INVALID_HANDLE, bool:show=true);
416 * Creates a HUD synchronization object. This object is used to automatically assign and
417 * re-use channels for a set of messages.
419 * The HUD has a hardcoded number of channels (usually 6) for displaying
420 * text. You can use any channel for any area of the screen. Text on
421 * different channels can overlap, but text on the same channel will
422 * erase the old text first. This overlapping and overwriting gets problematic.
424 * A HUD synchronization object automatically selects channels for you based on
425 * the following heuristics:
426 * - If channel X was last used by the object, and hasn't been modified again,
427 * channel X gets re-used.
428 * - Otherwise, a new channel is chosen based on the least-recently-used channel.
430 * This ensures that if you display text on a sync object, that the previous text
431 * displayed on it will always be cleared first. This is because your new text
432 * will either overwrite the old text on the same channel, or because another
433 * channel has already erased your text.
435 * Note that messages can still overlap if they are on different synchronization
436 * objects, or they are displayed to manual channels.
438 * These are particularly useful for displaying repeating or refreshing HUD text, in
439 * addition to displaying multiple message sets in one area of the screen (for example,
440 * center-say messages that may pop up randomly that you don't want to overlap each
443 * @return New HUD synchronization object.
444 * The Handle can be closed with CloseHandle().
445 * If HUD text is not supported on this mod, then
446 * INVALID_HANDLE is returned.
448 native Handle:CreateHudSynchronizer();
451 * Sets the HUD parameters for drawing text. These parameters are stored
452 * globally, although nothing other than this function and SetHudTextParamsEx
455 * You must call this function before drawing text. If you are drawing
456 * text to multiple clients, you can set the parameters once, since
457 * they won't be modified. However, as soon as you pass control back
458 * to other plugins, you must reset the parameters next time you draw.
460 * @param x x coordinate, from 0 to 1. -1.0 is the center.
461 * @param y y coordinate, from 0 to 1. -1.0 is the center.
462 * @param holdTime Number of seconds to hold the text.
463 * @param r Red color value.
464 * @param g Green color value.
465 * @param b Blue color value.
466 * @param a Alpha transparency value.
467 * @param effect 0/1 causes the text to fade in and fade out.
468 * 2 causes the text to flash[?].
469 * @param fxTime Duration of chosen effect (may not apply to all effects).
470 * @param fadeIn Number of seconds to spend fading in.
471 * @param fadeOut Number of seconds to spend fading out.
474 native SetHudTextParams(Float:x, Float:y, Float:holdTime, r, g, b, a, effect = 0,
475 Float:fxTime=6.0, Float:fadeIn=0.1, Float:fadeOut=0.2);
478 * Sets the HUD parameters for drawing text. These parameters are stored
479 * globally, although nothing other than this function and SetHudTextParams
482 * This is the same as SetHudTextParams(), except it lets you set the alternate
483 * color for when effects require it.
485 * @param x x coordinate, from 0 to 1. -1.0 is the center.
486 * @param y y coordinate, from 0 to 1. -1.0 is the center.
487 * @param holdTime Number of seconds to hold the text.
488 * @param color1 First color set, array values being [red, green, blue, alpha]
489 * @param color2 Second color set, array values being [red, green, blue, alpha]
490 * @param effect 0/1 causes the text to fade in and fade out.
491 * 2 causes the text to flash[?].
492 * @param fxTime Duration of chosen effect (may not apply to all effects).
493 * @param fadeIn Number of seconds to spend fading in.
494 * @param fadeOut Number of seconds to spend fading out.
497 native SetHudTextParamsEx(Float:x, Float:y, Float:holdTime, color1[4],
498 color2[4]={255,255,255,0}, effect = 0, Float:fxTime=6.0,
499 Float:fadeIn=0.1, Float:fadeOut=0.2);
502 * Shows a synchronized HUD message to a client.
504 * As of this writing, only TF, HL2MP, and SourceForts support HUD Text.
506 * @param client Client index to send the message to.
507 * @param sync Synchronization object.
508 * @param message Message text or formatting rules.
509 * @param ... Message formatting parameters.
510 * @return -1 on failure, anything else on success.
511 * This function fails if the mod does not support it.
512 * @error Client not in-game, or sync object not valid.
514 native ShowSyncHudText(client, Handle:sync, const String:message[], any:...);
517 * Clears the text on a synchronized HUD channel.
519 * This is not the same as sending "" because it guarantees that it won't
520 * overwrite text on another channel. For example, consider the scenario:
522 * 1. Your synchronized message goes to channel 3.
523 * 2. Someone else's non-synchronized message goes to channel 3.
525 * If you were to simply send "" on your synchronized message,
526 * then someone else's text could be overwritten.
528 * @param client Client index to send the message to.
529 * @param sync Synchronization object.
531 * @error Client not in-game, or sync object not valid.
533 native ClearSyncHud(client, Handle:sync);
536 * Shows a HUD message to a client on the given channel.
538 * As of this writing, only TF, HL2MP, and SourceForts support HUD Text.
540 * @param client Client index to send the message to.
541 * @param channel A channel number.
542 * If -1, then a channel will automatically be selected
543 * based on the least-recently-used channel. If the
544 * channel is any other number, it will be modulo'd with
545 * the channel count to get a final channel number.
546 * @param message Message text or formatting rules.
547 * @param ... Message formatting parameters.
548 * @return -1 on failure (lack of mod support).
549 * Any other return value is the channel number that was
550 * used to render the text.
552 native ShowHudText(client, channel, const String:message[], any:...);
555 * Shows a MOTD panel to a specific client.
557 * @param client Client index.
558 * @param title Title of the panel (printed on the top border of the window).
559 * @param msg Contents of the panel, it can be treated as an url, filename or plain text
560 * depending on the type parameter (WARNING: msg has to be 192 bytes maximum!)
561 * @param type Determines the way to treat the message body of the panel.
563 * @error If the client is not connected an error will be thrown.
565 stock ShowMOTDPanel(client, const String:title[], const String:msg[], type=MOTDPANEL_TYPE_INDEX)
568 new Handle:Kv = CreateKeyValues("data");
569 IntToString(type, num, sizeof(num));
571 KvSetString(Kv, "title", title);
572 KvSetString(Kv, "type", num);
573 KvSetString(Kv, "msg", msg);
574 ShowVGUIPanel(client, "info", Kv);
579 * Displays a panel asking the client to connect to a specified IP.
581 * @param client Client index.
582 * @param time Duration to hold the panel on the client's screen.
583 * @param ip Destionation IP.
586 stock DisplayAskConnectBox(client, Float:time, const String:ip[])
588 new Handle:Kv = CreateKeyValues("data");
589 KvSetFloat(Kv, "time", time);
590 KvSetString(Kv, "title", ip);
591 CreateDialog(client, Kv, DialogType_AskConnect);
596 * Converts an entity index into a serial encoded entity reference.
598 * @param entity Entity index.
599 * @return Entity reference.
601 native EntIndexToEntRef(entity);
604 * Retrieves the entity index from a reference.
606 * @param ref Entity reference.
607 * @return Entity index.
609 native EntRefToEntIndex(ref);
612 * Converts a reference into a backwards compatible version.
614 * @param ref Entity reference.
615 * @return Bcompat reference.
617 native MakeCompatEntRef(ref);