From a160b78aa5e3396ce8a70442dc2f199f1a2cdb49 Mon Sep 17 00:00:00 2001 From: Javekson Date: Sat, 9 Sep 2023 19:54:58 +0400 Subject: [PATCH] Updated return logic in rg_remove_items_by_slot - Updated return logic in rg_remove_items_by_slot - Updated removal logic for 'weapon_c4' slot considering 'arg_remammo' parameter --- .../scripting/include/reapi_gamedll.inc | 2 +- reapi/src/natives/natives_misc.cpp | 22 +++++++++++++------ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/reapi/extra/amxmodx/scripting/include/reapi_gamedll.inc b/reapi/extra/amxmodx/scripting/include/reapi_gamedll.inc index 3ea2a44c..d3f6a11a 100644 --- a/reapi/extra/amxmodx/scripting/include/reapi_gamedll.inc +++ b/reapi/extra/amxmodx/scripting/include/reapi_gamedll.inc @@ -500,7 +500,7 @@ 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 if all items were found and removed, 0 otherwise */ 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 8d1bcb6e..2694bd0f 100644 --- a/reapi/src/natives/natives_misc.cpp +++ b/reapi/src/natives/natives_misc.cpp @@ -909,7 +909,7 @@ 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 if all items were found and removed, 0 otherwise * * native rg_remove_items_by_slot(const index, const InventorySlotType:slot, const bool:removeAmmo = true); */ @@ -922,13 +922,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); + bool slotCleaned = true; + if (params[arg_slot] == C4_SLOT) { - pPlayer->CSPlayer()->RemovePlayerItemEx("weapon_c4", true); + // Compatible with older versions of the plugin, + // which still only pass two parameters + slotCleaned = pPlayer->CSPlayer()->RemovePlayerItemEx("weapon_c4", (PARAMS_COUNT < 3 || params[arg_remammo] != 0)); } else { - pPlayer->ForEachItem(params[arg_slot], [pPlayer, params](CBasePlayerItem *pItem) + pPlayer->ForEachItem(params[arg_slot], [&](CBasePlayerItem *pItem) { if (pItem->IsWeapon()) { if (pItem == pPlayer->m_pActiveItem) { @@ -937,12 +941,14 @@ cell AMX_NATIVE_CALL rg_remove_items_by_slot(AMX *amx, cell *params) // 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 (PARAMS_COUNT < 3 || params[arg_remammo] != 0) { + pPlayer->m_rgAmmo[pItem->PrimaryAmmoIndex()] = 0; } } - if (pPlayer->RemovePlayerItem(pItem)) { + bool removedItem = pPlayer->RemovePlayerItem(pItem) ? true : false; + + if (removedItem) { pPlayer->pev->weapons &= ~(1 << pItem->m_iId); // No more weapon @@ -953,6 +959,8 @@ cell AMX_NATIVE_CALL rg_remove_items_by_slot(AMX *amx, cell *params) pItem->Kill(); } + slotCleaned &= removedItem; + return false; }); @@ -961,7 +969,7 @@ cell AMX_NATIVE_CALL rg_remove_items_by_slot(AMX *amx, cell *params) } } - return TRUE; + return slotCleaned ? TRUE : FALSE; } /*