From 8c8af88cee70e4b88fbf67a79e879ab156ac0688 Mon Sep 17 00:00:00 2001 From: Ruben Gonzalez Date: Tue, 19 Sep 2017 12:37:11 -0400 Subject: [PATCH] Add additional native, fix include file. --- extensions/cstrike/natives.cpp | 17 ++++++++++++++++- plugins/include/cstrike.inc | 22 +++++++++++++++++----- 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/extensions/cstrike/natives.cpp b/extensions/cstrike/natives.cpp index 5d4bbfcb..76cd66ee 100644 --- a/extensions/cstrike/natives.cpp +++ b/extensions/cstrike/natives.cpp @@ -877,6 +877,20 @@ static cell_t CS_ItemDefIndexToID(IPluginContext *pContext, const cell_t *params #endif } +static cell_t CS_WeaponIDToItemDefIndex(IPluginContext *pContext, const cell_t *params) +{ +#if SOURCE_ENGINE == SE_CSGO + WeaponIDMap::Result res = g_mapWeaponIDToDefIdx.find((uint16_t)params[1]); + + if (!res.found()) + return pContext->ThrowNativeError("Invalid weapon id passed."); + + return res->value.m_iDefIdx; +#else + return pContext->ThrowNativeError("CS_WeaponIDToItemDefIndex is not supported on this game"); +#endif +} + sp_nativeinfo_t g_CSNatives[] = { {"CS_RespawnPlayer", CS_RespawnPlayer}, @@ -899,7 +913,8 @@ sp_nativeinfo_t g_CSNatives[] = {"CS_SetClientAssists", CS_SetClientAssists}, {"CS_UpdateClientModel", CS_UpdateClientModel}, {"CS_IsValidWeaponID", CS_IsValidWeaponID}, - {"CS_ItemDefIndexToID", CS_ItemDefIndexToID }, + {"CS_ItemDefIndexToID", CS_ItemDefIndexToID}, + {"CS_WeaponIDToItemDefIndex", CS_WeaponIDToItemDefIndex}, {NULL, NULL} }; diff --git a/plugins/include/cstrike.inc b/plugins/include/cstrike.inc index e7d84152..49e0aec0 100644 --- a/plugins/include/cstrike.inc +++ b/plugins/include/cstrike.inc @@ -141,7 +141,7 @@ enum CSWeaponID CSWeapon_CZ75A = 63, CSWeapon_REVOLVER = 64, CSWeapon_TAGGRENADE = 68, - CSWeapon_MAX_WEAPONS_NO_KNIFES, // Max without the knife item defs, usefull when treating all knives as a regular knife. + CSWeapon_MAX_WEAPONS_NO_KNIFES, // Max without the knife item defs, useful when treating all knives as a regular knife. CSWeapon_BAYONET = 500, CSWeapon_KNIFE_FLIP = 505, CSWeapon_KNIFE_GUT = 506, @@ -380,7 +380,7 @@ native int CS_WeaponIDToAlias(CSWeaponID weaponID, char[] destination, int len); * @param weaponID WeaponID to check * @return Returns true if its a valid WeaponID false otherwise. * - * @note This will return false always for CSWeapon_NONE + * @note This will return false always for CSWeapon_NONE. Should only be called after OnMapStart since weapon info isnt intialized before. */ native bool CS_IsValidWeaponID(CSWeaponID id); @@ -395,13 +395,24 @@ 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. + * @param iDefIndex 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. + * @note In most cases the id will be the item definition index. Works for CS:GO ONLY. */ -native CSWeaponID CS_ItemDefIndexToID(int ItemDefinitionIndex); +native CSWeaponID CS_ItemDefIndexToID(int iDefIndex); + +/** + * Returns a item definition index equivalent based on the CSWeaponID. + * + * @param id CSWeaponID to get the item definition for. + * @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. + */ +native int CS_WeaponIDToItemDefIndex(CSWeaponID id); /** * Do not edit below this line! @@ -442,5 +453,6 @@ public void __ext_cstrike_SetNTVOptional() MarkNativeAsOptional("CS_IsValidWeaponID"); MarkNativeAsOptional("CS_UpdateClientModel"); MarkNativeAsOptional("CS_ItemDefIndexToID"); + MarkNativeAsOptional("CS_WeaponIDToItemDefIndex"); } #endif