Advertisement
Hasky

ColorChat.inc

Jan 19th, 2013
956
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.05 KB | None | 0 0
  1.  
  2. #if defined _colorchat_included
  3.   #endinput
  4. #endif
  5. #define _colorchat_included
  6.  
  7. enum Color
  8. {
  9.     NORMAL = 1, // clients scr_concolor cvar color
  10.     GREEN, // Green Color
  11.     TEAM_COLOR, // Red, grey, blue
  12.     GREY, // grey
  13.     RED, // Red
  14.     BLUE, // Blue
  15. }
  16.  
  17. new const TeamName[][] =
  18. {
  19.     "",
  20.     "TERRORIST",
  21.     "CT",
  22.     "SPECTATOR"
  23. }
  24.  
  25. ColorChat(id, Color:type, const msg[], any:...)
  26. {
  27.     new message[256];
  28.  
  29.     switch(type)
  30.     {
  31.         case NORMAL: // clients scr_concolor cvar color
  32.         {
  33.             message[0] = 0x01;
  34.         }
  35.         case GREEN: // Green
  36.         {
  37.             message[0] = 0x04;
  38.         }
  39.         default: // White, Red, Blue
  40.         {
  41.             message[0] = 0x03;
  42.         }
  43.     }
  44.  
  45.     vformat(message[1], 251, msg, 4);
  46.  
  47.     // Make sure message is not longer than 192 character. Will crash the server.
  48.     message[192] = '^0';
  49.  
  50.     new team, ColorChange, index, MSG_Type;
  51.    
  52.     if(id)
  53.     {
  54.         MSG_Type = MSG_ONE_UNRELIABLE;
  55.         index = id;
  56.     } else {
  57.         index = FindPlayer();
  58.         MSG_Type = MSG_BROADCAST;
  59.     }
  60.    
  61.     team = get_user_team(index);
  62.     ColorChange = ColorSelection(index, MSG_Type, type);
  63.  
  64.     ShowColorMessage(index, MSG_Type, message);
  65.        
  66.     if(ColorChange)
  67.     {
  68.         Team_Info(index, MSG_Type, TeamName[team]);
  69.     }
  70. }
  71.  
  72. ShowColorMessage(id, type, message[])
  73. {
  74.     static msgSayText;
  75.     if(!msgSayText)
  76.     {
  77.         msgSayText = get_user_msgid("SayText");
  78.     }
  79.     message_begin(type, msgSayText, _, id);
  80.     write_byte(id)     
  81.     write_string(message);
  82.     message_end(); 
  83. }
  84.  
  85. Team_Info(id, type, team[])
  86. {
  87.     static msgTeamInfo;
  88.     if(!msgTeamInfo)
  89.     {
  90.         msgTeamInfo = get_user_msgid("TeamInfo");
  91.     }
  92.     message_begin(type, msgTeamInfo, _, id);
  93.     write_byte(id);
  94.     write_string(team);
  95.     message_end();
  96.  
  97.     return 1;
  98. }
  99.  
  100. ColorSelection(index, type, Color:Type)
  101. {
  102.     switch(Type)
  103.     {
  104.         case RED:
  105.         {
  106.             return Team_Info(index, type, TeamName[1]);
  107.         }
  108.         case BLUE:
  109.         {
  110.             return Team_Info(index, type, TeamName[2]);
  111.         }
  112.         case GREY:
  113.         {
  114.             return Team_Info(index, type, TeamName[0]);
  115.         }
  116.     }
  117.  
  118.     return 0;
  119. }
  120.  
  121. FindPlayer()
  122. {
  123.     new i = -1;
  124.  
  125.     while(i <= get_maxplayers())
  126.     {
  127.         if(is_user_connected(++i))
  128.             return i;
  129.     }
  130.  
  131.     return -1;
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement