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' argument
  • Loading branch information
Javekson committed Sep 17, 2023
1 parent 2142208 commit b413cd3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 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
16 changes: 11 additions & 5 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 removed = 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
removed = 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,7 +941,7 @@ 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]) {
if (PARAMS_COUNT < 3 || params[arg_remammo] != 0) {
pPlayer->m_rgAmmo[ pItem->PrimaryAmmoIndex() ] = 0;
}
}
Expand All @@ -951,6 +955,8 @@ cell AMX_NATIVE_CALL rg_remove_items_by_slot(AMX *amx, cell *params)
}

pItem->Kill();
} else {
removed = false;
}

return false;
Expand All @@ -961,7 +967,7 @@ cell AMX_NATIVE_CALL rg_remove_items_by_slot(AMX *amx, cell *params)
}
}

return TRUE;
return removed ? TRUE : FALSE;
}

/*
Expand Down

0 comments on commit b413cd3

Please sign in to comment.