diff --git a/core/smn_core.cpp b/core/smn_core.cpp index b55042ed..cd8de231 100644 --- a/core/smn_core.cpp +++ b/core/smn_core.cpp @@ -585,6 +585,18 @@ static cell_t GetExtensionFileStatus(IPluginContext *pContext, const cell_t *par return 1; } +static cell_t FindPluginByNumber(IPluginContext *pContext, const cell_t *params) +{ + CPlugin *pPlugin = g_PluginSys.GetPluginByOrder(params[1]); + + if (pPlugin == NULL) + { + return BAD_HANDLE; + } + + return pPlugin->GetMyHandle(); +} + REGISTER_NATIVES(coreNatives) { {"AutoExecConfig", AutoExecConfig}, @@ -607,6 +619,7 @@ REGISTER_NATIVES(coreNatives) {"LogToFile", LogToFile}, {"LogToFileEx", LogToFileEx}, {"GetExtensionFileStatus", GetExtensionFileStatus}, + {"FindPluginByNumber", FindPluginByNumber}, {NULL, NULL}, }; diff --git a/plugins/include/sourcemod.inc b/plugins/include/sourcemod.inc index 842c5740..aab0d7ab 100644 --- a/plugins/include/sourcemod.inc +++ b/plugins/include/sourcemod.inc @@ -266,6 +266,18 @@ native bool:IsPluginDebugging(Handle:hndl); */ native bool:GetPluginInfo(Handle:plugin, PluginInfo:info, String:buffer[], maxlength); +/** + * Finds a plugin by its order in the list from the "plugins list" server + * "sm" command. You should not use this function to loop through all plugins, + * use the iterator instead. Looping through all plugins using this native + * is O(n^2), whereas using the iterator is O(n). + * + * @param order_num Number of the plugin as it appears in "sm plugins list". + * @return Plugin Handle on success, INVALID_HANDLE if no plugin + * matches the given number. + */ +native Handle:FindPluginByNumber(order_num); + /** * Causes the plugin to enter a failed state. An error will be thrown and * the plugin will be paused until it is unloaded or reloaded.