Skip to content

Commit

Permalink
Add cs_get_weaponbox_item native (#548)
Browse files Browse the repository at this point in the history
* Add cs_get_wpnbox_weapon native

* Rename native + fix strcmp check
  • Loading branch information
HamletEagle authored and Arkshine committed Sep 7, 2018
1 parent 99ebd62 commit 9a95fd9
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
29 changes: 29 additions & 0 deletions modules/cstrike/cstrike/CstrikeNatives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1998,6 +1998,34 @@ static cell AMX_NATIVE_CALL cs_get_user_weapon(AMX *amx, cell *params)
return 0;
}

// native cs_get_weaponbox_item(weaponboxIndex);
static cell AMX_NATIVE_CALL cs_get_weaponbox_item(AMX *amx, cell *params)
{
GET_OFFSET("CWeaponBox", m_rgpPlayerItems);

int weaponboxIndex = params[1];
CHECK_NONPLAYER(weaponboxIndex);
edict_t *pWeaponBox = TypeConversion.id_to_edict(weaponboxIndex);

if (strcmp(STRING(pWeaponBox->v.classname), "weaponbox") != 0)
{
MF_LogError(amx, AMX_ERR_NATIVE, "Not a weaponbox entity! (%d)", weaponboxIndex);
return 0;
}

edict_t *pWeapon;
for (int i = 1; i < MAX_ITEM_TYPES; i++)
{
pWeapon = TypeConversion.cbase_to_edict(get_pdata<void *>(pWeaponBox, m_rgpPlayerItems, i));
if (!FNullEnt(pWeapon))
{
return TypeConversion.edict_to_id(pWeapon);
}
}

return 0;
}

AMX_NATIVE_INFO CstrikeNatives[] =
{
{"cs_set_user_money", cs_set_user_money},
Expand Down Expand Up @@ -2070,5 +2098,6 @@ AMX_NATIVE_INFO CstrikeNatives[] =
{"cs_get_weapon_info", cs_get_weapon_info},
{"cs_get_user_weapon_entity", cs_get_user_weapon_entity},
{"cs_get_user_weapon", cs_get_user_weapon},
{"cs_get_weaponbox_item", cs_get_weaponbox_item},
{nullptr, nullptr}
};
11 changes: 11 additions & 0 deletions plugins/include/cstrike.inc
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,17 @@ native cs_get_armoury_type(index, &count = 1);
*/
native cs_set_armoury_type(index, type, count = -1);

/**
* Returns the weapon entity index that was packed into a weaponbox.
*
* @param weaponboxIndex Weaponbox entity index
*
* @return Weapon entity index on success or 0 if no weapon can be found
* @error If a non-weaponbox entity is provided or the entity is invalid, an error will be
* thrown.
*/
native cs_get_weaponbox_item(weaponboxIndex);

/**
* Returns the map zones the client is inside of as a bitflag value.
*
Expand Down

0 comments on commit 9a95fd9

Please sign in to comment.