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 _sourcemod_included
36 #define _sourcemod_included
39 * Plugin public information.
43 const String:name[], /**< Plugin Name */
44 const String:description[], /**< Plugin Description */
45 const String:author[], /**< Plugin Author */
46 const String:version[], /**< Plugin Version */
47 const String:url[], /**< Plugin URL */
68 #include <usermessages>
74 #include <commandfilters>
77 * Declare this as a struct in your plugin to expose its information.
80 * public Plugin:myinfo =
89 * Called when the plugin is fully initialized and all known external references
90 * are resolved. This is only called once in the lifetime of the plugin, and is
91 * paired with OnPluginEnd().
93 * If any run-time error is thrown during this callback, the plugin will be marked
96 * It is not necessary to close any handles or remove hooks in this function.
97 * SourceMod guarantees that plugin shutdown automatically and correctly releases
102 forward OnPluginStart();
105 * Called before OnPluginStart, in case the plugin wants to check for load failure.
106 * This is called even if the plugin type is "private." Any natives from modules are
107 * not available at this point. Thus, this forward should only be used for explicit
108 * pre-emptive things, such as adding dynamic natives, or setting certain types of load filters.
110 * @note It is not safe to call externally resolved natives until OnPluginStart().
111 * @note Any sort of RTE in this function will cause the plugin to fail loading.
112 * @note You MUST remember to return SOMETHING here. The act of not returning is
113 * equivalent to returning 0 (false). If you forgot to return, it will
114 * cause your plugin to not load with a very strange error message.
116 * @param myself Handle to the plugin.
117 * @param late Whether or not the plugin was loaded "late" (after map load).
118 * @param error Error message buffer in case load failed.
119 * @param err_max Maximum number of characters for error message buffer.
120 * @return True if load success, false otherwise.
122 forward bool:AskPluginLoad(Handle:myself, bool:late, String:error[], err_max);
125 * Called when the plugin is about to be unloaded.
129 forward OnPluginEnd();
132 * Called when the plugin's pause status is changing.
134 * @param pause True if the plugin is being paused, false otherwise.
137 forward OnPluginPauseChange(bool:pause);
140 * Called before every server frame. Note that you should avoid
141 * doing expensive computations here, and you should declare large
142 * local arrays using 'decl' instead of 'new'.
144 forward OnGameFrame();
147 * Called when the map is loaded.
149 * @note This used to be OnServerLoad(), which is now deprecated.
150 * Plugins still using the old forward will work.
152 forward OnMapStart();
155 * Called right before a map ends.
160 * Called when the map has loaded, servercfgfile (server.cfg) has been
161 * executed, and all plugin configs are done executing. This is the best
162 * place to initialize plugin functions which are based on cvar data.
164 * @note This will always be called once and only once per map. It will be
165 * called after OnMapStart().
169 forward OnConfigsExecuted();
172 * @deprecated Use OnConfigsExecuted() instead.
174 #pragma deprecated Use OnConfigsExecuted() instead
175 forward OnServerCfg();
178 * Called after all plugins have been loaded. This is called once for
179 * every plugin. If a plugin late loads, it will be called immediately
180 * after OnPluginStart().
182 forward OnAllPluginsLoaded();
185 * Returns the calling plugin's Handle.
187 * @return Handle of the calling plugin.
189 native Handle:GetMyHandle();
192 * Returns an iterator that can be used to search through plugins.
194 * @return Handle to iterate with. Must be closed via
196 * @error Invalid Handle.
198 native Handle:GetPluginIterator();
201 * Returns whether there are more plugins available in the iterator.
203 * @param iter Handle to the plugin iterator.
204 * @return True on more plugins, false otherwise.
205 * @error Invalid Handle.
207 native bool:MorePlugins(Handle:iter);
210 * Returns the current plugin in the iterator and advances the iterator.
212 * @param iter Handle to the plugin iterator.
213 * @return Current plugin the iterator is at, before
214 * the iterator is advanced.
215 * @error Invalid Handle.
217 native Handle:ReadPlugin(Handle:iter);
220 * Returns a plugin's status.
222 * @param plugin Plugin Handle (INVALID_HANDLE uses the calling plugin).
223 * @return Status code for the plugin.
224 * @error Invalid Handle.
226 native PluginStatus:GetPluginStatus(Handle:plugin);
229 * Retrieves a plugin's file name relative to the plugins folder.
231 * @param plugin Plugin Handle (INVALID_HANDLE uses the calling plugin).
232 * @param buffer Buffer to the store the file name.
233 * @param maxlength Maximum length of the name buffer.
235 * @error Invalid Handle.
237 native GetPluginFilename(Handle:plugin, String:buffer[], maxlength);
240 * Retrieves whether or not a plugin is being debugged.
242 * @param plugin Plugin Handle (INVALID_HANDLE uses the calling plugin).
243 * @return True if being debugged, false otherwise.
244 * @error Invalid Handle.
246 native bool:IsPluginDebugging(Handle:hndl);
249 * Retrieves a plugin's public info.
251 * @param plugin Plugin Handle (INVALID_HANDLE uses the calling plugin).
252 * @param info Plugin info property to retrieve.
253 * @param buffer Buffer to store info in.
254 * @param maxlength Maximum length of buffer.
255 * @return True on success, false if property is not available.
256 * @error Invalid Handle.
258 native bool:GetPluginInfo(Handle:plugin, PluginInfo:info, String:buffer[], maxlength);
261 * Finds a plugin by its order in the list from the "plugins list" server
262 * "sm" command. You should not use this function to loop through all plugins,
263 * use the iterator instead. Looping through all plugins using this native
264 * is O(n^2), whereas using the iterator is O(n).
266 * @param order_num Number of the plugin as it appears in "sm plugins list".
267 * @return Plugin Handle on success, INVALID_HANDLE if no plugin
268 * matches the given number.
270 native Handle:FindPluginByNumber(order_num);
273 * Causes the plugin to enter a failed state. An error will be thrown and
274 * the plugin will be paused until it is unloaded or reloaded.
276 * For backwards compatibility, if no extra arguments are passed, no
277 * formatting is applied. If one or more additional arguments is passed,
278 * the string is formatted using Format(). If any errors are encountered
279 * during formatting, both the format specifier string and an additional
280 * error message are written.
282 * This function does not return, and no further code in the plugin is
285 * @param string Format specifier string.
286 * @param ... Formatting arguments.
288 * @error Always throws SP_ERROR_ABORT.
290 native SetFailState(const String:string[], any:...);
293 * Aborts the current callback and throws an error. This function
294 * does not return in that no code is executed following it.
296 * @param format String format.
297 * @param ... Format arguments.
301 native ThrowError(const String:fmt[], any:...);
304 * Gets the system time as a unix timestamp.
306 * @param bigStamp Optional array to store the 64bit timestamp in.
307 * @return 32bit timestamp (number of seconds since unix epoch).
309 native GetTime(bigStamp[2]={0,0});
312 * Produces a date and/or time string value for a timestamp.
314 * See this URL for valid parameters:
315 * http://opengroup.org/onlinepubs/007908799/xsh/strftime.html
317 * @param buffer Destination string buffer.
318 * @param maxlength Maximum length of output string buffer.
319 * @param format Formatting rules (passing NULL_STRING will use the rules defined in sm_datetime_format).
320 * @param stamp Optional time stamp.
322 * @error Buffer too small or invalid time format.
324 native FormatTime(String:buffer[], maxlength, const String:format[], stamp=-1);
327 * Loads a game config file.
329 * @param file File to load. The path must be relative to the 'gamedata' folder under the config folder
330 * and the extension should be omitted.
331 * @return A handle to the game config file or INVALID_HANDLE in failure.
333 native Handle:LoadGameConfigFile(const String:file[]);
336 * Returns an offset value.
338 * @param gc Game config handle.
339 * @param key Key to retrieve from the offset section.
340 * @return An offset, or -1 on failure.
342 native GameConfGetOffset(Handle:gc, const String:key[]);
345 * Gets the value of a key from the "Keys" section.
347 * @param gc Game config handle.
348 * @param key Key to retrieve from the Keys section.
349 * @param buffer Destination string buffer.
350 * @param maxlen Maximum length of output string buffer.
351 * @return True if key existed, false otherwise.
353 native bool:GameConfGetKeyValue(Handle:gc, const String:key[], String:buffer[], maxlen);
356 * Returns the operating system's "tick count," which is a number of
357 * milliseconds since the operating system loaded. This can be used
358 * for basic benchmarks.
360 * @return Tick count in milliseconds.
362 native GetSysTickCount();
365 * Specifies that the given config file should be executed after plugin load.
366 * OnConfigsExecuted() will not be called until the config file has executed,
367 * but it will be called if the execution fails.
369 * @param autoCreate If true, and the config file does not exist, such a config
370 * file will be automatically created and populated with
371 * information from the plugin's registered cvars.
372 * @param name Name of the config file, excluding the .cfg extension.
373 * If empty, <plugin.filename.cfg> is assumed.
374 * @param folder Folder under cfg/ to use. By default this is "sourcemod."
377 native AutoExecConfig(bool:autoCreate=true, const String:name[]="", const String:folder[]="sourcemod");
380 * Sets a native as optional, such that if it is unloaded, removed,
381 * or otherwise non-existent, the plugin will still work. Calling
382 * removed natives results in a run-time error.
384 * @param name Native name.
387 native MarkNativeAsOptional(const String:name[]);
390 * Registers a library name for identifying as a dependency to
393 * @param name Library name.
396 native RegPluginLibrary(const String:name[]);
399 * Returns whether a library exists. This function should be considered
400 * expensive; it should only be called on plugin to determine availability
401 * of resources. Use OnLibraryAdded()/OnLibraryRemoved() to detect changes
402 * in optional resources.
404 * @param name Library name of a plugin or extension.
405 * @return True if exists, false otherwise.
407 native bool:LibraryExists(const String:name[]);
410 * Returns the status of an extension, by filename.
412 * @param name Extension name (like "sdktools.ext").
413 * @param error Optional error message buffer.
414 * @param maxlength Length of optional error message buffer.
415 * @return -2 if the extension was not found.
416 * -1 if the extension was found but failed to load.
417 * 0 if the extension loaded but reported an error.
418 * 1 if the extension is running without error.
420 native GetExtensionFileStatus(const String:name[], String:error[]="", maxlength=0);
423 * Called after a library is added that the current plugin references
424 * optionally. A library is either a plugin name or extension name, as
425 * exposed via its include file.
427 * @param name Library name.
429 forward OnLibraryAdded(const String:name[]);
432 * Called right before a library is removed that the current plugin references
433 * optionally. A library is either a plugin name or extension name, as
434 * exposed via its include file.
436 * @param name Library name.
438 forward OnLibraryRemoved(const String:name[]);
440 #define MAPLIST_FLAG_MAPSFOLDER (1<<0) /**< On failure, use all maps in the maps folder. */
441 #define MAPLIST_FLAG_CLEARARRAY (1<<1) /**< If an input array is specified, clear it before adding. */
442 #define MAPLIST_FLAG_NO_DEFAULT (1<<2) /**< Do not read "default" or "mapcyclefile" on failure. */
445 * Loads a map list to an ADT Array.
447 * A map list is a list of maps from a file. SourceMod allows easy configuration of
448 * maplists through addons/sourcemod/configs/maplists.cfg. Each entry is given a
449 * name and a file (for example, "rtv" => "rtv.cfg"), or a name and a redirection
450 * (for example, "rtv" => "default"). This native will read a map list entry,
451 * cache the file, and return the list of maps it holds.
453 * Serial change numbers are used to identify if a map list has changed. Thus, if
454 * you pass a serial change number and it's equal to what SourceMod currently knows
455 * about the map list, then SourceMod won't reparse the file.
457 * If the maps end up being read from the maps folder (MAPLIST_FLAG_MAPSFOLDER), they
458 * are automatically sorted in alphabetical, ascending order.
460 * Arrays created by this function are temporary and must be freed via CloseHandle().
461 * Modifying arrays created by this function will not affect future return values or
462 * or the contents of arrays returned to other plugins.
464 * @param array Array to store the map list. If INVALID_HANDLE, a new blank
465 * array will be created. The blocksize should be at least 16;
466 * otherwise results may be truncated. Items are added to the array
467 * as strings. The array is never checked for duplicates, and it is
468 * not read beforehand. Only the serial number is used to detect
470 * @param serial Serial number to identify last known map list change. If -1, the
471 * the value will not be checked. If the map list has since changed,
472 * the serial is updated (even if -1 was passed). If there is an error
473 * finding a valid maplist, then the serial is set to -1.
474 * @param str Config name, or "default" for the default map list. Config names
475 * should be somewhat descriptive. For example, the admin menu uses
476 * a config name of "admin menu". The list names can be configured
477 * by users in addons/sourcemod/configs/maplists.cfg.
478 * @param flags MAPLIST_FLAG flags.
479 * @return On failure:
480 * INVALID_HANDLE is returned, the serial is set to -1, and the input
481 * array (if any) is left unchanged.
483 INVALID_HANDLE is returned, the serial is unchanged, and the input
484 array (if any) is left unchanged.
486 * A valid array Handle is returned, containing at least one map string.
487 * If an array was passed, the return value is equal to the passed Array
488 * Handle. If the passed array was not cleared, it will have grown by at
489 * least one item. The serial number is updated to a positive number.
490 * @error Invalid array Handle that is not INVALID_HANDLE.
492 native Handle:ReadMapList(Handle:array=INVALID_HANDLE,
494 const String:str[]="default",
495 flags=MAPLIST_FLAG_CLEARARRAY);
498 * Makes a compatibility binding for map lists. For example, if a function previously used
499 * "clam.cfg" for map lists, this function will insert a "fake" binding to "clam.cfg" that
500 * will be overridden if it's in the maplists.cfg file.
502 * @param name Configuration name that would be used with ReadMapList().
503 * @param file Default file to use.
506 native SetMapListCompatBind(const String:name[], const String:file[]);
509 * Called when a client has sent chat text. This must return either true or
510 * false to indicate that a client is or is not spamming the server.
512 * The return value is a hint only. Core or another plugin may decide
515 * @param client Client index. The server (0) will never be passed.
516 * @return True if client is spamming the server, false otherwise.
518 forward bool:OnClientFloodCheck(client);
521 * Called after a client's flood check has been computed. This can be used
522 * by antiflood algorithms to decay/increase flooding weights.
524 * Since the result from "OnClientFloodCheck" isn't guaranteed to be the
525 * final result, it is generally a good idea to use this to play with other
528 * @param client Client index. The server (0) will never be passed.
529 * @param blocked True if client flooded last "say", false otherwise.
532 forward OnClientFloodResult(client, bool:blocked);
536 #include <entity_prop_stocks>