Ejemplo n.º 1
0
//-----------------------------------------------------------------------------
// Purpose: MyTouch function for the ammopack
//-----------------------------------------------------------------------------
bool CAmmoPack::MyTouch( CBasePlayer *pPlayer )
{
	bool bSuccess = false;

	if ( ValidTouch( pPlayer ) )
	{
		CTFPlayer *pTFPlayer = ToTFPlayer( pPlayer );
		if ( !pTFPlayer )
			return false;

		int iMaxPrimary = pTFPlayer->GetMaxAmmo( TF_AMMO_PRIMARY );
		if ( pPlayer->GiveAmmo( ceil( iMaxPrimary * PackRatios[GetPowerupSize()] ), TF_AMMO_PRIMARY, true ) )
		{
			bSuccess = true;
		}

		int iMaxSecondary = pTFPlayer->GetMaxAmmo( TF_AMMO_SECONDARY );
		if ( pPlayer->GiveAmmo( ceil( iMaxSecondary * PackRatios[GetPowerupSize()] ), TF_AMMO_SECONDARY, true ) )
		{
			bSuccess = true;
		}

		int iMaxMetal = pTFPlayer->GetMaxAmmo( TF_AMMO_METAL );
		if ( pPlayer->GiveAmmo( ceil( iMaxMetal * PackRatios[GetPowerupSize()] ), TF_AMMO_METAL, true ) )
		{
			bSuccess = true;
		}

		float flCloak = pTFPlayer->m_Shared.GetSpyCloakMeter();
		if ( flCloak < 100.0f )
		{
			pTFPlayer->m_Shared.SetSpyCloakMeter( min( 100.0f, flCloak + 100.0f * PackRatios[GetPowerupSize()] ) );
			bSuccess = true;
		}

		// did we give them anything?
		if ( bSuccess )
		{
			CSingleUserRecipientFilter filter( pPlayer );
			EmitSound( filter, entindex(), TF_AMMOPACK_PICKUP_SOUND );
		}
	}

	return bSuccess;
}
//-----------------------------------------------------------------------------
// Purpose: MyTouch function for the ammopack
//-----------------------------------------------------------------------------
bool CAmmoPack::MyTouch( CBasePlayer *pPlayer )
{
    bool bSuccess = false;

    if ( ValidTouch( pPlayer ) )
    {
        CTFPlayer *pTFPlayer = ToTFPlayer( pPlayer );
        if ( !pTFPlayer )
            return false;

        int iMaxPrimary = pTFPlayer->GetPlayerClass()->GetData()->m_aAmmoMax[TF_AMMO_PRIMARY];
        if ( pPlayer->GiveAmmo( ceil(iMaxPrimary * PackRatios[GetPowerupSize()]), TF_AMMO_PRIMARY, true ) )
        {
            bSuccess = true;
        }

        int iMaxSecondary = pTFPlayer->GetPlayerClass()->GetData()->m_aAmmoMax[TF_AMMO_SECONDARY];
        if ( pPlayer->GiveAmmo( ceil(iMaxSecondary * PackRatios[GetPowerupSize()]), TF_AMMO_SECONDARY, true ) )
        {
            bSuccess = true;
        }

        int iMaxMetal = pTFPlayer->GetPlayerClass()->GetData()->m_aAmmoMax[TF_AMMO_METAL];
        if ( pPlayer->GiveAmmo( ceil(iMaxMetal * PackRatios[GetPowerupSize()]), TF_AMMO_METAL, true ) )
        {
            bSuccess = true;
        }

        // did we give them anything?
        if ( bSuccess )
        {
            CSingleUserRecipientFilter filter( pPlayer );
            EmitSound( filter, entindex(), TF_AMMOPACK_PICKUP_SOUND );
        }
    }

    return bSuccess;
}
Ejemplo n.º 3
0
//-----------------------------------------------------------------------------
// Purpose: MyTouch function for the healthkit
//-----------------------------------------------------------------------------
bool CHealthKit::MyTouch( CBasePlayer *pPlayer )
{
	bool bSuccess = false;

	if ( ValidTouch( pPlayer ) )
	{
		if (GetPowerupSize() == POWERUP_TINY) // TF2C tiny medkit, overheals. can't pick up if hp would exceed max
		{
			if (pPlayer->GetHealth() < pPlayer->GetMaxHealth() * (tf_max_health_boost.GetFloat() - PackRatios[GetPowerupSize()]))
			{
				if (pPlayer->TakeHealth(ceil(pPlayer->GetMaxHealth() * PackRatios[GetPowerupSize()]), DMG_IGNORE_MAXHEALTH))
				{
					CSingleUserRecipientFilter user(pPlayer);
					user.MakeReliable();

					UserMessageBegin(user, "ItemPickup");
					WRITE_STRING(GetClassname());
					MessageEnd();

					if (pPlayer->GetHealth() > pPlayer->GetMaxHealth())
					{
						EmitSound( user, entindex(), "OverhealPillRattle.Touch" );
					}
					else
					{
						EmitSound(user, entindex(), "OverhealPillNoRattle.Touch");
					}

					bSuccess = true;
				}
			}
		}
		else
		{
			if ( pPlayer->TakeHealth( ceil(pPlayer->GetMaxHealth() * PackRatios[GetPowerupSize()]), DMG_GENERIC ) )
				bSuccess = true;

			CTFPlayer *pTFPlayer = ToTFPlayer( pPlayer );

			Assert( pTFPlayer );
			
			// Remove any negative conditions whether player got healed or not.
			if ( pTFPlayer->m_Shared.InCond( TF_COND_BURNING ) )
			{
				pTFPlayer->m_Shared.RemoveCond( TF_COND_BURNING );
				bSuccess = true;
			}
			if ( pTFPlayer->m_Shared.InCond( TF_COND_SLOWED ) )
			{
				pTFPlayer->m_Shared.RemoveCond( TF_COND_SLOWED );
				bSuccess = true;
			}

			if ( bSuccess )
			{
				CSingleUserRecipientFilter user( pPlayer );
				user.MakeReliable();

				UserMessageBegin( user, "ItemPickup" );
				WRITE_STRING( GetClassname() );
				MessageEnd();

				EmitSound( user, entindex(), TF_HEALTHKIT_PICKUP_SOUND );
			}
		}
	}

	return bSuccess;
}