This is part of the FX library I�m working on and it�s NEW, so if
you use this, please contact me
before, please.
To include the red screen I made use of
UTIL_ScreenFade, but since
I do not have pointer on the player while I code I have to use the
edict, so I will write the whole ScreenFade stuff for edicts into
the player.cpp:
Above void CBasePlayer::
TakeDamage( entvars_t *pevInflictor, entvars_t *pevAttacker, float
flDamage, int bitsDamageType ) insert:
static unsigned short
FixedUnsigned16( float value, float scale ) //FX
{
int output;
output = value * scale;
if ( output < 0 )
output = 0;
if ( output > 0xFFFF )
output = 0xFFFF;
return (unsigned short)output;
}
void UTIL_EdictScreenFadeBuild( ScreenFade &fade, const Vector &color,
float fadeTime, float fadeHold, int alpha, int flags )
{
fade.duration = FixedUnsigned16( fadeTime, 1<<12 ); // 4.12 fixed
fade.holdTime = FixedUnsigned16( fadeHold, 1<<12 ); // 4.12 fixed
fade.r = (int)color.x;
fade.g = (int)color.y;
fade.b = (int)color.z;
fade.a = alpha;
fade.fadeFlags = flags;
}
void UTIL_EdictScreenFadeWrite( const ScreenFade &fade, edict_s
*edict )
{
MESSAGE_BEGIN( MSG_ONE, gmsgFade, NULL, edict ); // use the magic #1
for "one client"
WRITE_SHORT( fade.duration ); // fade lasts this long
WRITE_SHORT( fade.holdTime ); // fade lasts this long
WRITE_SHORT( fade.fadeFlags ); // fade type (in / out)
WRITE_BYTE( fade.r ); // fade red
WRITE_BYTE( fade.g ); // fade green
WRITE_BYTE( fade.b ); // fade blue
WRITE_BYTE( fade.a ); // fade blue
MESSAGE_END();
}
void UTIL_EdictScreenFade( edict_s *edict, const Vector &color,
float fadeTime, float fadeHold, int alpha, int flags ) //FX
{
ScreenFade fade;
UTIL_EdictScreenFadeBuild( fade, color, fadeTime, fadeHold, alpha,
flags );
UTIL_EdictScreenFadeWrite( fade, edict );
}
Now this is just what you find in
util.cpp, just with Edict in front (exept for the fisrt one,
so sue me...)
Now these would be implemented so let�s get over to their use, In
the TakeDamage function
put:
float alphachange;
alphachange = flDamage * 3;
if (alphachange > 255)
alphachange = 255;
UTIL_EdictScreenFade( edict(), Vector(128,0,0), 1, 1, (int)alphachange,
FFADE_IN ); //FX
I recommend you should tweak these values for your use.
Then in the Killed
function put:
UTIL_EdictScreenFade( edict(),
Vector(128,0,0), 10, 15, 200, FFADE_OUT | FFADE_STAYOUT ); //FX
where it has been commented out.
But we will have to fade them back or they will run around like
that, so put:
UTIL_EdictScreenFade( edict(),
Vector(128,0,0), 1, 15, 0, FFADE_OUT | FFADE_STAYOUT ); //FX
into StartDeathCam and
Spawn.
And there we�re done! Go test it (on bounce with realistic falling
damage) and there you go! |