Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated the return logic of rg_drop_item and rg_drop_items_by_slot #289

Merged
merged 3 commits into from
Oct 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions reapi/extra/amxmodx/scripting/include/reapi_gamedll.inc
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,8 @@ native rg_remove_items_by_slot(const index, const InventorySlotType:slot, const
* @param index Client index
* @param slot Specific slot for remove of each item.
*
* @return 1 on success, 0 otherwise
* @return 1 - successful drop of all items in the slot or the slot is empty
* 0 - if at least one item failed to drop
*/
native rg_drop_items_by_slot(const index, const InventorySlotType:slot);

Expand All @@ -528,9 +529,9 @@ native rg_remove_all_items(const index, const bool:removeSuit = false);
* Forces the player to drop the specified item classname.
*
* @param index Client index
* @param item_name Item classname
* @param item_name Item classname, if no name, the active item classname
*
* @return 1 on success, 0 otherwise
* @return Entity index of weaponbox, AMX_NULLENT (-1) otherwise
*
*/
native rg_drop_item(const index, const item_name[]);
Expand Down
4 changes: 2 additions & 2 deletions reapi/include/cssdk/dlls/API/CSPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ class CCSPlayer: public CCSMonster
virtual CBaseEntity *GiveNamedItemEx(const char *pszName) = 0;
virtual void GiveDefaultItems() = 0;
virtual void GiveShield(bool bDeploy = true) = 0;
virtual void DropShield(bool bDeploy = true) = 0;
virtual void DropPlayerItem(const char *pszItemName) = 0;
virtual CBaseEntity *DropShield(bool bDeploy = true) = 0;
virtual CBaseEntity *DropPlayerItem(const char *pszItemName) = 0;
virtual bool RemoveShield() = 0;
virtual void RemoveAllItems(bool bRemoveSuit) = 0;
virtual bool RemovePlayerItem(const char* pszItemName) = 0;
Expand Down
23 changes: 15 additions & 8 deletions reapi/src/natives/natives_misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -970,7 +970,8 @@ cell AMX_NATIVE_CALL rg_remove_items_by_slot(AMX *amx, cell *params)
* @param index Client index
* @param slot Specific slot for remove of each item.
*
* @return 1 on success, 0 otherwise
* @return 1 - successful drop of all items in the slot or the slot is empty
* 0 - if at least one item failed to drop
*
* native rg_drop_items_by_slot(const index, const InventorySlotType:slot);
*/
Expand All @@ -983,12 +984,14 @@ cell AMX_NATIVE_CALL rg_drop_items_by_slot(AMX *amx, cell *params)
CBasePlayer *pPlayer = UTIL_PlayerByIndex(params[arg_index]);
CHECK_CONNECTED(pPlayer, arg_index);

pPlayer->ForEachItem(params[arg_slot], [pPlayer](CBasePlayerItem *pItem) {
pPlayer->CSPlayer()->DropPlayerItem(STRING(pItem->pev->classname));
bool success = true;

pPlayer->ForEachItem(params[arg_slot], [&](CBasePlayerItem *pItem) {
success &= pPlayer->CSPlayer()->DropPlayerItem(STRING(pItem->pev->classname)) ? true : false;
return false;
});

return TRUE;
return success ? TRUE : FALSE;
}

/*
Expand Down Expand Up @@ -1018,9 +1021,9 @@ cell AMX_NATIVE_CALL rg_remove_all_items(AMX *amx, cell *params)
* Forces the player to drop the specified item classname.
*
* @param index Client index
* @param item_name Item classname
* @param item_name Item classname, if no name, the active item classname
*
* @return 1 on success, 0 otherwise
* @return Entity index of weaponbox, AMX_NULLENT (-1) otherwise
*
* native rg_drop_item(const index, const item_name[]);
*/
Expand All @@ -1034,8 +1037,12 @@ cell AMX_NATIVE_CALL rg_drop_item(AMX *amx, cell *params)
CHECK_CONNECTED(pPlayer, arg_index);

char item[256];
pPlayer->CSPlayer()->DropPlayerItem(getAmxString(amx, params[arg_item_name], item));
return TRUE;
auto pEntity = pPlayer->CSPlayer()->DropPlayerItem(getAmxString(amx, params[arg_item_name], item));

if (pEntity)
return indexOfPDataAmx(pEntity);

return AMX_NULLENT;
}

/*
Expand Down