Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define ARMOR_RATIO 0.5 // Armor Takes 80% of the damage
- #define ARMOR_BONUS 0.5 // Each Point of Armor is work 1/x points of health
- int CBasePlayer::TakeDamage( entvars_t* pevInflictor, entvars_t* pevAttacker, float flDamage, int bitsDamageType )
- {
- float flRatioShield;
- float flBonus;
- float flRatio;
- int iTookDamage;
- PLAYER_ANIM iAnim;
- bool bHasKevlar;
- if( bitsDamageType & ( DMG_GRENADE | DMG_BLAST | DMG_FALL ) )
- {
- m_LastHitGroup = HITGROUP_GENERIC;
- }
- if( m_LastHitGroup == HITGROUP_SHIELD && bitsDamageType & DMG_BULLET )
- {
- return 0;
- }
- flRatioShield = 0;
- flBonus = ARMOR_BONUS;
- flRatio = ARMOR_RATIO;
- if( HasShield() )
- {
- flRatioShield = 0.2;
- }
- if( m_fIsVIP )
- {
- flRatio = 0.25;
- }
- if( bitsDamageType & ( DMG_GRENADE | DMG_BLAST ) )
- {
- if( !IsAlive() )
- {
- return 0;
- }
- CBaseEntity *pInflictor = CBaseEntity::Instance( pevInflictor );
- if( bitsDamageType & DMG_GRENADE )
- {
- if( !strcmp( STRING( pInflictor->pev->classname ), "grenade" ) )
- {
- if( !CVAR_GET_FLOAT( "mp_friendlyfire" ) )
- }
- }
- }
- if( ~bitsDamageType & ( DMG_GRENADE | DMG_BLAST ) )
- {
- CBaseEntity *pInflictor = CBaseEntity::Instance( pevInflictor );
- if( !g_pGameRules->FPlayerCanTakeDamage( this, pInflictor ) && strcmp( STRING( pInflictor->pev->classname ), "grenade" ) )
- {
- return 0;
- }
- if( ( bitsDamageType & DMG_BLAST ) && g_pGameRules->IsMultiplayer() )
- {
- flBonus *= 2;
- }
- if( !IsAlive() )
- {
- return 0;
- }
- CBaseEntity *pEntity = GetClassPtr( (CBaseEntity *)pevAttacker );
- if( pEntity && pEntity->IsPlayer() )
- {
- CBasePlayer *pAttacker = GetClassPtr( (CBasePlayer *)pevAttacker );
- if( pAttacker != this && pAttacker->m_iTeam == m_iTeam )
- {
- if( !FBitSet( pAttacker->m_fHintMessageHistory, Hint_try_not_to_injure_teammates ) )
- {
- pAttacker->m_fHintMessageHistory |= Hint_try_not_to_injure_teammates;
- pAttacker->HintMessage( "#Hint_try_not_to_injure_teammates", FALSE, FALSE );
- }
- if( m_flNextGameTeamAttack + 0.6 < gpGlobals->time )
- {
- m_flNextGameTeamAttack = gpGlobals->time;
- CBaseEntity *pEntity = NULL;
- while( ( pEntity = UTIL_FindEntityByClassname( pEntity, "player" ) ) != NULL )
- {
- if( !FNullEnt( pEntity ) )
- {
- CBasePlayer *pPlayer = GetClassPtr( (CBasePlayer *)pEntity->pev );
- if( pPlayer->m_iTeam == m_iTeam )
- {
- ClientPrint( pPlayer->pev, HUD_PRINTCENTER, "#Game_teammate_attack", STRING( this->pev->netname ) );
- }
- }
- }
- }
- flDamage *= 0.35;
- }
- CBasePlayerItem *pActiveItem = pAttacker->m_pActiveItem;
- int iAttackerWeaponId = pActiveItem->m_iId;
- if( pActiveItem )
- {
- float flWeaponRatio;
- flRatio += flRatioShield;
- switch( iAttackerWeaponId )
- {
- case WEAPON_AWP : flWeaponRatio = 1.95; break;
- case WEAPON_G3SG1 : flWeaponRatio = 1.65; break;
- case WEAPON_SG550 : flWeaponRatio = 1.45; break;
- case WEAPON_ELITE : flWeaponRatio = 1.05; break;
- case WEAPON_GLOCK18 : flWeaponRatio = 1.05; break;
- case WEAPON_FIVESEVEN : flWeaponRatio = 1.50; break;
- case WEAPON_M249 : flWeaponRatio = 1.50; break;
- case WEAPON_DEAGLE : flWeaponRatio = 1.50; break;
- case WEAPON_P90 : flWeaponRatio = 1.50; break;
- case WEAPON_MAC10 : flWeaponRatio = 0.95; break;
- case WEAPON_P228 : flWeaponRatio = 1.25; break;
- case WEAPON_SCOUT : flWeaponRatio = 1.70; break;
- case WEAPON_KNIFE : flWeaponRatio = 1.70; break;
- case WEAPON_AUG : flWeaponRatio = 1.40; break;
- case WEAPON_FAMAS : flWeaponRatio = 1.40; break;
- case WEAPON_M4A1 : flWeaponRatio = 1.40; break;
- case WEAPON_SG552 : flWeaponRatio = 1.40; break;
- case WEAPON_GALIL : flWeaponRatio = 1.55; break;
- case WEAPON_AK47 : flWeaponRatio = 1.55; break;
- }
- flRatio *= flWeaponRatio;
- }
- if( ShouldDoLargeFlinch( m_LastHitGroup, iAttackerWeaponId ) )
- {
- if( pev->velocity.Length() < 300 )
- {
- pev->velocity = pev->velocity + ( pev->origin - pAttacker->pev->origin ).Normalize() * 170;
- m_flPainShock = 0.65;
- }
- iAnim = PLAYER_LARGE_FLINCH;
- }
- else
- {
- m_flPainShock = 0.50;
- m_fKilledByHeadshot = FALSE;
- if( m_LastHitGroup == HITGROUP_HEAD && flDamage > 60 )
- {
- m_fKilledByHeadshot = TRUE;
- }
- else if( flDamage <= 20 )
- {
- m_fKilledByHeadshot = FALSE;
- }
- iAnim = PLAYER_SMALL_FLINCH;
- }
- SetAnimation( iAnim );
- }
- m_lastDamageAmount = flDamage;
- if( !pev->armorvalue || bitsDamageType & ( DMG_FALL | DMG_DROWN ) || !IsArmored( m_LastHitGroup ) )
- {
- bHasKevlar = false;
- }
- else
- {
- float flNew = flDamage * flRatio;
- float flArmor = ( flDamage - flNew ) * flBonus;
- if( flArmor > pev->armorvalue )
- {
- flArmor = ( 1 / flBonus ) * pev->armorvalue;
- flNew = flDamage - flArmor;
- pev->armorvalue = 0;
- }
- else
- {
- if( flArmor < 0 )
- flArmor = 1.0;
- pev->armorvalue -= flArmor;
- }
- flDamage = flNew;
- if( pev->armorvalue < 0 )
- m_iKevlar = 0;
- bHasKevlar = true;
- }
- Pain( m_LastHitGroup, bHasKevlar );
- LogAttack( pAttacker, this, _, _, _, pev->health - flNew, pev->armorvalue, GetWeaponName( this->pev, pInflictor ) );
- iTookDamage = CBaseMonster::TakeDamage( pevInflictor, pevAttacker, (int)flDamage, bitsDamageType );
- if( iTookDamage )
- {
- /*! @todo Implements this :
- if( TheBots )
- TheBots->OnEvent( EVENT_PLAYER_TOOK_DAMAGE, pevAttacker, this ); */
- if( g_pGameRules->IsCareer() )
- {
- for( int i = 1; i <= gpGlobals->maxClients; ++i )
- {
- CBasePlayer* pPlayer = (CBasePlayer *)UTIL_PlayerByIndex( i );
- if( pPlayer && !pPlayer->IsBot() && pPlayer->pev == pevAttacker && pPlayer->m_iTeam != m_iTeam )
- {
- /*! @todo Implements this :
- TheCareerTasks->HandleEnemyInjury( GetWeaponName( pevInflictor, pevAttacker ), pPlayer->HasShield(), pPlayer ); */
- }
- }
- }
- }
- for( int i = 0; i < CDMG_TIMEBASED; i++ )
- {
- if( bitsDamageType & ( DMG_PARALYZE << i ) )
- {
- m_rgbTimeBasedDamage[i] = 0;
- }
- }
- MESSAGE_BEGIN( MSG_SPEC, SVC_DIRECTOR );
- WRITE_BYTE ( 9 ); // command length in bytes
- WRITE_BYTE ( DRC_CMD_EVENT ); // take damage event
- WRITE_SHORT( ENTINDEX( this->edict() ) ); // index number of primary entity
- WRITE_SHORT( ENTINDEX(ENT( pevInflictor ) ) ); // index number of secondary entity
- WRITE_LONG( 5 ); // eventflags (priority and flags)
- MESSAGE_END();
- int health = pev->health;
- if( health < 0 )
- health = 0;
- MESSAGE_BEGIN( MSG_SPEC, gmsgHLTV );
- WRITE_BYTE( ENTINDEX( this->edict() ) );
- WRITE_BYTE( health );
- MESSAGE_END();
- for( int i = 1; i <= gpGlobals->maxClients; ++i )
- {
- CBasePlayer* pPlayer = (CBasePlayer *)UTIL_PlayerByIndex( i );
- if( pPlayer && m_hObserverTarget == this )
- {
- int health = pPlayer->pev->health;
- if( health < 0 )
- health = 0;
- MESSAGE_BEGIN( MSG_ONE, gmsgSpecHealth, NULL, ENT( pPlayer->pev ) );
- WRITE_BYTE( health );
- MESSAGE_END();
- }
- }
- m_bitsDamageType |= bitsDamageType; // Save this so we can report it to the client
- m_bitsHUDDamage = -1; // make sure the damage bits get resent
- return iTookDamage;
- }
- else
- {
- if( !IsAlive() )
- {
- return 0;
- }
- CBaseEntity *pInflictor = CBaseEntity::Instance( pevInflictor );
- if( bitsDamageType & DMG_GRENADE )
- {
- if( !strcmp( STRING( pInflictor->pev->classname ), "grenade" ) )
- {
- if( !CVAR_GET_FLOAT( "mp_friendlyfire" ) )
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement