From 4ef19557c96a8262c4798587b7dcdf2d12eee462 Mon Sep 17 00:00:00 2001 From: Javekson <132286351+Javekson@users.noreply.github.com> Date: Tue, 5 Sep 2023 18:11:49 +0400 Subject: [PATCH] Added a new argument removeAmmo to the rg_remove_items_by_slot native (#283) --- .../scripting/include/reapi_gamedll.inc | 9 +++++---- reapi/src/natives/natives_misc.cpp | 19 ++++++++++++------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/reapi/extra/amxmodx/scripting/include/reapi_gamedll.inc b/reapi/extra/amxmodx/scripting/include/reapi_gamedll.inc index f454e98..3ea2a44 100644 --- a/reapi/extra/amxmodx/scripting/include/reapi_gamedll.inc +++ b/reapi/extra/amxmodx/scripting/include/reapi_gamedll.inc @@ -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. diff --git a/reapi/src/natives/natives_misc.cpp b/reapi/src/natives/natives_misc.cpp index a917084..8d1bcb6 100644 --- a/reapi/src/natives/natives_misc.cpp +++ b/reapi/src/natives/natives_misc.cpp @@ -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); @@ -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)) {