AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   ScreenShake time stock (https://forums.alliedmods.net/showthread.php?t=213957)

Podarok 04-21-2013 09:05

ScreenShake time stock
 
Can someone write a small stock where you can choose a numeric Float for duration, amout and freaquency of ScreenShake.

ConnorMcLeod 04-21-2013 09:15

Re: ScreenShake time stock
 
I think that if you look at screenFADE_util thread, you can find a post from arkshine with another stock, for make screenshake according to distance from a specific origin.
Following one is a simple stock with float input values.

PHP Code:

// ScreenShake
stock Util_ScreenShake(idFloat:durationFloat:frequencyFloat:amplitude)
{
    static 
ScreenShake 0;
    if( !
ScreenShake )
    {
        
ScreenShake get_user_msgid("ScreenShake");
    }
    
message_beginid MSG_ONE_UNRELIABLE MSG_BROADCASTScreenShake_id);
    
write_shortFixedUnsigned16amplitude1<<12 ) ); // shake amount
    
write_shortFixedUnsigned16duration1<<12 ) ); // shake lasts this long
    
write_shortFixedUnsigned16frequency1<<) ); // shake noise frequency
    
message_end();
}

stock FixedUnsigned16Float:valuescale )
{
    new 
output;

    
output floatround(value scale);
    if ( 
output )
        
output 0;
    if ( 
output 0xFFFF )
        
output 0xFFFF;

    return 
output;



Podarok 04-21-2013 09:18

Re: ScreenShake time stock
 
Thanks you a lot!

EDIT : From which to which number is frequency and amplityde ?

ConnorMcLeod 04-21-2013 10:10

Re: ScreenShake time stock
 
max short value is 65535

1<<12 = 4096
1<<8 = 256

So amplitude and duration can be max 16.0 (65535 / 4096 = 15.999756) and freq can be max 256.0 (255.996094).

Podarok 04-22-2013 01:05

Re: ScreenShake time stock
 
Thanks a lot Connor, but it is not actually working as it should, i guess
Code:
Util_ScreenShake(id, 6.0, 256.0, 16.0)
Shake doesnt last for 6 seconds :/

ConnorMcLeod 04-22-2013 02:19

Re: ScreenShake time stock
 
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 &center, 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;
}



All times are GMT -4. The time now is 10:55.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.