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 function
- Updated removal logic for 'weapon_c4' slot considering 'arg_remammo' parameter
  • Loading branch information
Javekson committed Sep 13, 2023
1 parent 2142208 commit 9ce840e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 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 found and remove, 0 otherwise
*/
native rg_remove_items_by_slot(const index, const InventorySlotType:slot, const bool:removeAmmo = true);

Expand Down
18 changes: 12 additions & 6 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 found and remove, 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 = false;

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,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]) {
if (PARAMS_COUNT < 3 || params[arg_remammo] != 0) {
pPlayer->m_rgAmmo[ pItem->PrimaryAmmoIndex() ] = 0;
}
}

if (pPlayer->RemovePlayerItem(pItem)) {
removed = pPlayer->RemovePlayerItem(pItem) ? true : false;

if (removed) {
pPlayer->pev->weapons &= ~(1 << pItem->m_iId);

// No more weapon
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 9ce840e

Please sign in to comment.