Skip to content

Commit

Permalink
Updated return logic in rg_remove_items_by_slot
Browse files Browse the repository at this point in the history
- Updated return logic in rg_remove_items_by_slot
- Updated removal logic for 'weapon_c4' slot considering 'arg_remammo' parameter
  • Loading branch information
Javekson committed Sep 14, 2023
1 parent 2142208 commit a160b78
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion reapi/extra/amxmodx/scripting/include/reapi_gamedll.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
22 changes: 15 additions & 7 deletions reapi/src/natives/natives_misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
*/
Expand All @@ -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) {
Expand All @@ -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
Expand All @@ -953,6 +959,8 @@ cell AMX_NATIVE_CALL rg_remove_items_by_slot(AMX *amx, cell *params)
pItem->Kill();
}

slotCleaned &= removedItem;

return false;
});

Expand All @@ -961,7 +969,7 @@ cell AMX_NATIVE_CALL rg_remove_items_by_slot(AMX *amx, cell *params)
}
}

return TRUE;
return slotCleaned ? TRUE : FALSE;
}

/*
Expand Down

0 comments on commit a160b78

Please sign in to comment.