AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved Hooking ScreenFade (https://forums.alliedmods.net/showthread.php?t=332255)

davidto1995 05-02-2021 03:25

Hooking ScreenFade
 
I tried to hook ScreenFade messages and block some of them.

PHP Code:

register_messageget_user_msgid"ScreenFade" ) , "msgScreenFade" ); // Hook ScreenFade messages 

PHP Code:

public msgScreenFademsg_id msg_dest msg_entity )
{

    new 
boolplayer_blinded boolget_xvar_numXVar_IsAllHumanBlind );

    
client_printprint_chat "player_blinded: %i" player_blinded );

    if( 
player_blinded )
    {

        return 
PLUGIN_HANDLED;

    }
    else
    {

        return 
PLUGIN_CONTINUE;

    }



PHP Code:

stock fade_user_screen(idFloat:duration 1.0Float:fadetime 1.0ScreenFadeFlags:flags ScreenFade_FadeIn0025575bool:reliable true)
{
    if(
id && !is_user_connected(id))
        return 
0;

    static 
MSG_ScreenFade;

    if(!
MSG_ScreenFade)
        
MSG_ScreenFade get_user_msgid("ScreenFade");

    
message_begin(get_msg_destination(idreliable), MSG_ScreenFade, .player id);
    
write_short(float_to_short(fadetime));
    
write_short(float_to_short(duration));
    
write_short(_:flags);
    
write_byte(r);
    
write_byte(g);
    
write_byte(b);
    
write_byte(a);
    
message_end();

    return 
1;


However, except at the time when a player spawned ( client_print() called ), the ScreenFade message is not hooked at any time during the game ( no client_print() called ).

Black Rose 05-02-2021 07:47

Re: Hooking ScreenFade
 
If you're trying to hook screenfade sent by other plugins they need to send it using emessage_*()/ewrite_*() natives.

Code:
/* These are the same as above, except that the messages sent  *  are also sent to all other plugins and Metamod plugins.  * This means that if you send one of these messages, other plugins will  *  be notified, which was previously impossible.    * BE CAREFUL! Using these incorrectly, or not for their intended purpose,  *  could cause infinite recursion or something just as bad.  * NOTE! These natives are experimental.  */ native emessage_begin(dest, msg_type, const origin[3] = {0,0,0}, player = 0); native emessage_end(); native ewrite_byte(x); native ewrite_char(x); native ewrite_short(x); native ewrite_long(x); native ewrite_entity(x); native ewrite_angle(x); native ewrite_coord(x); native ewrite_string(const x[]);

davidto1995 05-05-2021 19:10

Re: Hooking ScreenFade
 
Thanks it is solved.


All times are GMT -4. The time now is 02:38.

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