Raised This Month: $ Target: $400
 0% 

black screen fade function


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
n0br41ner
Senior Member
Join Date: May 2012
Location: Planet Earth
Old 06-18-2012 , 08:38   black screen fade function
Reply With Quote #1

i want to fade a players screen to black (just like fade to black)

i know i have to use this
so i wrote these functions

PHP Code:
g_MsgFade get_user_msgid("ScreenFade");

public 
BlackOutSameIPs() {
    
g_iDeadPlayer read_data(2);
    
    if(!
is_user_alive(g_iDeadPlayer) && g_bSameIPs[g_iDeadPlayer]) {
        
message_begin(MSG_ONEg_MsgFade, {0,0,0}, g_iDeadPlayer);
        
write_short(4096);
        
write_short(4096);
        
write_short(4096);
        
write_byte(0);
        
write_byte(0);
        
write_byte(0);
        
write_byte(255);
        
message_end();
    } 

and the one that removes his black screen (back to normal)
PHP Code:
g_MsgFade get_user_msgid("ScreenFade");

public 
ResetScreen(iPlayerID) {
    if(
is_user_alive(iPlayerID)) {
        
message_begin(MSG_ONEg_MsgFade, {0,0,0}, iPlayerID);
        
write_short(1<<12);
        
write_short(1<<8);
        
write_short(1<<1);
        
write_byte(0);
        
write_byte(0);
        
write_byte(0);
        
write_byte(255);
        
message_end();
    }

i have no idea what these mean
PHP Code:
        write_short(1<<12);
        
write_short(1<<8);
        
write_short(1<<1); 
or these
PHP Code:
        write_short(4096);
        
write_short(4096);
        
write_short(4096); 
sometime you write numbers and others you write 1>>3 or w/e that means
can you please explain?

also i want that the first function blacks it out infinitly until i call the second function that removes the black screen

EDIT: i just noticed
Note: Duration and HoldTime is in special units. 1 second is equal to (1<<12) i.e. 4096 units.
so lets say i want it for 2 seconds, i do 4096*2 ?? bu ti want it not to stop

any help??

thank you in advance

Last edited by n0br41ner; 06-18-2012 at 08:41.
n0br41ner is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 06-18-2012 , 11:22   Re: black screen fade function
Reply With Quote #2

Following stocks let you choose time in seconds (and contains formulas if you want to rip code).

http://forums.alliedmods.net/showthread.php?t=87623

UTIL_FadeToBlack( id )
__________________
- tired and retired -

- my plugins -

Last edited by ConnorMcLeod; 06-18-2012 at 11:23.
ConnorMcLeod is offline
n0br41ner
Senior Member
Join Date: May 2012
Location: Planet Earth
Old 06-18-2012 , 15:40   Re: black screen fade function
Reply With Quote #3

I know i can use this, i have already came across it before while searching. But i really want to understand what they do and how to use them (the three write_short() i mean). Plus if i use this, i will have to get the .inc to compile my code, and i want it to be able to compile without any additions.

I tried to check the code inside the .inc, i got a bit lost

Since you used them in the .inc, can you please explain?
Thanks again

EDIT: I have managed to get this far, did i do it correctly?

PHP Code:
public BlackOutSameIPs() {
    
g_iDeadPlayer read_data(2);
    new 
iFadeTime;
    
iFadeTime FixedUnsigned16(flFxTime 1<<12);
    
    if(!
is_user_alive(g_iDeadPlayer) && g_bSameIPs[g_iDeadPlayer]) {
        
message_begin(MSG_ONEg_MsgFade, {0,0,0}, g_iDeadPlayer);
        
write_short(iFadeTime);
        
write_short(FixedUnsigned16(0.0 1<<12));
        
write_short(FFADE_STAYOUT);
        
write_byte(0);
        
write_byte(0);
        
write_byte(0);
        
write_byte(255);
        
message_end();
    } 
    
    
client_print(g_iDeadPlayerprint_center"Your IP was found matching to another player, ^nyour screen is now blacked out.");
}

public 
ResetScreen(iPlayerID) {
    new 
iFadeTime;
    
iFadeTime FixedUnsigned16(flFxTime 1<<12);
    
    if(
is_user_alive(iPlayerID)) {
        
message_begin(MSG_ONEg_MsgFade, {0,0,0}, iPlayerID);
        
write_short(iFadeTime);
        
write_short(FixedUnsigned16(0.0 1<<12));
        
write_short(FFADE_OUT);
        
write_byte(0);
        
write_byte(0);
        
write_byte(0);
        
write_byte(0);
        
message_end();
    }
    
    
client_print(iPlayerIDprint_center"Your screen has been reset.");
}

public 
FixedUnsigned16(Float:flValueiScale)
{
    new 
iOutput;

    
iOutput floatround(flValue iScale);

    if ( 
iOutput )
        
iOutput 0;

    if ( 
iOutput 0xFFFF )
        
iOutput 0xFFFF;

    return 
iOutput;

I have looked the code of your .inc and copied a few things if you don't mind
__________________

Last edited by n0br41ner; 06-18-2012 at 16:06.
n0br41ner is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 06-18-2012 , 16:07   Re: black screen fade function
Reply With Quote #4

This is more correct than your first post, but flags to unfade would more be FFADE_IN and alpha 255 (except if the way you wrote it FFADE_OUT + alpha 0 makes a smooth effect).

If you still don't know why the formula of duration is FixedUnsigned16(seconds , 1<<12),
it's because the value of 1 second is 1<<12 (or 4096), but the argument is a short,
so the max value you can pass as argument is max value of an unsigned short (unisigned16) (65535 or 0xFFFF),
so the max duration you can use is 65535 / 4096 = 15.999 seconds,
if you want more duration you need a workaround like using STAYOUT flag or re-send the message after some time.
__________________
- tired and retired -

- my plugins -

Last edited by ConnorMcLeod; 06-18-2012 at 16:16.
ConnorMcLeod is offline
n0br41ner
Senior Member
Join Date: May 2012
Location: Planet Earth
Old 06-18-2012 , 16:10   Re: black screen fade function
Reply With Quote #5

Now i understood better, thank you a lot
So i will replace FFADE_OUT by FFADE_IN and i am good to go
__________________
n0br41ner is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 06-18-2012 , 16:13   Re: black screen fade function
Reply With Quote #6

May be the way you wrote it works, dunno i haven't tested, or may be it works if you add MODULATE flag.

Also, you can copy/paste the whole .inc in your .sma if you have any doubt.


But for your plugin, you don't need to clamp values because you use STAYOUT flag, you can put write_short(1), write_short(1), write_short( FFLAG_STAYOUT ) and it'll work fine.

Default fade to black effect duration is 3 sec so :

PHP Code:
        message_begin(MSG_ONEg_MsgFade_g_iDeadPlayer);
        
write_short(3<<12);
        
write_short(3<<12);
        
write_short(FFADE_STAYOUT);
        
write_byte(0);
        
write_byte(0);
        
write_byte(0);
        
write_byte(255);
        
message_end();
    
    
        
message_begin(MSG_ONEg_MsgFade_g_iDeadPlayer);
        
write_short(4); // default value passed in the game when screen is reset (0.001 sec)
        
write_short(0);
        
write_short(FFADE_IN);
        
write_byte(0);
        
write_byte(0);
        
write_byte(0);
        
write_byte(0);
        
message_end(); 
You should only need to reset player screen when other player with same ip has deconnected, but take care player could reset their screen using fullupdate command.
__________________
- tired and retired -

- my plugins -

Last edited by ConnorMcLeod; 06-18-2012 at 16:22.
ConnorMcLeod is offline
n0br41ner
Senior Member
Join Date: May 2012
Location: Planet Earth
Old 06-18-2012 , 16:44   Re: black screen fade function
Reply With Quote #7

alright now i ran into another problem, the screen fade worked perfectly but it dissapears when the players press space (to change view mode when he is dead, the screen fade is only applicable when dead btw) the black screen is gone, Also when the player press E (when this small square windows comes up on the top left corner of your screen).
how can i block that?
I want to ask also, if when a player is respawned (after round end for example) does the screen fade goes away by it self?

EDIT: i just noticed your edited response
thank you, and when a player disconnects, it automatically refresh the info (recalculates the players who have the same ip), i can leave it until next round, when he dies he doesnt get blacked out
and how can i also disable the players from resetting the screen by typing fullupdate? you don't have to right the code for me, just lead me in the direction (link to a thread, another plugin maybe that has the same functionality, ...)

I know you might get frustrated from me, but its my first week in coding with amxmodx

EDIT2: just thought of this, maybe i can use this?
register_clcmd("fullupdate", "BlackoutFullupdate"";
and then inside BlackoutFullupdate i check if he one of the sameips and stuff like that?
but still i donno how to block the change view mode thingy

EDIT3: came up with this function, will it work? is it recommended or not?
PHP Code:
public BlackoutFullupdate(iPlayerID) {
    if(!
is_user_alive(iPlayerID) && g_bSameIPs[iPlayerID]) {
        
message_begin(MSG_ONEg_MsgFade, {0,0,0}, iPlayerID);
        
write_short(3<<12);
        
write_short(3<<12);
        
write_short(FFADE_OUT);
        
write_byte(0);
        
write_byte(0);
        
write_byte(0);
        
write_byte(0);
        
message_end();
    }

__________________

Last edited by n0br41ner; 06-18-2012 at 17:15.
n0br41ner is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 06-18-2012 , 17:16   Re: black screen fade function
Reply With Quote #8

You can block message :

PHP Code:
public plugin_init()
{
    
RegisterMessage("ScreenFade""Message_ScreenFade")
}

public 
Message_ScreenFade(iMsgIndex /* gmsgFade */ iMsgDest /* MSG_ONE */ id)
{
    if( 
g_bSameIPs[id] && !is_user_alive(id) )
    {
        return 
PLUGIN_HANDLED
    
}
    return 
PLUGIN_CONTINUE
}

RegisterMessage(const szMsgName[], const szCallBack[])
{
    return 
register_message(get_user_msgid(szMsgName), szCallBack)

Basically, when you use register_message(), when the game sends MESSAGE_BEGIN and the message is flagged as registered, amxx blocks all from MESSAGE_BEGIN to MESSAGE_END, at MESSAGE_END amxx sends you the callback (here Message_ScreenFade) and you can block it or not, and if you don't block it you can change its arguments, a new message is sent if you don't block it.
I'm not sure if the client uses fadetoblack cvar value or another system to know if the screen can be reset, so there should be more efficient ways to achieve what you want, but this method should work.


Also, see in which order i made the checks :

if( g_bSameIPs[id] && !is_user_alive(id) )

It's better to check variables first and to use natives after, so you can save some natives calls.



You should find usefull links on there : http://forums.alliedmods.net/showthread.php?t=172936
One of them : http://wiki.amxmodx.org/Optimizing_P...X_Scripting%29

Also, if you know more in C than in pawn, you should have a look on pawn guide, page 133 : http://www.compuphase.com/pawn/Pawn_Language_Guide.pdf
__________________
- tired and retired -

- my plugins -

Last edited by ConnorMcLeod; 06-18-2012 at 17:19.
ConnorMcLeod is offline
n0br41ner
Senior Member
Join Date: May 2012
Location: Planet Earth
Old 06-18-2012 , 17:48   Re: black screen fade function
Reply With Quote #9

On second thought, the screenfade goes away in like 3 to 5 seconds, i guess ill post the whole code:
I decided simply to use your include, cause i thought i was doing something wrong
PHP Code:
buuurp problem solved 

-------------------------------------------------------------------------------------------
I did not understand this:
PHP Code:
RegisterMessage(const szMsgName[], const szCallBack[])
{
    return 
register_message(get_user_msgid(szMsgName), szCallBack)

EDIT: i think i got it,
so RegisterMessage is a function that you created, and you defined that function here right? cause at first i thought its a native

---------------------------------------------------------------------------------------------
Let me get it straight, this will block the message when the view mode is changed and when client type fullupdate?
excuse me, but it's 6 AM here so im pretty tired, i think imma go to sleep waiting for your answer 2morrow
PHP Code:
public plugin_init()
{
    
RegisterMessage("ScreenFade""Message_ScreenFade")
}

public 
Message_ScreenFade(iMsgIndex /* gmsgFade */ iMsgDest /* MSG_ONE */ id)
{
    if( 
g_bSameIPs[id] && !is_user_alive(id) )
    {
        return 
PLUGIN_HANDLED
    
}
    return 
PLUGIN_CONTINUE
}

RegisterMessage(const szMsgName[], const szCallBack[])
{
    return 
register_message(get_user_msgid(szMsgName), szCallBack)

Again, i am sorry if i am taking from your time
__________________

Last edited by n0br41ner; 06-20-2012 at 13:50.
n0br41ner is offline
n0br41ner
Senior Member
Join Date: May 2012
Location: Planet Earth
Old 06-19-2012 , 21:53   Re: black screen fade function
Reply With Quote #10

Alright now all is good i hope i only have 1 more problem, players are visible when switched to overview mode.
Is there a way to disable overview? or something of that sort?

EDIT: sorry didn't notice my post, should have edited the previous one
__________________

Last edited by n0br41ner; 06-19-2012 at 21:53.
n0br41ner 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 06:05.


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