diff --git a/extensions/cstrike/natives.cpp b/extensions/cstrike/natives.cpp index bc5e5e51..5d4bbfcb 100644 --- a/extensions/cstrike/natives.cpp +++ b/extensions/cstrike/natives.cpp @@ -862,6 +862,21 @@ static cell_t CS_UpdateClientModel(IPluginContext *pContext, const cell_t *param return 1; } + +static cell_t CS_ItemDefIndexToID(IPluginContext *pContext, const cell_t *params) +{ +#if SOURCE_ENGINE == SE_CSGO + ItemIndexMap::Result res = g_mapDefIdxToClass.find((uint16_t)params[1]); + + if (!res.found()) + return pContext->ThrowNativeError("Invalid item definition passed."); + + return res->value.m_iWeaponID; +#else + return pContext->ThrowNativeError("CS_ItemDefIndexToID is not supported on this game"); +#endif +} + sp_nativeinfo_t g_CSNatives[] = { {"CS_RespawnPlayer", CS_RespawnPlayer}, @@ -884,6 +899,7 @@ sp_nativeinfo_t g_CSNatives[] = {"CS_SetClientAssists", CS_SetClientAssists}, {"CS_UpdateClientModel", CS_UpdateClientModel}, {"CS_IsValidWeaponID", CS_IsValidWeaponID}, + {"CS_ItemDefIndexToID", CS_ItemDefIndexToID }, {NULL, NULL} }; diff --git a/plugins/include/cstrike.inc b/plugins/include/cstrike.inc index f2b40dad..a80103b5 100644 --- a/plugins/include/cstrike.inc +++ b/plugins/include/cstrike.inc @@ -391,6 +391,17 @@ native bool CS_IsValidWeaponID(CSWeaponID id); */ native void CS_UpdateClientModel(int client); +/** + * Returns a CSWeaponID equivalent based on the item definition index. + * + * @param ItemDefinitionIndex Definition index to get the CSWeaponID value for. + * @return Returns CSWeaponID value for the definition index. + * + * @error Invalid definition index. + * @note In most cases the id will be the item definition index. + */ +native CSWeaponID CS_ItemDefIndexToID(int ItemDefinitionIndex); + /** * Do not edit below this line! */ @@ -429,5 +440,6 @@ public void __ext_cstrike_SetNTVOptional() MarkNativeAsOptional("CS_WeaponIDToAlias"); MarkNativeAsOptional("CS_IsValidWeaponID"); MarkNativeAsOptional("CS_UpdateClientModel"); + MarkNativeAsOptional("CS_ItemDefIndexToID"); } #endif