| closedCreating screenfades |
| Started by Tank on 03-31-2009, 10:37 PM |
Threads: 59
Joined: Jan 2007
Ok I am trying to add some screenfades to a plugin. I've been working on this a few months ago and Im not sure if I managed to get it working back then, nor if Im on the right way now.nnWhat are my issues:n- No idea how to set the duration of the screenfade. As in how long does it last.n- How do I set the hold time?nMy general idea is to create a slow fading in/fading out screenfade which lasts for the amount of seconds I can set somehownnI am trying to either work around the deci-seconds as I am talking about a screenfade lasting for example 25 seconds, something I have no clue about how to set it in deci-seconds, not even with this post.nnNow im still in my "creating my own/borrowing pieces of code" stage of coding. So I think (didn't update comments on coding and now I have no idea where I was at that point) this piece of coding should set my duration?n
for(new Float:xtime = 2.0;xtime <= 40.0;xtime +=2.0)n set_task(xtime,"screenpulse",capper)nnIf so, which amount do I have to change, the 2.0, the 40.0 or the +=2.0? As I still have no clue how to use a for statement.nnThis is what I got so far:n//=========================================================n// Array'sn//=========================================================nnew g_Color[33][3]nn//=========================================================n// piece of coding in a functionn//=========================================================n// Set the colours on the screenfade, in this case greenn g_Color[capper] = {0,255,0}n // run the function screenpulse(capper)n screenpulse(capper)n n // How long screenfade lastn for(new Float:xtime = 2.0;xtime <= 40.0;xtime +=2.0)n set_task(xtime,"screenpulse",capper)nn//=========================================================n// Screen pulse (screenfade)n//=========================================================npublic screenpulse(capper)n{n message_begin(MSG_ONE_UNRELIABLE,get_user_msgid("ScreenFade"),{0,0,0},capper)n write_short(1<<300)//n write_short(1<<300)// Making these three at 2, 2, 2 and the screenfade will stay, so no pulsen write_short(1<<12)//n write_byte(g_Color[capper][0])n write_byte(g_Color[capper][1]) n write_byte(g_Color[capper][2])n write_byte(150)n message_end()n}nThreads: 75
Joined: Nov 2007
check this looks ok imo.rnrn
/* Plugin generated by AMXX-Studio */rnrn#include <amxmodx>rnrn#define PLUGIN "screen fade"rn#define VERSION "1.0"rn#define AUTHOR "Doc"rnrn/* by ConnorMcLeod */rn#define FFADE_IN 0x0000 // Just here so we don't pass 0 into the functionrn#define FFADE_OUT 0x0001 // Fade out (not in)rn#define FFADE_MODULATE 0x0002 // Modulate (don't blend)rn#define FFADE_STAYOUT 0x0004 // ignores the duration, stays faded out until new ScreenFade message receivedrnrnenum {rn Red,rn Green,rn Bluern}rnrnnew p_timernrnpublic plugin_init() rn{rn register_plugin(PLUGIN, VERSION, AUTHOR)rn rn p_time = register_cvar("sf_test","0.5")rn rn register_clcmd("say /sfi","fade_in")rn}rnrnpublic fade_in(id)rn{rn // fade inrn UTIL_ScreenFade(id,{0,255,0}, get_pcvar_float(p_time)/2, get_pcvar_float(p_time), 50, FFADE_OUT, false, false)rn rn set_task(get_pcvar_float(p_time) - 0.1, "fade_out", id)rn}rnpublic fade_out(id)rn{rn // fade outrn UTIL_ScreenFade(id,{0,255,0}, get_pcvar_float(p_time)/2, get_pcvar_float(p_time), 50, FFADE_IN, false, false)rnrn}rnrn/* stocks by ConnorMcLeod */rnstock FixedUnsigned16(Float:flValue, iScale)rn{rn new iOutput;rnrn iOutput = floatround(flValue * iScale);rnrn if ( iOutput < 0 )rn iOutput = 0;rnrn if ( iOutput > 0xFFFF )rn iOutput = 0xFFFF;rnrn return iOutput;rn}rnrnstock 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)rn{rn if( id && !is_user_connected(id))rn return;rnrn new iFadeTime;rn if( flFxTime == -1.0 )rn {rn iFadeTime = 4;rn }rn elsern {rn iFadeTime = FixedUnsigned16( flFxTime , 1<<12 );rn }rnrn static gmsgScreenFade;rn if( !gmsgScreenFade )rn {rn gmsgScreenFade = get_user_msgid("ScreenFade");rn }rnrn new MSG_DEST;rn if( bReliable )rn {rn MSG_DEST = id ? MSG_ONE : MSG_ALL;rn }rn elsern {rn MSG_DEST = id ? MSG_ONE_UNRELIABLE : MSG_BROADCAST;rn }rnrn if( bExternal )rn {rn emessage_begin( MSG_DEST, gmsgScreenFade, _, id );rn ewrite_short( iFadeTime );rn ewrite_short( FixedUnsigned16( flHoldTime , 1<<12 ) );rn ewrite_short( iFlags );rn ewrite_byte( iColor[Red] );rn ewrite_byte( iColor[Green] );rn ewrite_byte( iColor[Blue] );rn ewrite_byte( iAlpha );rn emessage_end();rn }rn elsern {rn message_begin( MSG_DEST, gmsgScreenFade, _, id );rn write_short( iFadeTime );rn write_short( FixedUnsigned16( flHoldTime , 1<<12 ) );rn write_short( iFlags );rn write_byte( iColor[Red] );rn write_byte( iColor[Green] );rn write_byte( iColor[Blue] );rn write_byte( iAlpha );rn message_end();rn }rn}rnrnstock UTIL_FadeToBlack(id,Float:fxtime=3.0,bool:bReliable=false,bool:bExternal=false)rn{rn UTIL_ScreenFade(id, _, fxtime, fxtime, 255, FFADE_OUT|FFADE_STAYOUT,bReliable,bExternal);rn}rnrnsay /sfi to see what it does. the stocks used is made by ConnorMcLeod and his inc file and details can be found here: http://forums.alliedmods.net/showthread.php?t=87623
