AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Code Snippets/Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=83)
-   -   [INC] ScreenFade Util [RAGE Supported] (https://forums.alliedmods.net/showthread.php?t=87623)

ConnorMcLeod 03-14-2009 14:49

[INC] ScreenFade Util [RAGE Supported]
 
1 Attachment(s)
Rage version of this : - Clic on me -


Two stocks :

Code:

// Main util
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)

// Util from main util
UTIL_FadeToBlack(id,Float:fxtime=3.0,bool:bReliable=false,bool:bExternal=false)

Details :
  • fxtime and time in seconds (that's the main idea of this util).
  • Color, type : {0-255,0-255,0-255}
  • Alpha, type : 0-255
  • bReliable : if true, uses MSG_ONE or MSG_ALL, if false uses MSG_ONE_UNRELIABLE or MSG_BROADCAST
  • bExternal : if true uses emessage


How to use this stock with a cvar that handle color ?

Cvar should be like this :

Code:
    cvar_pointer = register_cvar("cvar_color", "RRRGGGBBB")
Even if some values are less than 100, you should put the 3 digits, aka 10 -> 010


Then to retrieve the color use :

PHP Code:

get_cvar_colorg_pCvar )
{
    new 
Color[3]

    new 
iTemp get_pcvar_num(g_pCvar)
    
Color[0] = iTemp 1000000
    iTemp 
%= 1000000
    Color
[1] = iTemp 1000
    Color
[2] = iTemp 1000

    
return Color


Example with 2 other ways (less efficient) to handle colors by cvars : -link-

Dr.G 03-14-2009 16:02

Re: ScreenFade Util
 
k+! well done

One 03-21-2009 21:33

Re: [INC] ScreenFade Util
 
Hey,

Have a see here please : http://forums.alliedmods.net/showthread.php?t=88224 :cry:

{PHILMAGROIN} 05-17-2009 11:58

Re: [INC] ScreenFade Util
 
so with this you would not be able to make a cvar "rgb" colors becuase there has to be a value in the {0,0,0} correct?

xPaw 05-17-2009 12:38

Re: [INC] ScreenFade Util
 
they are rgb, {R, G, B}

{PHILMAGROIN} 05-17-2009 13:06

Re: [INC] ScreenFade Util
 
Quote:

Originally Posted by xPaw (Post 829334)
they are rgb, {R, G, B}

yes i know. but if you wanted to make a cvar so you could change those ingame. you couldn't with this correct?

SnoW 05-17-2009 15:02

Re: [INC] ScreenFade Util
 
Quote:

Originally Posted by {PHILMAGROIN} (Post 829363)
yes i know. but if you wanted to make a cvar so you could change those ingame. you couldn't with this correct?

Like this?
PHP Code:

new gCvar];
public 
plugin_init( ) 
{
    
gCvar] = register_cvar"color_red""100" );
    
gCvar] = register_cvar"color_green""255" );
    
gCvar] = register_cvar"color_blue""0" );
}
funcid )
{
    new 
iColor];
    
iColor] = get_pcvar_numgCvar] );
    
iColor] = get_pcvar_numgCvar] );
    
iColor] = get_pcvar_numgCvar] );
    
UTIL_ScreenFadeidiColor1.0....... );



{PHILMAGROIN} 05-17-2009 16:17

Re: [INC] ScreenFade Util
 
Quote:

Originally Posted by SnoW (Post 829459)
Like this?
PHP Code:

new gCvar];
public 
plugin_init( ) 
{
    
gCvar] = register_cvar"color_red""100" );
    
gCvar] = register_cvar"color_green""255" );
    
gCvar] = register_cvar"color_blue""0" );
}
funcid )
{
    new 
iColor];
    
iColor] = get_pcvar_numgCvar] );
    
iColor] = get_pcvar_numgCvar] );
    
iColor] = get_pcvar_numgCvar] );
    
UTIL_ScreenFadeidiColor1.0....... );



maybe. but i was thinking more like on cvar. like i_colors "255 0 0"

ConnorMcLeod 05-17-2009 16:24

Re: [INC] ScreenFade Util
 
Example with 3 way to handle colors by cvars :

way 1 is recommanded, way 2 is deprecated.

PHP Code:

#include <amxmodx>
#include "screenfade_util.inc"

new g_pCvarType1
    
g_pCvarType2
    
g_pCvarType3_Redg_pCvarType3_Greeng_pCvarType3_Blue

public plugin_init()
{
    
register_plugin("color test""0.1""noob")

    
g_pCvarType1 register_cvar("color_type1""000200000")

    
g_pCvarType2 register_cvar("color_type2""0 200 0")

    
g_pCvarType3_Red register_cvar("color_type3_red""0")
    
g_pCvarType3_Green register_cvar("color_type3_green""200")
    
g_pCvarType3_Blue register_cvar("color_type3_blue""0")

    
register_clcmd("say test1""test1")
    
register_clcmd("say test2""test2")
    
register_clcmd("say test3""test3")
}

