diff --git a/reapi/extra/amxmodx/scripting/include/reapi_gamedll.inc b/reapi/extra/amxmodx/scripting/include/reapi_gamedll.inc index 3ea2a44..bb3c706 100644 --- a/reapi/extra/amxmodx/scripting/include/reapi_gamedll.inc +++ b/reapi/extra/amxmodx/scripting/include/reapi_gamedll.inc @@ -500,7 +500,8 @@ native rg_set_weapon_info(const {WeaponIdType,_}:weapon_id, WpnInfo:type, any:.. * @param slot The slot that will be emptied * @param removeAmmo Remove ammunition * -* @return 1 on success, 0 otherwise +* @return 1 - successful removal of all items in the slot or the slot is empty +* 0 - if at least one item failed to remove */ native rg_remove_items_by_slot(const index, const InventorySlotType:slot, const bool:removeAmmo = true); diff --git a/reapi/src/natives/natives_misc.cpp b/reapi/src/natives/natives_misc.cpp index 8d1bcb6..ccae232 100644 --- a/reapi/src/natives/natives_misc.cpp +++ b/reapi/src/natives/natives_misc.cpp @@ -909,7 +909,8 @@ cell AMX_NATIVE_CALL rg_set_weapon_info(AMX *amx, cell *params) * @param slot The slot that will be emptied * @param removeAmmo Remove ammunition * -* @return 1 on success, 0 otherwise +* @return 1 - successful removal of all items in the slot or the slot is empty +* 0 - if at least one item failed to remove * * native rg_remove_items_by_slot(const index, const InventorySlotType:slot, const bool:removeAmmo = true); */ @@ -922,46 +923,17 @@ cell AMX_NATIVE_CALL rg_remove_items_by_slot(AMX *amx, cell *params) CBasePlayer *pPlayer = UTIL_PlayerByIndex(params[arg_index]); CHECK_CONNECTED(pPlayer, arg_index); - if (params[arg_slot] == C4_SLOT) + bool success = true; + + pPlayer->ForEachItem(params[arg_slot], [&](CBasePlayerItem *pItem) { - pPlayer->CSPlayer()->RemovePlayerItemEx("weapon_c4", true); - } - else - { - pPlayer->ForEachItem(params[arg_slot], [pPlayer, params](CBasePlayerItem *pItem) - { - if (pItem->IsWeapon()) { - if (pItem == pPlayer->m_pActiveItem) { - ((CBasePlayerWeapon *)pItem)->RetireWeapon(); - } + // Compatible with older versions of the plugin, + // which still only pass two parameters + success &= pPlayer->CSPlayer()->RemovePlayerItemEx(STRING(pItem->pev->classname), (PARAMS_COUNT < 3 || params[arg_remammo] != 0)) ? true : false; + return false; + }); - // Compatible with older versions of the plugin, - // which still only pass two parameters - if (PARAMS_COUNT < 3 || params[arg_remammo]) { - pPlayer->m_rgAmmo[ pItem->PrimaryAmmoIndex() ] = 0; - } - } - - if (pPlayer->RemovePlayerItem(pItem)) { - pPlayer->pev->weapons &= ~(1 << pItem->m_iId); - - // No more weapon - if ((pPlayer->pev->weapons & ~(1 << WEAPON_SUIT)) == 0) { - pPlayer->m_iHideHUD |= HIDEHUD_WEAPONS; - } - - pItem->Kill(); - } - - return false; - }); - - if (!pPlayer->m_rgpPlayerItems[PRIMARY_WEAPON_SLOT]) { - pPlayer->m_bHasPrimary = false; - } - } - - return TRUE; + return success ? TRUE : FALSE; } /*