AMXX-BG.INFO screenfade_util.inc Raw include

screenfade_util.inc

Original include source with line numbers.

Back Download .inc
1 #if defined _screenfade_util_included
2 #endinput
3 #endif
4 #define _screenfade_util_included
5
6 #define FFADE_IN 0x0000 // Just here so we don't pass 0 into the function
7 #define FFADE_OUT 0x0001 // Fade out (not in)
8 #define FFADE_MODULATE 0x0002 // Modulate (don't blend)
9 #define FFADE_STAYOUT 0x0004 // ignores the duration, stays faded out until new ScreenFade message received
10
11 enum {
12 Red,
13 Green,
14 Blue
15 };
16
17 stock FixedUnsigned16(Float:flValue, iScale)
18 {
19 new iOutput;
20
21 iOutput = floatround(flValue * iScale);
22
23 if ( iOutput < 0 )
24 iOutput = 0;
25
26 if ( iOutput > 0xFFFF )
27 iOutput = 0xFFFF;
28
29 return iOutput;
30 }
31
32 stock UTIL_ScreenFade(id=0,iColor[3]={0,0,0},Float:flFxTime=-1.0,Float:flHoldTime=0.0,iAlpha=0,iFlags=FFADE_IN,bool:bReliable=false,bool:bExternal=false)
33 {
34 if( id && !is_user_connected(id))
35 return;
36
37 new iFadeTime;
38 if( flFxTime == -1.0 )
39 {
40 iFadeTime = 4;
41 }
42 else
43 {
44 iFadeTime = FixedUnsigned16( flFxTime , 1<<12 );
45 }
46
47 static gmsgScreenFade;
48 if( !gmsgScreenFade )
49 {
50 gmsgScreenFade = get_user_msgid("ScreenFade");
51 }
52
53 new MSG_DEST;
54 if( bReliable )
55 {
56 MSG_DEST = id ? MSG_ONE : MSG_ALL;
57 }
58 else
59 {
60 MSG_DEST = id ? MSG_ONE_UNRELIABLE : MSG_BROADCAST;
61 }
62
63 if( bExternal )
64 {
65 emessage_begin( MSG_DEST, gmsgScreenFade, _, id );
66 ewrite_short( iFadeTime );
67 ewrite_short( FixedUnsigned16( flHoldTime , 1<<12 ) );
68 ewrite_short( iFlags );
69 ewrite_byte( iColor[Red] );
70 ewrite_byte( iColor[Green] );
71 ewrite_byte( iColor[Blue] );
72 ewrite_byte( iAlpha );
73 emessage_end();
74 }
75 else
76 {
77 message_begin( MSG_DEST, gmsgScreenFade, _, id );
78 write_short( iFadeTime );
79 write_short( FixedUnsigned16( flHoldTime , 1<<12 ) );
80 write_short( iFlags );
81 write_byte( iColor[Red] );
82 write_byte( iColor[Green] );
83 write_byte( iColor[Blue] );
84 write_byte( iAlpha );
85 message_end();
86 }
87 }
88
89 stock UTIL_FadeToBlack(id,Float:fxtime=3.0,bool:bReliable=false,bool:bExternal=false)
90 {
91 UTIL_ScreenFade(id, _, fxtime, fxtime, 255, FFADE_OUT|FFADE_STAYOUT,bReliable,bExternal);
92 }