dvander@429: /** ds@475: * vim: set ts=4 : dvander@429: * =============================================================== dvander@429: * SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved. dvander@429: * =============================================================== dvander@429: * dvander@429: * This file is part of the SourceMod/SourcePawn SDK. This file may only be used dvander@429: * or modified under the Terms and Conditions of its License Agreement, which is found dvander@429: * in LICENSE.txt. The Terms and Conditions for making SourceMod extensions/plugins dvander@429: * may change at any time. To view the latest information, see: dvander@429: * http://www.sourcemod.net/license.php dvander@429: * faluco@506: * Version: $Id$ dvander@429: */ dvander@429: dvander@429: #if defined _sourcemod_included dvander@429: #endinput dvander@429: #endif dvander@429: #define _sourcemod_included dvander@429: dvander@619: /** dvander@619: * Plugin public information. dvander@619: */ dvander@429: struct Plugin dvander@429: { dvander@619: const String:name[], /**< Plugin Name */ dvander@619: const String:description[], /**< Plugin Description */ dvander@619: const String:author[], /**< Plugin Author */ dvander@619: const String:version[], /**< Plugin Version */ dvander@619: const String:url[], /**< Plugin URL */ dvander@429: }; dvander@429: dvander@429: #include dvander@429: #include dvander@429: #include dvander@429: #include dvander@429: #include dvander@429: #include ds@457: #include faluco@505: #include dvander@535: #include dvander@545: #include ds@576: #include ds@576: #include dvander@601: #include dvander@643: #include dvander@429: dvander@429: /** dvander@429: * Declare this as a struct in your plugin to expose its information. dvander@429: * Example: dvander@429: * dvander@429: * public Plugin:myinfo = dvander@429: * { dvander@429: * name = "My Plugin", dvander@429: * //etc dvander@429: * }; dvander@429: */ dvander@429: public Plugin:myinfo; dvander@429: dvander@429: /** dvander@429: * Called when the plugin is fully initialized and all known external references are resolved. dvander@429: * This is called even if the plugin type is "private." dvander@619: * @note Errors in this function will cause the plugin to stop running. dvander@429: * dvander@429: * @noreturn dvander@429: */ dvander@536: forward OnPluginStart(); dvander@429: dvander@429: /** dvander@429: * Called before OnPluginStart, in case the plugin wants to check for load failure. dvander@429: * This is called even if the plugin type is "private." Any natives from modules are dvander@429: * not available at this point. Thus, this forward should only be used for explicit dvander@429: * pre-emptive things, such as adding dynamic natives, or setting certain types of load filters. dvander@429: * dvander@619: * @note It is not safe to call externally resolved natives until OnPluginStart(). dvander@619: * @note Any sort of RTE in this function will cause the plugin to fail loading. dvander@429: * dvander@429: * @param myself Handle to the plugin. dvander@429: * @param late Whether or not the plugin was loaded "late" (after map load). dvander@429: * @param error Error message buffer in case load failed. dvander@429: * @param err_max Maximum number of characters for error message buffer. dvander@429: * @return True if load success, false otherwise. dvander@429: */ dvander@429: forward bool:AskPluginLoad(Handle:myself, bool:late, String:error[], err_max); dvander@429: dvander@429: /** dvander@429: * Called when the plugin is about to be unloaded. dvander@429: * dvander@429: * @noreturn dvander@429: */ dvander@429: forward OnPluginEnd(); dvander@429: dvander@429: /** dvander@429: * Called when the plugin's pause status is changing. dvander@429: * ds@475: * @param pause True if the plugin is being paused, false otherwise. dvander@429: * @noreturn dvander@429: */ dvander@429: forward OnPluginPauseChange(bool:pause); dvander@429: dvander@429: /** dvander@531: * Called before every server frame. Note that you should avoid dvander@531: * doing expensive computations here, and you should declare large dvander@531: * local arrays using 'decl' instead of 'new'. dvander@531: */ dvander@531: forward OnGameFrame(); dvander@531: dvander@531: /** dvander@643: * Called when the map is loaded and configs have been parsed. dvander@643: * Note that commands are processed per-frame, and thus config dvander@643: * files may not be fully loaded until a few seconds later. faluco@651: * This function will be called on each mapchange. dvander@643: */ dvander@643: forward OnServerLoad(); dvander@643: dvander@643: /** dvander@536: * Returns the calling plugin's Handle. dvander@536: * dvander@536: * @return Handle of the calling plugin. dvander@536: */ dvander@536: native Handle:GetMyHandle(); dvander@536: dvander@618: /** dvander@618: * Returns an iterator that can be used to search through plugins. dvander@618: * dvander@618: * @return Handle to iterate with. Must be closed via dvander@618: * CloseHandle(). dvander@618: * @error Invalid Handle. dvander@618: */ dvander@618: native Handle:GetPluginIterator(); dvander@618: dvander@618: /** dvander@618: * Returns whether there are more plugins available in the iterator. dvander@618: * dvander@618: * @param iter Handle to the plugin iterator. dvander@618: * @return True on more plugins, false otherwise. dvander@618: * @error Invalid Handle. dvander@618: */ dvander@618: native bool:MorePlugins(Handle:iter); dvander@618: dvander@618: /** dvander@618: * Returns the current plugin in the iterator and advances the iterator. dvander@618: * dvander@618: * @param iter Handle to the plugin iterator. dvander@618: * @return Current plugin the iterator is at, before dvander@618: * the iterator is advanced. dvander@618: * @error Invalid Handle. dvander@618: */ dvander@618: native Handle:ReadPlugin(Handle:iter); dvander@618: dvander@618: /** dvander@618: * Returns a plugin's status. dvander@618: * dvander@618: * @param plugin Plugin Handle (INVALID_HANDLE uses the calling plugin). dvander@618: * @return Status code for the plugin. dvander@618: * @error Invalid Handle. dvander@618: */ dvander@618: native PluginStatus:GetPluginStatus(Handle:plugin); dvander@618: dvander@618: /** dvander@618: * Retrieves a plugin's file name relative to the plugins folder. dvander@618: * dvander@618: * @param plugin Plugin Handle (INVALID_HANDLE uses the calling plugin). dvander@618: * @param buffer Buffer to the store the file name. dvander@618: * @param maxlength Maximum length of the name buffer. dvander@618: * @noreturn dvander@618: * @error Invalid Handle. dvander@618: */ dvander@618: native GetPluginFilename(Handle:plugin, String:buffer[], maxlength); dvander@618: dvander@618: /** dvander@618: * Retrieves whether or not a plugin is being debugged. dvander@618: * dvander@618: * @param plugin Plugin Handle (INVALID_HANDLE uses the calling plugin). dvander@618: * @return True if being debugged, false otherwise. dvander@618: * @error Invalid Handle. dvander@618: */ dvander@618: native bool:IsPluginDebugging(Handle:hndl); dvander@618: dvander@618: /** dvander@618: * Retrieves a plugin's public info. dvander@618: * dvander@618: * @param plugin Plugin Handle (INVALID_HANDLE uses the calling plugin). dvander@618: * @param info Plugin info property to retrieve. dvander@618: * @param buffer Buffer to store info in. dvander@618: * @param maxlength Maximum length of buffer. dvander@618: * @return True on success, false if property is not available. dvander@618: * @error Invalid Handle. dvander@618: */ dvander@618: native bool:GetPluginInfo(Handle:plugin, PluginInfo:info, String:buffer[], maxlength); dvander@560: dvander@560: /** dvander@560: * Aborts the current callback and throws an error. This function dvander@560: * does not return in that no code is executed following it. dvander@560: * dvander@560: * @param format String format. dvander@560: * @param ... Format arguments. dvander@560: * @noreturn dvander@560: * @error Always! dvander@560: */ ds@634: native ThrowError(const String:fmt[], any:...); dvander@560: dvander@536: /** dvander@429: * Logs a generic message to the HL2 logs. dvander@429: * ds@475: * @param format String format. ds@475: * @param ... Format arguments. dvander@429: * @noreturn dvander@429: */ ds@634: native LogToGame(const String:format[], any:...); dvander@429: dvander@429: /** dvander@429: * Logs a plugin message to the SourceMod logs. dvander@429: * ds@475: * @param format String format. ds@475: * @param ... Format arguments. dvander@429: * @noreturn dvander@429: */ ds@634: native LogMessage(const String:format[], any:...); dvander@429: dvander@429: /** dvander@429: * Logs a plugin error message to the SourceMod logs. dvander@429: * ds@475: * @param format String format. ds@475: * @param ... Format arguments. dvander@429: * @noreturn dvander@429: */ ds@634: native LogError(const String:format[], any:...); dvander@460: dvander@530: /** dvander@595: * Gets the system time as a unix timestamp. dvander@595: * dvander@595: * @param bigStamp Optional array to store the 64bit timestamp in. dvander@595: * @return 32bit timestamp (number of seconds since unix epoch). dvander@595: */ dvander@595: native GetTime(bigStamp[2]={0,0}); dvander@595: dvander@595: /** dvander@530: * Sets the seed value for the global Half-Life 2 Random Stream dvander@530: * dvander@530: * @param seed Seed value. dvander@530: * @noreturn dvander@530: */ dvander@530: native SetRandomSeed(seed); dvander@530: dvander@530: /** dvander@530: * Returns a random floating point number from the Half-Life 2 Random Stream dvander@530: * dvander@530: * @param fMin Minimum random bound. dvander@530: * @param fMax Maximum random bound. dvander@530: * @return A random number between (inclusive) fMin and fMax. dvander@530: */ dvander@530: native Float:GetRandomFloat(Float:fMin=0.0, Float:fMax=1.0); dvander@530: dvander@530: /** dvander@530: * Returns a random number from the Half-Life 2 Random Stream dvander@530: * dvander@530: * @param nmin Minimum random bound. dvander@530: * @param nmax Maximum random bound. dvander@530: * @return A random number between (inclusive) nmin and nmax. dvander@530: */ dvander@530: native GetRandomInt(nmin, nmax); dvander@530: dvander@532: /** dvander@532: * Returns whether a map is valid or not. dvander@532: * dvander@532: * @param Map name, excluding .bsp extension. dvander@532: * @return True if valid, false otherwise. dvander@532: */ dvander@532: native bool:IsMapValid(const String:map[]); dvander@532: dvander@532: /** dvander@532: * Returns whether the server is dedicated. dvander@532: * dvander@532: * @return True if dedicated, false otherwise. dvander@532: */ dvander@532: native bool:IsDedicatedServer(); dvander@532: dvander@532: /** dvander@532: * Returns a high-precision time value for profiling the engine. dvander@532: * dvander@532: * @return A floating point time value. dvander@532: */ dvander@532: native Float:GetEngineTime(); dvander@532: dvander@532: /** dvander@532: * Returns the game time based on the game tick. dvander@532: * dvander@532: * @return Game tick time. dvander@532: */ dvander@532: native Float:GetGameTime(); dvander@532: dvander@532: /** dvander@532: * Returns the game description from the mod. dvander@532: * dvander@532: * @param buffer Buffer to store the description. dvander@532: * @param maxlength Maximum size of the buffer. dvander@532: * @param original If true, retrieves the original game description, dvander@532: * ignoring any potential hooks from plugins. dvander@532: * @return Number of bytes written to the buffer (UTF-8 safe). dvander@532: */ dvander@532: native GetGameDescription(String:buffer[], maxlength, bool:original=false); dvander@532: dvander@532: /** dvander@532: * Returns the current map name. dvander@532: * dvander@532: * @param buffer Buffer to store map name. dvander@532: * @param maxlength Maximum length of buffer. dvander@532: * @return Number of bytes written (UTF-8 safe). dvander@532: */ dvander@532: native GetCurrentMap(String:buffer[], maxlength); dvander@530: faluco@656: /** faluco@656: * Precaches a given model. faluco@656: * faluco@656: * @param model Name of the model to precache. faluco@656: * @param preload If preload is true the file will be precached before level startup. faluco@656: * @return Returns the model index, 0 for error. faluco@656: */ faluco@656: native PrecacheModel(const String:model[], bool:preload=false); faluco@656: faluco@656: /** faluco@656: * Precaches a given sentence file. faluco@656: * faluco@656: * @param file Name of the sentence file to precache. faluco@656: * @param preload If preload is true the file will be precached before level startup. faluco@656: * @return Returns a sentence file index. faluco@656: */ faluco@656: native PrecacheSentenceFile(const String:file[], bool:preload=false); faluco@656: faluco@656: /** faluco@656: * Precaches a given decal. faluco@656: * faluco@656: * @param decal Name of the decal to precache. faluco@656: * @param preload If preload is true the file will be precached before level startup. faluco@656: * @return Returns a decal index. faluco@656: */ faluco@656: native PrecacheDecal(const String:decal[], bool:preload=false); faluco@656: faluco@656: /** faluco@656: * Precaches a given generic file. faluco@656: * faluco@656: * @param generic Name of the generic file to precache. faluco@656: * @param preload If preload is true the file will be precached before level startup. faluco@656: * @return Returns a generic file index. faluco@656: */ faluco@656: native PrecacheGeneric(const String:generic[], bool:preload=false); faluco@656: faluco@656: /** faluco@656: * Returns if a given model is precached. faluco@656: * faluco@656: * @param model Name of the model to check. faluco@656: * @return True if precached, false otherwise. faluco@656: */ faluco@656: native bool:IsModelPrecached(const String:model[]); faluco@656: faluco@656: /** faluco@656: * Returns if a given decal is precached. faluco@656: * faluco@656: * @param decal Name of the decal to check. faluco@656: * @return True if precached, false otherwise. faluco@656: */ faluco@656: native bool:IsDecalPrecached(const String:decal[]); faluco@656: faluco@656: /** faluco@656: * Returns if a given generic file is precached. faluco@656: * faluco@656: * @param decal Name of the generic file to check. faluco@656: * @return True if precached, false otherwise. faluco@656: */ faluco@656: native bool:IsGenericPrecached(const String:generic[]); faluco@656: faluco@656: /** faluco@656: * Precaches a given sound. faluco@656: * faluco@656: * @param sound Name of the sound to precache. faluco@656: * @param preload If preload is true the file will be precached before level startup. faluco@656: * @return True if successfully precached, false otherwise. faluco@656: */ faluco@656: native bool:PrecacheSound(const String:sound[], bool:preload=false); faluco@656: faluco@656: /** faluco@656: * Returns if a given sound is precached. faluco@656: * faluco@656: * @param sound Name of the sound to check. faluco@656: * @return True if precached, false otherwise. faluco@656: */ faluco@656: native bool:IsSoundPrecached(const String:sound[]); faluco@656: faluco@659: /** faluco@659: * Executes a client command on the server without being networked. faluco@659: * faluco@659: * @param client Index of the client. faluco@659: * @param fmt Format of the client command. faluco@659: * @param ... Format parameters faluco@659: * @noreturn faluco@659: * @error Invalid client index, or client not connected. faluco@659: */ faluco@659: native FakeClientCommand(client, const String:fmt[], any:...); faluco@659: dvander@460: #include dvander@560: #include