Skip to content

Commit

Permalink
Added a new argument removeAmmo to the rg_remove_items_by_slot native (
Browse files Browse the repository at this point in the history
  • Loading branch information
Javekson authored Sep 5, 2023
1 parent 4637997 commit 4ef1955
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
9 changes: 5 additions & 4 deletions reapi/extra/amxmodx/scripting/include/reapi_gamedll.inc
Original file line number Diff line number Diff line change
Expand Up @@ -496,12 +496,13 @@ native rg_set_weapon_info(const {WeaponIdType,_}:weapon_id, WpnInfo:type, any:..
/*
* Remove all the player's stuff in a specific slot.
*
* @param index Client index
* @param slot The slot that will be emptied
* @param index Client index
* @param slot The slot that will be emptied
* @param removeAmmo Remove ammunition
*
* @return 1 on success, 0 otherwise
* @return 1 on success, 0 otherwise
*/
native rg_remove_items_by_slot(const index, const InventorySlotType:slot);
native rg_remove_items_by_slot(const index, const InventorySlotType:slot, const bool:removeAmmo = true);

/*
* Drop to floor all the player's stuff by specific slot.
Expand Down
19 changes: 12 additions & 7 deletions reapi/src/natives/natives_misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -905,16 +905,17 @@ cell AMX_NATIVE_CALL rg_set_weapon_info(AMX *amx, cell *params)
/*
* Remove all the player's stuff in a specific slot.
*
* @param index Client index
* @param slot The slot that will be emptied
* @param index Client index
* @param slot The slot that will be emptied
* @param removeAmmo Remove ammunition
*
* @return 1 on success, 0 otherwise
* @return 1 on success, 0 otherwise
*
* native rg_remove_items_by_slot(const index, const InventorySlotType:slot);
* native rg_remove_items_by_slot(const index, const InventorySlotType:slot, const bool:removeAmmo = true);
*/
cell AMX_NATIVE_CALL rg_remove_items_by_slot(AMX *amx, cell *params)
{
enum args_e { arg_count, arg_index, arg_slot };
enum args_e { arg_count, arg_index, arg_slot, arg_remammo };

CHECK_ISPLAYER(arg_index);

Expand All @@ -927,14 +928,18 @@ cell AMX_NATIVE_CALL rg_remove_items_by_slot(AMX *amx, cell *params)
}
else
{
pPlayer->ForEachItem(params[arg_slot], [pPlayer](CBasePlayerItem *pItem)
pPlayer->ForEachItem(params[arg_slot], [pPlayer, params](CBasePlayerItem *pItem)
{
if (pItem->IsWeapon()) {
if (pItem == pPlayer->m_pActiveItem) {
((CBasePlayerWeapon *)pItem)->RetireWeapon();
}

pPlayer->m_rgAmmo[ pItem->PrimaryAmmoIndex() ] = 0;
// 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)) {
Expand Down

0 comments on commit 4ef1955

Please sign in to comment.