SHARE
TWEET

Chat Prefix za Savu

milutinke May 19th, 2020 1,124 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include < amxmodx >
  2.  
  3. #define IsValidPlayer(%0)   ( 1 <= %0 <= g_iMaxPlayers )
  4.  
  5. new g_bConnected[ 33 ] = false;
  6. new g_iTeam[ 33 ];
  7. new g_szName[ 33 ][ 32 ];
  8. new bool: g_bHasPrefix[ 33 ] = false;
  9.  
  10. new g_iMessageChat;
  11. new g_iMaxPlayers;
  12.  
  13. public plugin_init( ) {
  14.     register_plugin( "VIP: Chat Prefix for user info", "1.0", "Milutinke (ByM)" );
  15.    
  16.     register_event( "TeamInfo", "fw_EventTeamInfo", "a" );
  17.    
  18.     register_clcmd( "say", "fw_ChatPrefix" );
  19.     register_clcmd( "say_team", "fw_ChatPrefixTeam" );
  20.    
  21.     g_iMessageChat = get_user_msgid( "SayText" );
  22.     g_iMaxPlayers = get_maxplayers( );
  23. }
  24.  
  25. public client_connect( iPlayer ) {
  26.     g_bHasPrefix[ iPlayer ] = false;
  27.     g_bConnected[ iPlayer ] = false;
  28.     g_iTeam[ iPlayer ] = 0;
  29. }
  30.  
  31. public client_putinserver( iPlayer )
  32.     g_bConnected[ iPlayer ] = true;
  33.  
  34. public client_authorized( iPlayer ) {
  35.     get_user_name( iPlayer, g_szName[ iPlayer ], charsmax( g_szName[ ] ) );
  36.    
  37.     new szInfo[ 32 ];
  38.     if( get_user_info( iPlayer, "vip", szInfo, charsmax( szInfo ) ) ) {
  39.         trim( szInfo );
  40.        
  41.         if( szInfo[ 0 ] == EOS )
  42.             return;
  43.            
  44.         g_bHasPrefix[ iPlayer ] = bool: equal( szInfo, "1" );
  45.     }
  46. }
  47.  
  48. public client_disconnect( iPlayer ) {
  49.     g_szName[ iPlayer ][ 0 ] = EOS;
  50.     g_bHasPrefix[ iPlayer ] = false;
  51.     g_bConnected[ iPlayer ] = false;
  52.     g_iTeam[ iPlayer ] = 0;
  53. }
  54.  
  55. public client_infochanged( iPlayer ) {
  56.     new szName[ 32 ];
  57.     get_user_name( iPlayer, szName, charsmax( szName ) );
  58.    
  59.     if( !equal( g_szName[ iPlayer ], szName ) )
  60.         copy( g_szName[ iPlayer ], charsmax( g_szName[ ] ), szName );
  61. }
  62.  
  63. public fw_EventTeamInfo( ) {
  64.     new iPlayer = read_data( 1 );
  65.    
  66.     if( !g_bConnected[ iPlayer ] )
  67.         return PLUGIN_CONTINUE;
  68.    
  69.     new szTeam[ 12 ];
  70.     read_data( 2, szTeam, charsmax( szTeam ) );
  71.    
  72.     switch( szTeam[ 0 ] ) {
  73.         case 'T' :  g_iTeam[ iPlayer ] = 1;
  74.         case 'C' :  g_iTeam[ iPlayer ] = 2;
  75.         case 'S' :  g_iTeam[ iPlayer ] = 3;
  76.         default: g_iTeam[ iPlayer ] = 4;
  77.     }
  78.    
  79.     return PLUGIN_CONTINUE;
  80. }
  81.  
  82. public fw_ChatPrefix( iPlayer ) {
  83.     if( !g_bConnected[ iPlayer ] || !IsValidPlayer( iPlayer ) )
  84.         return 2;
  85.        
  86.     static szSaid[ 191 ];
  87.     read_args( szSaid, charsmax( szSaid ) );
  88.     remove_quotes( szSaid );
  89.    
  90.     return ChatPrefix( iPlayer, szSaid, charsmax( szSaid ), false );
  91. }
  92.  
  93. public fw_ChatPrefixTeam( iPlayer ) {
  94.     if( !g_bConnected[ iPlayer ] || !IsValidPlayer( iPlayer ) )
  95.         return 2;
  96.        
  97.     static szSaid[ 191 ];
  98.     read_args( szSaid, charsmax( szSaid ) );
  99.     remove_quotes( szSaid );
  100.    
  101.     return ChatPrefix( iPlayer, szSaid, charsmax( szSaid ), true );
  102. }
  103.  
  104. public ChatPrefix( const iPlayer, szSaid[ ], const iSaidLength, const bTeamChat ) {
  105.     static szMessage[ 191 ], iPlayers;
  106.  
  107.     if( !szSaid[ 0 ] )
  108.         return 2;
  109.    
  110.     formatex( szMessage, charsmax( szMessage ), "%s!t%s: !n%s", g_bHasPrefix[ iPlayer ] ? "!g[VIP] " : "", g_szName[ iPlayer ], szSaid );
  111.     replace_all( szMessage, charsmax( szMessage ), "%", "" );
  112.     replace_all( szMessage, charsmax( szMessage ), "!n", "^x01" );
  113.     replace_all( szMessage, charsmax( szMessage ), "!r", "^x02" );
  114.     replace_all( szMessage, charsmax( szMessage ), "!g", "^x04" );
  115.     replace_all( szMessage, charsmax( szMessage ), "!t", "^x03" );
  116.     trim( szMessage );
  117.    
  118.     for( iPlayers = 1; iPlayers <= g_iMaxPlayers; iPlayers ++ ) {
  119.         if( !g_bConnected[ iPlayer ] )
  120.             continue;
  121.        
  122.         if( bTeamChat ) {
  123.             if( get_user_team( iPlayer ) != get_user_team( iPlayers ) )
  124.                 continue;
  125.         }
  126.        
  127.         message_begin( MSG_ONE, g_iMessageChat, { 0, 0, 0 }, iPlayers );
  128.         write_byte( iPlayer );
  129.         write_string( szMessage );
  130.         message_end( );
  131.     }
  132.    
  133.     return 2;
  134. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top