Browse Source

Merge pull request #26 from FreeSlave/weaponbox_exhaustible_weapons

Give player exhaustible weapons when taking ammo for them from weaponbox
pull/1/head
Alibek Omarov 7 years ago committed by GitHub
parent
commit
163d8bad04
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 41
      dlls/weapons.cpp

41
dlls/weapons.cpp

@ -1265,6 +1265,18 @@ void CWeaponBox::Kill( void ) @@ -1265,6 +1265,18 @@ void CWeaponBox::Kill( void )
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
// if the toucher is a player.
@ -1296,6 +1308,35 @@ void CWeaponBox::Touch( CBaseEntity *pOther ) @@ -1296,6 +1308,35 @@ void CWeaponBox::Touch( CBaseEntity *pOther )
{
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.
pPlayer->GiveAmmo( m_rgAmmo[i], STRING( m_rgiszAmmo[i] ), MaxAmmoCarry( m_rgiszAmmo[i] ) );

Loading…
Cancel
Save