3 * ===============================================================
4 * SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved.
5 * ===============================================================
7 * This file is part of the SourceMod/SourcePawn SDK. This file may only be used
8 * or modified under the Terms and Conditions of its License Agreement, which is found
9 * in LICENSE.txt. The Terms and Conditions for making SourceMod extensions/plugins
10 * may change at any time. To view the latest information, see:
11 * http://www.sourcemod.net/license.php
16 #if defined _sourcemod_included
19 #define _sourcemod_included
22 * Plugin public information.
26 const String:name[], /**< Plugin Name */
27 const String:description[], /**< Plugin Description */
28 const String:author[], /**< Plugin Author */
29 const String:version[], /**< Plugin Version */
30 const String:url[], /**< Plugin URL */
43 #include <usermessages>
50 DialogType_Msg = 0, /**< just an on screen message */
51 DialogType_Menu, /**< an options menu */
52 DialogType_Text, /**< a richtext dialog */
53 DialogType_Entry /**< an entry box */
57 * Declare this as a struct in your plugin to expose its information.
60 * public Plugin:myinfo =
69 * Called when the plugin is fully initialized and all known external references are resolved.
70 * This is called even if the plugin type is "private."
71 * @note Errors in this function will cause the plugin to stop running.
75 forward OnPluginStart();
78 * Called before OnPluginStart, in case the plugin wants to check for load failure.
79 * This is called even if the plugin type is "private." Any natives from modules are
80 * not available at this point. Thus, this forward should only be used for explicit
81 * pre-emptive things, such as adding dynamic natives, or setting certain types of load filters.
83 * @note It is not safe to call externally resolved natives until OnPluginStart().
84 * @note Any sort of RTE in this function will cause the plugin to fail loading.
86 * @param myself Handle to the plugin.
87 * @param late Whether or not the plugin was loaded "late" (after map load).
88 * @param error Error message buffer in case load failed.
89 * @param err_max Maximum number of characters for error message buffer.
90 * @return True if load success, false otherwise.
92 forward bool:AskPluginLoad(Handle:myself, bool:late, String:error[], err_max);
95 * Called when the plugin is about to be unloaded.
99 forward OnPluginEnd();
102 * Called when the plugin's pause status is changing.
104 * @param pause True if the plugin is being paused, false otherwise.
107 forward OnPluginPauseChange(bool:pause);
110 * Called before every server frame. Note that you should avoid
111 * doing expensive computations here, and you should declare large
112 * local arrays using 'decl' instead of 'new'.
114 forward OnGameFrame();
117 * Called when the map is loaded.
119 * @note This used to be OnServerLoad(), which is now deprecated.
120 * Plugins still using the old forward will work.
122 forward OnMapStart();
125 * Called right before a map ends.
130 * Called when the map has loaded and the servercfgfile has finished
131 * executing. This is usually 'server.cfg' but most mods allow it to
132 * be set via 'servercfgfile'.
134 * @note If server.cfg is executed more than once per map, this forward
135 * will only be called the first time (per map).
137 forward OnServerCfg();
140 * Returns the calling plugin's Handle.
142 * @return Handle of the calling plugin.
144 native Handle:GetMyHandle();
147 * Returns an iterator that can be used to search through plugins.
149 * @return Handle to iterate with. Must be closed via
151 * @error Invalid Handle.
153 native Handle:GetPluginIterator();
156 * Returns whether there are more plugins available in the iterator.
158 * @param iter Handle to the plugin iterator.
159 * @return True on more plugins, false otherwise.
160 * @error Invalid Handle.
162 native bool:MorePlugins(Handle:iter);
165 * Returns the current plugin in the iterator and advances the iterator.
167 * @param iter Handle to the plugin iterator.
168 * @return Current plugin the iterator is at, before
169 * the iterator is advanced.
170 * @error Invalid Handle.
172 native Handle:ReadPlugin(Handle:iter);
175 * Returns a plugin's status.
177 * @param plugin Plugin Handle (INVALID_HANDLE uses the calling plugin).
178 * @return Status code for the plugin.
179 * @error Invalid Handle.
181 native PluginStatus:GetPluginStatus(Handle:plugin);
184 * Retrieves a plugin's file name relative to the plugins folder.
186 * @param plugin Plugin Handle (INVALID_HANDLE uses the calling plugin).
187 * @param buffer Buffer to the store the file name.
188 * @param maxlength Maximum length of the name buffer.
190 * @error Invalid Handle.
192 native GetPluginFilename(Handle:plugin, String:buffer[], maxlength);
195 * Retrieves whether or not a plugin is being debugged.
197 * @param plugin Plugin Handle (INVALID_HANDLE uses the calling plugin).
198 * @return True if being debugged, false otherwise.
199 * @error Invalid Handle.
201 native bool:IsPluginDebugging(Handle:hndl);
204 * Retrieves a plugin's public info.
206 * @param plugin Plugin Handle (INVALID_HANDLE uses the calling plugin).
207 * @param info Plugin info property to retrieve.
208 * @param buffer Buffer to store info in.
209 * @param maxlength Maximum length of buffer.
210 * @return True on success, false if property is not available.
211 * @error Invalid Handle.
213 native bool:GetPluginInfo(Handle:plugin, PluginInfo:info, String:buffer[], maxlength);
216 * Aborts the current callback and throws an error. This function
217 * does not return in that no code is executed following it.
219 * @param format String format.
220 * @param ... Format arguments.
224 native ThrowError(const String:fmt[], any:...);
227 * Logs a generic message to the HL2 logs.
229 * @param format String format.
230 * @param ... Format arguments.
233 native LogToGame(const String:format[], any:...);
236 * Logs a plugin message to the SourceMod logs.
238 * @param format String format.
239 * @param ... Format arguments.
242 native LogMessage(const String:format[], any:...);
245 * Logs a plugin error message to the SourceMod logs.
247 * @param format String format.
248 * @param ... Format arguments.
251 native LogError(const String:format[], any:...);
254 * Gets the system time as a unix timestamp.
256 * @param bigStamp Optional array to store the 64bit timestamp in.
257 * @return 32bit timestamp (number of seconds since unix epoch).
259 native GetTime(bigStamp[2]={0,0});
262 * Sets the seed value for the global Half-Life 2 Random Stream
264 * @param seed Seed value.
267 native SetRandomSeed(seed);
270 * Returns a random floating point number from the Half-Life 2 Random Stream
272 * @param fMin Minimum random bound.
273 * @param fMax Maximum random bound.
274 * @return A random number between (inclusive) fMin and fMax.
276 native Float:GetRandomFloat(Float:fMin=0.0, Float:fMax=1.0);
279 * Returns a random number from the Half-Life 2 Random Stream
281 * @param nmin Minimum random bound.
282 * @param nmax Maximum random bound.
283 * @return A random number between (inclusive) nmin and nmax.
285 native GetRandomInt(nmin, nmax);
288 * Returns whether a map is valid or not.
290 * @param Map name, excluding .bsp extension.
291 * @return True if valid, false otherwise.
293 native bool:IsMapValid(const String:map[]);
296 * Returns whether the server is dedicated.
298 * @return True if dedicated, false otherwise.
300 native bool:IsDedicatedServer();
303 * Returns a high-precision time value for profiling the engine.
305 * @return A floating point time value.
307 native Float:GetEngineTime();
310 * Returns the game time based on the game tick.
312 * @return Game tick time.
314 native Float:GetGameTime();
317 * Returns the game description from the mod.
319 * @param buffer Buffer to store the description.
320 * @param maxlength Maximum size of the buffer.
321 * @param original If true, retrieves the original game description,
322 * ignoring any potential hooks from plugins.
323 * @return Number of bytes written to the buffer (UTF-8 safe).
325 native GetGameDescription(String:buffer[], maxlength, bool:original=false);
328 * Returns the name of the game's directory.
330 * @param buffer Buffer to store the directory name.
331 * @param maxlength Maximum size of the buffer.
333 * return Number of bytes written to the buffer (UTF-8 safe).
335 native GetGameFolderName(String:buffer[], maxlength);
338 * Returns the current map name.
340 * @param buffer Buffer to store map name.
341 * @param maxlength Maximum length of buffer.
342 * @return Number of bytes written (UTF-8 safe).
344 native GetCurrentMap(String:buffer[], maxlength);
347 * Precaches a given model.
349 * @param model Name of the model to precache.
350 * @param preload If preload is true the file will be precached before level startup.
351 * @return Returns the model index, 0 for error.
353 native PrecacheModel(const String:model[], bool:preload=false);
356 * Precaches a given sentence file.
358 * @param file Name of the sentence file to precache.
359 * @param preload If preload is true the file will be precached before level startup.
360 * @return Returns a sentence file index.
362 native PrecacheSentenceFile(const String:file[], bool:preload=false);
365 * Precaches a given decal.
367 * @param decal Name of the decal to precache.
368 * @param preload If preload is true the file will be precached before level startup.
369 * @return Returns a decal index.
371 native PrecacheDecal(const String:decal[], bool:preload=false);
374 * Precaches a given generic file.
376 * @param generic Name of the generic file to precache.
377 * @param preload If preload is true the file will be precached before level startup.
378 * @return Returns a generic file index.
380 native PrecacheGeneric(const String:generic[], bool:preload=false);
383 * Returns if a given model is precached.
385 * @param model Name of the model to check.
386 * @return True if precached, false otherwise.
388 native bool:IsModelPrecached(const String:model[]);
391 * Returns if a given decal is precached.
393 * @param decal Name of the decal to check.
394 * @return True if precached, false otherwise.
396 native bool:IsDecalPrecached(const String:decal[]);
399 * Returns if a given generic file is precached.
401 * @param decal Name of the generic file to check.
402 * @return True if precached, false otherwise.
404 native bool:IsGenericPrecached(const String:generic[]);
407 * Precaches a given sound.
409 * @param sound Name of the sound to precache.
410 * @param preload If preload is true the file will be precached before level startup.
411 * @return True if successfully precached, false otherwise.
413 native bool:PrecacheSound(const String:sound[], bool:preload=false);
416 * Returns if a given sound is precached.
418 * @param sound Name of the sound to check.
419 * @return True if precached, false otherwise.
421 native bool:IsSoundPrecached(const String:sound[]);
424 * Creates different types of ingame messages.
426 * @param client Index of the client.
427 * @param kv KeyValues handle to set the menu keys and options. (Check iserverplugin.h for more information).
428 * @param type Message type to display ingame.
430 * @error Invalid client index, or client not connected.
432 native CreateDialog(client, Handle:kv, DialogType:type);
435 * Loads a game config file.
437 * @param file File to load. The path must be relative to the 'gamedata' folder under the config folder
438 * and the extension should be omitted.
439 * @return A handle to the game config file or INVALID_HANDLE in failure.
441 native Handle:LoadGameConfigFile(const String:file[]);
444 * Returns an offset value.
446 * @param gc Game config handle.
447 * @param key Key to retrieve from the offset section.
448 * @return An offset, or -1 on failure.
450 native GameConfGetOffset(Handle:gc, const String:key[]);
453 * Gets the value of a key from the "Keys" section.
455 * @param gc Game config handle.
456 * @param key Key to retrieve from the Keys section.
457 * @param buffer Destination string buffer.
458 * @param maxlen Maximum length of output string buffer.
459 * @return True if key existed, false otherwise.
461 native bool:GameConfGetKeyValue(Handle:gc, const String:key[], String:buffer[], maxlen);