diff --git a/extensions/cstrike/natives.cpp b/extensions/cstrike/natives.cpp index c4c578ef..a3fedb96 100644 --- a/extensions/cstrike/natives.cpp +++ b/extensions/cstrike/natives.cpp @@ -954,6 +954,21 @@ static cell_t CS_WeaponIDToItemDefIndex(IPluginContext *pContext, const cell_t * #endif } +static cell_t CS_WeaponIDToLoadoutSlot(IPluginContext *pContext, const cell_t *params) +{ +#if SOURCE_ENGINE == SE_CSGO + WeaponIDMap::Result res = g_mapWeaponIDToDefIdx.find((SMCSWeapon)params[1]); + + if (!res.found()) + return pContext->ThrowNativeError("Invalid weapon id passed."); + + return res->value.m_iLoadoutSlot; +#else + return pContext->ThrowNativeError("CS_WeaponIDToLoadoutSlot is not supported on this game"); +#endif +} + + sp_nativeinfo_t g_CSNatives[] = { {"CS_RespawnPlayer", CS_RespawnPlayer}, @@ -978,6 +993,7 @@ sp_nativeinfo_t g_CSNatives[] = {"CS_IsValidWeaponID", CS_IsValidWeaponID}, {"CS_ItemDefIndexToID", CS_ItemDefIndexToID}, {"CS_WeaponIDToItemDefIndex", CS_WeaponIDToItemDefIndex}, + {"CS_WeaponIDToLoadoutSlot", CS_WeaponIDToLoadoutSlot}, {NULL, NULL} }; diff --git a/plugins/include/cstrike.inc b/plugins/include/cstrike.inc index e8b34b41..c7cb45eb 100644 --- a/plugins/include/cstrike.inc +++ b/plugins/include/cstrike.inc @@ -440,10 +440,19 @@ native CSWeaponID CS_ItemDefIndexToID(int iDefIndex); * @return Returns item definition index value for the weapon id. * @error Invalid weapon id. * - * @note In most cases the item deinition index will be the id. Works for CS:GO ONLY. + * @note In most cases the item definition index will be the id. Works for CS:GO ONLY. */ native int CS_WeaponIDToItemDefIndex(CSWeaponID id); +/** + * Returns the loadout slot based on the CSWeaponID. (CS:GO only) + * + * @param id CSWeaponID to get the loadout slot for. + * @return Returns loadout slot value for the weapon id. + * @error Invalid weapon id. + */ +native int CS_WeaponIDToLoadoutSlot(CSWeaponID id); + /** * Do not edit below this line! */ @@ -484,5 +493,6 @@ public void __ext_cstrike_SetNTVOptional() MarkNativeAsOptional("CS_UpdateClientModel"); MarkNativeAsOptional("CS_ItemDefIndexToID"); MarkNativeAsOptional("CS_WeaponIDToItemDefIndex"); + MarkNativeAsOptional("CS_WeaponIDToLoadoutSlot"); } #endif