| ConnorMcLeod |
05-31-2013 14:48 |
Re: shake
PHP Code:
stock FixedUnsigned16( Float:value, scale ) { new output;
output = floatround(value * scale); if ( output < 0 ) output = 0; if ( output > 0xFFFF ) output = 0xFFFF;
return output; }
// ScreenShake stock Util_ScreenShake(id, Float:duration, Float:frequency, Float:amplitude) { static ScreenShake = 0; if( !ScreenShake ) { ScreenShake = get_user_msgid("ScreenShake"); } message_begin( id ? MSG_ONE : MSG_ALL, ScreenShake, _, id); write_short( FixedUnsigned16( amplitude, 1<<12 ) ); // shake amount write_short( FixedUnsigned16( duration, 1<<12 ) ); // shake lasts this long write_short( FixedUnsigned16( frequency, 1<<8 ) ); // shake noise frequency message_end(); }
// ScreenFade enum ( <<=1 ){ FFADE_IN, // Just here so we don't pass 0 into the function FFADE_OUT = 1, // Fade out (not in) FFADE_MODULATE, // Modulate (don't blend) FFADE_STAYOUT // ignores the duration, stays faded out until new ScreenFade message received }
enum { _Red, _Green, _Blue };
stock UTIL_ScreenFade(const id=0,const iColor[3]={0,0,0},const Float:flFxTime=-1.0,const Float:flHoldTime=0.0,const iAlpha=0,const iFlags=FFADE_IN,bool:bReliable=false,bool:bExternal=false) { if( id && !is_user_connected(id)) return;
new iFadeTime; if( flFxTime == -1.0 ) { iFadeTime = 4; } else { iFadeTime = FixedUnsigned16( flFxTime , 1<<12 ); }
static msgScreenFade = 0; if( !msgScreenFade ) { msgScreenFade = get_user_msgid("ScreenFade"); }
new MSG_DEST; if( bReliable ) { MSG_DEST = id ? MSG_ONE : MSG_ALL; } else { MSG_DEST = id ? MSG_ONE_UNRELIABLE : MSG_BROADCAST; }
if( bExternal ) { emessage_begin( MSG_DEST, msgScreenFade, _, id ); ewrite_short( iFadeTime ); ewrite_short( FixedUnsigned16( flHoldTime , 1<<12 ) ); ewrite_short( iFlags ); ewrite_byte( iColor[_Red] ); ewrite_byte( iColor[_Green] ); ewrite_byte( iColor[_Blue] ); ewrite_byte( iAlpha ); emessage_end(); } else { message_begin( MSG_DEST, msgScreenFade, _, id ); write_short( iFadeTime ); write_short( FixedUnsigned16( flHoldTime , 1<<12 ) ); write_short( iFlags ); write_byte( iColor[_Red] ); write_byte( iColor[_Green] ); write_byte( iColor[_Blue] ); write_byte( iAlpha ); message_end(); } }
->
PHP Code:
public shake(id) { UTIL_ScreenFade(id, {34,34,139}, 4.0, 0.001, 75) Util_ScreenShake(id, 3.0, 255.0, 15.0) // maxs : ( , 15.0, 255.0, 15.0) }
|