For this tutorial, we will be modifying the base player class. Open up server/player.cpp and edit the DamageEffect function. This function do some kind of damage effect for the type of damage. In this case we're adding the extra code for shoot damage (DMG_BULLET):
Copy Source | Copy HTML
//------------------------------------------------------------------------------
- // Purpose : Do some kind of damage effect for the type of damage
- // Input :
- // Output :
- //------------------------------------------------------------------------------
- void CBasePlayer::DamageEffect(float flDamage, int fDamageType)
- {
- if (fDamageType & DMG_CRUSH)
- {
- //Red damage indicator
- color32 red = {128, 0, 0,128};
- UTIL_ScreenFade( this, red, 1.0f, 0.1f, FFADE_IN );
- }
- else if (fDamageType & DMG_DROWN)
- {
- //Red damage indicator
- color32 blue = { 0, 0,128,128};
- UTIL_ScreenFade( this, blue, 1.0f, 0.1f, FFADE_IN );
- }
- else if (fDamageType & DMG_SLASH)
- {
- // If slash damage shoot some blood
- SpawnBlood(EyePosition(), g_vecAttackDir, BloodColor(), flDamage);
- }
- else if (fDamageType & DMG_PLASMA)
- {
- // Blue screen fade
- color32 blue = { 0, 0,255,100};
- UTIL_ScreenFade( this, blue, 0.2, 0.4, FFADE_MODULATE );
- // Very small screen shake
- // Both -0.1 and 0.1 map to 0 when converted to integer, so all of these RandomInt
- // calls are just expensive ways of returning zero. This code has always been this
- // way and has never had any value. clang complains about the conversion from a
- // literal floating-point number to an integer.
- //ViewPunch(QAngle(random->RandomInt(-0.1,0.1), random->RandomInt(-0.1,0.1), random->RandomInt(-0.1,0.1)));
- // Burn sound
- EmitSound( "Player.PlasmaDamage" );
- }
- else if (fDamageType & DMG_SONIC)
- {
- // Sonic damage sound
- EmitSound( "Player.SonicDamage" );
- }
- else if ( fDamageType & DMG_BULLET )
- {
- //Disorient the player
- QAngle angles = GetLocalAngles();
- angles.x += random->RandomInt( -1, 1 );
- angles.y += random->RandomInt( -1, 1 );
- angles.z = 0;
- SnapEyeAngles( angles );
- ViewPunch( QAngle( -8, random->RandomFloat( -2, 2 ), 0 ) );
- EmitSound( "Flesh.BulletImpact" );
- }
- }