Raised This Month: $ Target: $400
 0% 

ScreenShake time stock


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Podarok
BANNED
Join Date: Jan 2011
Location: Narnia
Old 04-21-2013 , 09:05   ScreenShake time stock
Reply With Quote #1

Can someone write a small stock where you can choose a numeric Float for duration, amout and freaquency of ScreenShake.
Podarok is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 04-21-2013 , 09:15   Re: ScreenShake time stock
Reply With Quote #2

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;

__________________
- tired and retired -

- my plugins -

Last edited by ConnorMcLeod; 04-21-2013 at 09:17.
ConnorMcLeod is offline
Podarok
BANNED
Join Date: Jan 2011
Location: Narnia
Old 04-21-2013 , 09:18   Re: ScreenShake time stock
Reply With Quote #3

Thanks you a lot!

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

Last edited by Podarok; 04-21-2013 at 09:20.
Podarok is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 04-21-2013 , 10:10   Re: ScreenShake time stock
Reply With Quote #4

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).
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Podarok
BANNED
Join Date: Jan 2011
Location: Narnia
Old 04-22-2013 , 01:05   Re: ScreenShake time stock
Reply With Quote #5

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 :/
Podarok is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 04-22-2013 , 02:19   Re: ScreenShake time stock
Reply With Quote #6

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;
}
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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