See yourself HLSDK :
Code:
// Shake the screen of all clients within radius
// radius == 0, shake all clients
// UNDONE: Allow caller to shake clients not ONGROUND?
// UNDONE: Fix falloff model (disabled)?
// UNDONE: Affect user controls?
void UTIL_ScreenShake( const Vector ¢er, float amplitude, float frequency, float duration, float radius )
{
int i;
float localAmplitude;
ScreenShake shake;
shake.duration = FixedUnsigned16( duration, 1<<12 ); // 4.12 fixed
shake.frequency = FixedUnsigned16( frequency, 1<<8 ); // 8.8 fixed
for ( i = 1; i <= gpGlobals->maxClients; i++ )
{
CBaseEntity *pPlayer = UTIL_PlayerByIndex( i );
if ( !pPlayer || !(pPlayer->pev->flags & FL_ONGROUND) ) // Don't shake if not onground
continue;
localAmplitude = 0;
if ( radius <= 0 )
localAmplitude = amplitude;
else
{
Vector delta = center - pPlayer->pev->origin;
float distance = delta.Length();
// Had to get rid of this falloff - it didn't work well
if ( distance < radius )
localAmplitude = amplitude;//radius - distance;
}
if ( localAmplitude )
{
shake.amplitude = FixedUnsigned16( localAmplitude, 1<<12 ); // 4.12 fixed
MESSAGE_BEGIN( MSG_ONE, gmsgShake, NULL, pPlayer->edict() ); // use the magic #1 for "one client"
WRITE_SHORT( shake.amplitude ); // shake amount
WRITE_SHORT( shake.duration ); // shake lasts this long
WRITE_SHORT( shake.frequency ); // shake noise frequency
MESSAGE_END();
}
}
}
static unsigned short FixedUnsigned16( float value, float scale )
{
int output;
output = value * scale;
if ( output < 0 )
output = 0;
if ( output > 0xFFFF )
output = 0xFFFF;
return (unsigned short)output;
}
__________________