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_szName[ MAX_PLAYERS + 1 ][ 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_forward( FM_ClientUserInfoChanged , "ClientUserInfoChanged" , 1 );
}
public ClientUserInfoChanged( id )
{
if ( is_user_connected( id ) )
{
get_user_name( id , g_szName[ id ] , charsmax( g_szName[] ) );
unregister_forward( FM_ClientUserInfoChanged , g_iInfoChangedFwd , 1 );
client_print( id , print_chat , "*TEST* Name changed to [%s]" , g_szName[ id ] );
}
}
__________________