View Single Post
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 08-01-2009 , 08:26   Re: HE Grenade + Screen Shake
Reply With Quote #3

Here my version :

Code:
    #include <amxmodx>     #include <fakemeta>     #include <hamsandwich>         const MAX_CLIENTS = 32;         #define MAX_DAMAGE  100     #define AMPLITUDE   MAX_DAMAGE * 0.2     #define FREQUENCY   0.7     #define DURECTION   1.0     #define RADIUS      MAX_DAMAGE * 3.0         enum _:Coord_e     {         Float:x,         Float:y,         Float:z     };         new gMsgidScreenShake;     #define VectorSubtract(%1,%2,%3)  ( %3[ x ] = %1[ x ] - %2[ x ], %3[ y ] = %1[ y ] - %2[ y ], %3[ z ] = %1[ z ] - %2[ z ] )     #define VectorLength(%1)          ( floatsqroot ( %1[ x ] * %1[ x ] + %1[ y ] * %1[ y ] + %1[ z ] * %1[ z ] ) )     public plugin_init ()     {         register_plugin( "Shaking HeGrenade", "1.0.0", "Arkshine" );         register_event( "23", "CGrenade_Explosed", "a", "1=3", "6=25" );         gMsgidScreenShake = get_user_msgid( "ScreenShake" );     }     public CGrenade_Explosed ()     {         new Float:ExplosionOrigin[ Coord_e ];                 read_data( 2, ExplosionOrigin[ x ] );         read_data( 3, ExplosionOrigin[ y ] );         read_data( 4, ExplosionOrigin[ z ] );                 FX_ScreenShake( .Center    = ExplosionOrigin,                         .Amplitude = AMPLITUDE,                         .Frequency = FREQUENCY,                         .Duration  = DURECTION,                         .Radius    = RADIUS );     }             FX_ScreenShake ( const Float:Center[ Coord_e ], const Float:Amplitude, const Float:Frequency, const Float:Duration, const Float:Radius )     {         new Players[ MAX_CLIENTS ];         new Float:Origin[ Coord_e ];         new Float:LocalAmplitude;         new Ampl;         new Player;         new Num;                 new Dura = UTIL_FixedUnsigned16( Duration  , 1 << 12 );         new Freq = UTIL_FixedUnsigned16( Frequency , 1 << 8  );         get_players( Players, Num, "ac" );         for ( new i = 0; i < Num; i++ )         {             Player = Players[ i ];             LocalAmplitude = 0.0;             if ( Radius <= 0 )             {                 LocalAmplitude = Amplitude;             }             else             {                 pev( Player, pev_origin, Origin );                 VectorSubtract( Origin, Center, Origin );                 if ( VectorLength( Origin ) < Radius )                 {                     LocalAmplitude = Amplitude;                 }             }             if ( LocalAmplitude )             {                 if ( !( pev( Player, pev_flags ) & FL_ONGROUND ) )                 {                     LocalAmplitude *= 0.5;                 }             }             Ampl = UTIL_FixedUnsigned16( LocalAmplitude, 1 << 12 );             message_begin( MSG_ONE_UNRELIABLE, gMsgidScreenShake, .player = Player );             write_short( Ampl )// --| Shake amount.             write_short( Dura )// --| Shake lasts this long.             write_short( Freq )// --| Shake noise frequency.             message_end ();         }     }         UTIL_FixedUnsigned16 ( const Float:Value, const Scale )     {         return clamp( floatround( Value * Scale ), 0, 0xFFFF );     }
__________________
Arkshine is offline