View Single Post
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 11-02-2019 , 17:06   Re: client_infochanged Efficiency
Reply With Quote #12

OciXCrom's suggestion worked for me, adding the 1 to the unregister_forward() makes it only fire once. I also made an efficiency fix.
  • Using register_event() on only 2=#Cstrike_Name_Change, instead of hooking all SayText messages and then checking the 2nd arg within the callback.
  • unregister_message() post fix
Code:
*TEST* Name changed to [bugsy]
* bugsy3 changed name to bugsy
*TEST* Name changed to [bugsy2]
* bugsy changed name to bugsy2
PHP Code:
#include <amxmodx>
#include <fakemeta>

new const Version[] = "0.2";

#define MAX_PLAYERS 32

new g_szNameMAX_PLAYERS ][ 32 ];
new 
g_iInfoChangedFwd;

public 
plugin_init() 
{
    
register_plugin"Name Change Hook" Version "bugsy" );
    
    
register_event"SayText" "EventSayText" "a" "2=#Cstrike_Name_Change" );
}

public 
EventSayText()
{
    
g_iInfoChangedFwd register_forwardFM_ClientUserInfoChanged "ClientUserInfoChanged" );
}

public 
ClientUserInfoChangedid )
{
    if ( 
is_user_connectedid ) )
    {
        
get_user_nameid g_szNameid ] , charsmaxg_szName[] ) );
        
unregister_forwardFM_ClientUserInfoChanged g_iInfoChangedFwd );
        
client_printid print_chat "*TEST* Name changed to [%s]" g_szNameid ] );
    }

__________________

Last edited by Bugsy; 11-02-2019 at 17:07.
Bugsy is offline