mirror of
https://github.com/YGGverse/hlsdk-portable.git
synced 2025-02-03 10:35:42 +00:00
Give player exhaustible weapons when taking ammo for them from weaponbox
This commit is contained in:
parent
92aa5456cf
commit
5aa11a38b3
@ -1265,6 +1265,18 @@ void CWeaponBox::Kill( void )
|
|||||||
UTIL_Remove( this );
|
UTIL_Remove( this );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const char* IsAmmoForExhaustibleWeapon(const char* ammoName, int& weaponId)
|
||||||
|
{
|
||||||
|
for (int i=0; i<MAX_WEAPONS; ++i) {
|
||||||
|
ItemInfo& II = CBasePlayerItem::ItemInfoArray[i];
|
||||||
|
if ((II.iFlags & ITEM_FLAG_EXHAUSTIBLE) && II.pszAmmo1 && FStrEq(ammoName, II.pszAmmo1)) {
|
||||||
|
weaponId = II.iId;
|
||||||
|
return II.pszName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
//=========================================================
|
//=========================================================
|
||||||
// CWeaponBox - Touch: try to add my contents to the toucher
|
// CWeaponBox - Touch: try to add my contents to the toucher
|
||||||
// if the toucher is a player.
|
// if the toucher is a player.
|
||||||
@ -1296,6 +1308,35 @@ void CWeaponBox::Touch( CBaseEntity *pOther )
|
|||||||
{
|
{
|
||||||
if( !FStringNull( m_rgiszAmmo[i] ) )
|
if( !FStringNull( m_rgiszAmmo[i] ) )
|
||||||
{
|
{
|
||||||
|
// horrific HACK to give player an exhaustible weapon as a real weapon, not just ammo
|
||||||
|
int exhaustibleWeaponId;
|
||||||
|
const char* weaponName = IsAmmoForExhaustibleWeapon(STRING(m_rgiszAmmo[i]), exhaustibleWeaponId);
|
||||||
|
if (weaponName) {
|
||||||
|
bool foundWeapon = false;
|
||||||
|
for( int j = 0; j < MAX_ITEM_TYPES && !foundWeapon; j++ )
|
||||||
|
{
|
||||||
|
CBasePlayerItem *pPlayerItem = pPlayer->m_rgpPlayerItems[j];
|
||||||
|
while( pPlayerItem )
|
||||||
|
{
|
||||||
|
if (pPlayerItem->m_iId == exhaustibleWeaponId) {
|
||||||
|
foundWeapon = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
pPlayerItem = pPlayerItem->m_pNext;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!foundWeapon) {
|
||||||
|
CBasePlayerWeapon* weapon = (CBasePlayerWeapon*)Create(weaponName, pev->origin, pev->angles);
|
||||||
|
if (weapon) {
|
||||||
|
weapon->pev->spawnflags |= SF_NORESPAWN;
|
||||||
|
weapon->m_iDefaultAmmo = 0;
|
||||||
|
if (pPlayer->AddPlayerItem(weapon)) {
|
||||||
|
weapon->AttachToPlayer(pPlayer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// there's some ammo of this type.
|
// there's some ammo of this type.
|
||||||
pPlayer->GiveAmmo( m_rgAmmo[i], STRING( m_rgiszAmmo[i] ), MaxAmmoCarry( m_rgiszAmmo[i] ) );
|
pPlayer->GiveAmmo( m_rgAmmo[i], STRING( m_rgiszAmmo[i] ), MaxAmmoCarry( m_rgiszAmmo[i] ) );
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user