From 9a95fd988632f004af801772712a660f5a929fcf Mon Sep 17 00:00:00 2001 From: HamletEagle Date: Fri, 7 Sep 2018 00:01:47 -0700 Subject: [PATCH] Add cs_get_weaponbox_item native (#548) * Add cs_get_wpnbox_weapon native * Rename native + fix strcmp check --- modules/cstrike/cstrike/CstrikeNatives.cpp | 29 ++++++++++++++++++++++ plugins/include/cstrike.inc | 11 ++++++++ 2 files changed, 40 insertions(+) diff --git a/modules/cstrike/cstrike/CstrikeNatives.cpp b/modules/cstrike/cstrike/CstrikeNatives.cpp index fb973847..4931993e 100644 --- a/modules/cstrike/cstrike/CstrikeNatives.cpp +++ b/modules/cstrike/cstrike/CstrikeNatives.cpp @@ -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(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}, @@ -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} }; diff --git a/plugins/include/cstrike.inc b/plugins/include/cstrike.inc index 1587ebb7..bb366f4c 100755 --- a/plugins/include/cstrike.inc +++ b/plugins/include/cstrike.inc @@ -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. *