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 */
49 #include <usermessages>
55 * Declare this as a struct in your plugin to expose its information.
58 * public Plugin:myinfo =
67 * Called when the plugin is fully initialized and all known external references are resolved.
68 * This is called even if the plugin type is "private."
69 * @note Errors in this function will cause the plugin to stop running.
73 forward OnPluginStart();
76 * Called before OnPluginStart, in case the plugin wants to check for load failure.
77 * This is called even if the plugin type is "private." Any natives from modules are
78 * not available at this point. Thus, this forward should only be used for explicit
79 * pre-emptive things, such as adding dynamic natives, or setting certain types of load filters.
81 * @note It is not safe to call externally resolved natives until OnPluginStart().
82 * @note Any sort of RTE in this function will cause the plugin to fail loading.
84 * @param myself Handle to the plugin.
85 * @param late Whether or not the plugin was loaded "late" (after map load).
86 * @param error Error message buffer in case load failed.
87 * @param err_max Maximum number of characters for error message buffer.
88 * @return True if load success, false otherwise.
90 forward bool:AskPluginLoad(Handle:myself, bool:late, String:error[], err_max);
93 * Called when the plugin is about to be unloaded.
97 forward OnPluginEnd();
100 * Called when the plugin's pause status is changing.
102 * @param pause True if the plugin is being paused, false otherwise.
105 forward OnPluginPauseChange(bool:pause);
108 * Called before every server frame. Note that you should avoid
109 * doing expensive computations here, and you should declare large
110 * local arrays using 'decl' instead of 'new'.
112 forward OnGameFrame();
115 * Called when the map is loaded.
117 * @note This used to be OnServerLoad(), which is now deprecated.
118 * Plugins still using the old forward will work.
120 forward OnMapStart();
123 * Called right before a map ends.
128 * Called when the map has loaded, servercfgfile (server.cfg) has been
129 * executed, and all plugin configs are done executing. This is the best
130 * place to inialize plugin functions which are based on cvar data.
132 * @note This will always be called once and only once per map. It will be
133 * called after OnMapStart().
137 forward OnConfigsExecuted();
140 * @deprecated Use OnConfigsExecuted() instead.
142 forward OnServerCfg();
145 * Returns the calling plugin's Handle.
147 * @return Handle of the calling plugin.
149 native Handle:GetMyHandle();
152 * Returns an iterator that can be used to search through plugins.
154 * @return Handle to iterate with. Must be closed via
156 * @error Invalid Handle.
158 native Handle:GetPluginIterator();
161 * Returns whether there are more plugins available in the iterator.
163 * @param iter Handle to the plugin iterator.
164 * @return True on more plugins, false otherwise.
165 * @error Invalid Handle.
167 native bool:MorePlugins(Handle:iter);
170 * Returns the current plugin in the iterator and advances the iterator.
172 * @param iter Handle to the plugin iterator.
173 * @return Current plugin the iterator is at, before
174 * the iterator is advanced.
175 * @error Invalid Handle.
177 native Handle:ReadPlugin(Handle:iter);
180 * Returns a plugin's status.
182 * @param plugin Plugin Handle (INVALID_HANDLE uses the calling plugin).
183 * @return Status code for the plugin.
184 * @error Invalid Handle.
186 native PluginStatus:GetPluginStatus(Handle:plugin);
189 * Retrieves a plugin's file name relative to the plugins folder.
191 * @param plugin Plugin Handle (INVALID_HANDLE uses the calling plugin).
192 * @param buffer Buffer to the store the file name.
193 * @param maxlength Maximum length of the name buffer.
195 * @error Invalid Handle.
197 native GetPluginFilename(Handle:plugin, String:buffer[], maxlength);
200 * Retrieves whether or not a plugin is being debugged.
202 * @param plugin Plugin Handle (INVALID_HANDLE uses the calling plugin).
203 * @return True if being debugged, false otherwise.
204 * @error Invalid Handle.
206 native bool:IsPluginDebugging(Handle:hndl);
209 * Retrieves a plugin's public info.
211 * @param plugin Plugin Handle (INVALID_HANDLE uses the calling plugin).
212 * @param info Plugin info property to retrieve.
213 * @param buffer Buffer to store info in.
214 * @param maxlength Maximum length of buffer.
215 * @return True on success, false if property is not available.
216 * @error Invalid Handle.
218 native bool:GetPluginInfo(Handle:plugin, PluginInfo:info, String:buffer[], maxlength);
221 * Causes the plugin to enter a failed state. An error will be thrown and
222 * the plugin will be paused until it is unloaded or reloaded.
224 * @param string Message to print.
226 * @error Always throws SP_ERROR_ABORT.
228 native SetFailState(const String:string[]);
231 * Aborts the current callback and throws an error. This function
232 * does not return in that no code is executed following it.
234 * @param format String format.
235 * @param ... Format arguments.
239 native ThrowError(const String:fmt[], any:...);
242 * Logs a plugin message to the SourceMod logs.
244 * @param format String format.
245 * @param ... Format arguments.
248 native LogMessage(const String:format[], any:...);
251 * Logs a plugin error message to the SourceMod logs.
253 * @param format String format.
254 * @param ... Format arguments.
257 native LogError(const String:format[], any:...);
260 * Gets the system time as a unix timestamp.
262 * @param bigStamp Optional array to store the 64bit timestamp in.
263 * @return 32bit timestamp (number of seconds since unix epoch).
265 native GetTime(bigStamp[2]={0,0});
268 * Loads a game config file.
270 * @param file File to load. The path must be relative to the 'gamedata' folder under the config folder
271 * and the extension should be omitted.
272 * @return A handle to the game config file or INVALID_HANDLE in failure.
274 native Handle:LoadGameConfigFile(const String:file[]);
277 * Returns an offset value.
279 * @param gc Game config handle.
280 * @param key Key to retrieve from the offset section.
281 * @return An offset, or -1 on failure.
283 native GameConfGetOffset(Handle:gc, const String:key[]);
286 * Gets the value of a key from the "Keys" section.
288 * @param gc Game config handle.
289 * @param key Key to retrieve from the Keys section.
290 * @param buffer Destination string buffer.
291 * @param maxlen Maximum length of output string buffer.
292 * @return True if key existed, false otherwise.
294 native bool:GameConfGetKeyValue(Handle:gc, const String:key[], String:buffer[], maxlen);
297 * Returns the operating system's "tick count," which is a number of
298 * milliseconds since the operating system loaded. This can be used
299 * for basic benchmarks.
301 * @return Tick count in milliseconds.
303 native GetSysTickCount();
306 * Specifies that the given config file should be executed after plugin load.
307 * OnConfigsExecuted() will not be called until the config file has executed,
308 * but it will be called if the execution fails.
310 * @param autoCreate If true, and the config file does not exist, such a config
311 * file will be automatically created and populated with
312 * information from the plugin's registered cvars.
313 * @param name Name of the config file, excluding the .cfg extension.
314 * If empty, <plugin.filename.cfg> is assumed.
315 * @param folder Folder under cfg/ to use. By default this is "sourcemod."
318 native AutoExecConfig(bool:autoCreate=true, const String:name[]="", const String:folder[]="sourcemod");