public 
test1id )
{
    
UTIL_ScreenFade(idget_cvar_color1(g_pCvarType1), 10.010.0250)
    return 
PLUGIN_HANDLED
}

public 
test2id )
{
    
UTIL_ScreenFade(idget_cvar_color2(g_pCvarType2), 10.010.0250)
    return 
PLUGIN_HANDLED
}

public 
test3id )
{
    
UTIL_ScreenFade(idget_cvar_color3(g_pCvarType3_Redg_pCvarType3_Greeng_pCvarType3_Blue), 10.010.0250)
    return 
PLUGIN_HANDLED
}

stock get_cvar_color1g_pCvar // 4 natives // 1 if don't use clamp
{
    new 
Color[3]

    new 
iTemp get_pcvar_num(g_pCvar)
    
Color[0] = clamp(iTemp 10000000255)
    
iTemp %= 1000000
    Color
[1] = clamp(iTemp 10000255)
    
Color[2] = clamp(iTemp 10000255)

    return 
Color
}

stock get_cvar_color2g_pCvar // 8 natives // 5 if don't use clamp
{
    new 
Color[3]

    new 
szColor[12// "RRR GGG BBB"
    
get_pcvar_string(g_pCvarszColorcharsmax(szColor))

    new 
szRed[4], szGreen[4], szBlue[4]
    
parse(szColorszRedcharsmax(szRed), szGreencharsmax(szGreen), szBluecharsmax(szBlue))
    
Color[0] = clamp(str_to_num(szRed), 0255)
    
Color[1] = clamp(str_to_num(szGreen), 0255)
    
Color[2] = clamp(str_to_num(szBlue), 0255)

    return 
Color
}

stock get_cvar_color3g_pCvar_Redg_pCvar_Greeng_pCvar_Blue // 6 natives // 3 if don't use clamp
{
    new 
Color[3]

    
Color[0] = clamp(get_pcvar_num(g_pCvar_Red), 0255)
    
Color[1] = clamp(get_pcvar_num(g_pCvar_Green), 0255)
    
Color[2] = clamp(get_pcvar_num(g_pCvar_Blue), 0255)

    return 
Color



{PHILMAGROIN} 05-17-2009 18:00

Re: [INC] ScreenFade Util
 
Quote:

Originally Posted by ConnorMcLeod (Post 829510)
Something like this ? :

PHP Code:

new iColor[3] = GetColorCVAR_POINTER )

GetColorCVAR_POINTER )
{
    new 
szColors[16], szRed[4], szGreen[4], szBlue[4]
    
get_pcvar_string(CVAR_POINTERszColorscharsmax(szColors))

    new 
iColor[3]
    
iColor[0] = GetColorByte(szRed)
    
iColor[1] = GetColorByte(szGreen)
    
iColor[2] = GetColorByte(szBlue)

    return 
iColor
}

GetColorByte(szColor[4])
{
    new 
iByte str_to_num(szColor)
    if( 
iByte )
    {
        return 
0
    
}
    if( 
iByte 0xFF )
    {
        return 
0xFF
    
}
    return 
iByte



ive been looking trying to understand this and its not working very well haha. but what i think might be right is i would make a cvar from what you have given me which would be like
PHP Code:

iColor register_cvar"i_color""255 0 0" 

is that correct?

Edit: so ive been messing around with it. and nothing. here is the latest method I have tried:
PHP Code:

     #include <amxmodx>
#include <screenfade_util>

new gCvar_Color;

public 
plugin_init() 
{
    
register_pluginPLUGINVERSIONAUTHOR );
    
    
register_event"DeathMsg" "fwDeathMsg" "a" );
    
    
gCvar_Color register_cvar"stk_Color""255 0 0" )
    
}

public 
fwDeathMsg(id
{
            if( 
get_pcvar_numgCvar_Screenfade ))
            { 
            new 
Color_redColor_greenColor_blue;
            new 
color[16], red[4], green[4], blue[4];
            
get_pcvar_string(gCvar_Colorcolor15);
            
parse(colorred3green3blue3);
            
            
Color_red str_to_num(red);
            
Color_green str_to_num(green);
            
Color_blue str_to_num(blue);
                
            
UTIL_ScreenFadeid, {gCvar_Color},1.0,0.0,75  );
            }
        }
    }


this isnt all of the code but its what i have done to it. the error is: Error: Must be a constant expression; assumed zero on line 57 <--- that is the UTIL_ScreenFade line the last line of code. any ideas?


All times are GMT -4. The time now is 13:26.

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