diff --git a/modules/cstrike/cstrike/CstrikeNatives.cpp b/modules/cstrike/cstrike/CstrikeNatives.cpp index 143ec92d..92594e56 100644 --- a/modules/cstrike/cstrike/CstrikeNatives.cpp +++ b/modules/cstrike/cstrike/CstrikeNatives.cpp @@ -1903,6 +1903,41 @@ static cell AMX_NATIVE_CALL cs_get_weapon_info(AMX* amx, cell* params) return 0; } +// native cs_get_user_weapon_entity(playerIndex); +static cell AMX_NATIVE_CALL cs_get_user_weapon_entity(AMX *amx, cell *params) +{ + GET_OFFSET("CBasePlayer", m_pActiveItem); + + int playerIndex = params[1]; + + CHECK_PLAYER(playerIndex); + edict_t *pPlayer = MF_GetPlayerEdict(playerIndex); + + int weaponEntIndex = TypeConversion.cbase_to_id(get_pdata(pPlayer, m_pActiveItem)); + + return (weaponEntIndex != -1) ? weaponEntIndex : 0; +} + +// native cs_get_user_weapon(playerIndex); +static cell AMX_NATIVE_CALL cs_get_user_weapon(AMX *amx, cell *params) +{ + GET_OFFSET("CBasePlayer", m_pActiveItem); + GET_OFFSET("CBasePlayerItem", m_iId); + + int playerIndex = params[1]; + + CHECK_PLAYER(playerIndex); + edict_t *pPlayer = MF_GetPlayerEdict(playerIndex); + + edict_t *pWeapon = TypeConversion.cbase_to_edict(get_pdata(pPlayer, m_pActiveItem)); + + if (!FNullEnt(pWeapon)) + { + return get_pdata(pWeapon, m_iId); + } + + return 0; +} AMX_NATIVE_INFO CstrikeNatives[] = { @@ -1972,5 +2007,7 @@ AMX_NATIVE_INFO CstrikeNatives[] = {"cs_get_item_id", cs_get_item_id}, {"cs_get_translated_item_alias",cs_get_translated_item_alias}, {"cs_get_weapon_info", cs_get_weapon_info}, + {"cs_get_user_weapon_entity", cs_get_user_weapon_entity}, + {"cs_get_user_weapon", cs_get_user_weapon}, {nullptr, nullptr} }; diff --git a/plugins/include/cstrike.inc b/plugins/include/cstrike.inc index 70e3ade5..73e58628 100755 --- a/plugins/include/cstrike.inc +++ b/plugins/include/cstrike.inc @@ -1085,6 +1085,32 @@ native bool:cs_get_translated_item_alias(const alias[], itemname[], maxlength); */ native any:cs_get_weapon_info(weapon_id, CsWeaponInfo:type); +/** + * Returns active weapon entity. + * + * @param playerIndex Player index + * + * @return Weapon entity index on success or 0 if there is no active weapon + * @error If the client index is not within the range of 1 to + * maxClients, or the client is not connected, an error will be + * thrown. + */ +native cs_get_user_weapon_entity(playerIndex); + +/** + * Returns weapon index of the active weapon. + * + * @note More reliable than get_user_weapon. + * + * @param playerIndex Player index + * + * @return Weapon index on success or 0 if there is no active weapon + * @error If the client index is not within the range of 1 to + * maxClients, or the client is not connected, an error will be + * thrown. + */ +native cs_get_user_weapon(playerIndex); + /** * Returns a weapon class id associated with a weapon id. *