mirror of
https://github.com/rehlds/reapi.git
synced 2024-12-28 07:35:31 +03:00
Refactored rg_remove_items_by_slot and updated the return logic (#288)
This commit is contained in:
parent
fcca39b87b
commit
2077022a43
@ -500,7 +500,8 @@ 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 - successful removal of all items in the slot or the slot is empty
|
||||
* 0 - if at least one item failed to remove
|
||||
*/
|
||||
native rg_remove_items_by_slot(const index, const InventorySlotType:slot, const bool:removeAmmo = true);
|
||||
|
||||
|
@ -909,7 +909,8 @@ 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 - successful removal of all items in the slot or the slot is empty
|
||||
* 0 - if at least one item failed to remove
|
||||
*
|
||||
* native rg_remove_items_by_slot(const index, const InventorySlotType:slot, const bool:removeAmmo = true);
|
||||
*/
|
||||
@ -922,46 +923,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);
|
||||
|
||||
if (params[arg_slot] == C4_SLOT)
|
||||
bool success = true;
|
||||
|
||||
pPlayer->ForEachItem(params[arg_slot], [&](CBasePlayerItem *pItem)
|
||||
{
|
||||
pPlayer->CSPlayer()->RemovePlayerItemEx("weapon_c4", true);
|
||||
}
|
||||
else
|
||||
{
|
||||
pPlayer->ForEachItem(params[arg_slot], [pPlayer, params](CBasePlayerItem *pItem)
|
||||
{
|
||||
if (pItem->IsWeapon()) {
|
||||
if (pItem == pPlayer->m_pActiveItem) {
|
||||
((CBasePlayerWeapon *)pItem)->RetireWeapon();
|
||||
}
|
||||
// Compatible with older versions of the plugin,
|
||||
// which still only pass two parameters
|
||||
success &= pPlayer->CSPlayer()->RemovePlayerItemEx(STRING(pItem->pev->classname), (PARAMS_COUNT < 3 || params[arg_remammo] != 0)) ? true : false;
|
||||
return false;
|
||||
});
|
||||
|
||||
// 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)) {
|
||||
pPlayer->pev->weapons &= ~(1 << pItem->m_iId);
|
||||
|
||||
// No more weapon
|
||||
if ((pPlayer->pev->weapons & ~(1 << WEAPON_SUIT)) == 0) {
|
||||
pPlayer->m_iHideHUD |= HIDEHUD_WEAPONS;
|
||||
}
|
||||
|
||||
pItem->Kill();
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
if (!pPlayer->m_rgpPlayerItems[PRIMARY_WEAPON_SLOT]) {
|
||||
pPlayer->m_bHasPrimary = false;
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
return success ? TRUE : FALSE;
|
||||
}
|
||||
|
||||
/*
|
||||
|
Loading…
Reference in New Issue
Block a user