laurentiuarion

Rank Admin Chat

Feb 11th, 2020
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 6.20 KB | None | 0 0
  1. #include <amxmodx>
  2.  
  3. #pragma semicolon 1
  4.  
  5. enum Color {
  6.     NORMAL = 1, GREEN, TEAM_COLOR,  GREY, RED, BLUE,
  7. };
  8.  
  9. new TeamName[][] =  {
  10.     "", "TERRORIST", "CT", "SPECTATOR"
  11. };
  12.  
  13. // start cstrike.inc
  14. enum CsTeams {
  15.     CS_TEAM_UNASSIGNED = 0,
  16.     CS_TEAM_T = 1,
  17.     CS_TEAM_CT = 2,
  18.     CS_TEAM_SPECTATOR = 3
  19. };
  20.  
  21. native CsTeams:cs_get_user_team(index);
  22. // end cstrike.inc
  23.  
  24. // edit here
  25.  
  26. #define MAX_GROUPS 2
  27.  
  28. new g_Rang[MAX_GROUPS][] = {
  29.     "Detinator",
  30.     "Admin"
  31. };
  32.  
  33. new g_RangFlag[MAX_GROUPS][] = {
  34.     "abcdefghijklmnopqrstu",
  35.     "bcdefijkmno"
  36. };
  37.  
  38. // end edit here
  39.  
  40. new g_RangFlag_Value[MAX_GROUPS];
  41. new cvar_type, gType[2][50];
  42.  
  43. public plugin_init() {
  44.     register_plugin("RangAdminChat", "0.7", "Ex3cuTioN aka Arion HD.");
  45.    
  46.     register_clcmd("say","hook_say");
  47.     register_clcmd("say_team","hook_say2");
  48.    
  49.     for(new i = 0; i < MAX_GROUPS; i++)
  50.         g_RangFlag_Value[i] = read_flags(g_Rang[i]);
  51.    
  52.     cvar_type = register_cvar("amx_rang_chat","3");
  53.    
  54.     switch(get_pcvar_num(cvar_type)) {
  55.         case 1 : {
  56.             gType[0] = "^x04*%s*^x03%s^x01 : %s";
  57.             gType[1] = "^x04*%s*^x01(%s)^x03 %s^x01 : %s";
  58.         }
  59.         case 2 : {
  60.             gType[0] = "^x04(%s)^x03%s^x01 : %s";
  61.             gType[1] = "^x04(%s)^x01(%s)^x03 %s^x01 : %s";
  62.         }
  63.         case 3 : {
  64.             gType[0] = "^x04[%s]^x03 %s^x01 : %s";
  65.             gType[1] = "^x04[%s]^x01(%s)^x03 %s^x01 : %s";
  66.         }
  67.     }
  68. }
  69.  
  70. public hook_say(id) {
  71.     if(is_user_bot(id))
  72.         return PLUGIN_CONTINUE;
  73.    
  74.     static chat[192];
  75.     read_args(chat, sizeof(chat) - 1);
  76.     remove_quotes(chat);
  77.    
  78.     if(equali(chat,""))
  79.         return PLUGIN_CONTINUE;
  80.    
  81.     if(is_user_admin(id)) {
  82.         new bool:hasRang = false;
  83.         for(new i = 0; i < MAX_GROUPS; i++) {
  84.             if(get_user_flags(id) == read_flags(g_RangFlag[i]))  {
  85.                 switch(cs_get_user_team(id)) {
  86.                     case CS_TEAM_T : ColorChat(0, RED, gType[0],  g_Rang[i], get_name(id), chat);
  87.                     case CS_TEAM_CT : ColorChat(0, BLUE, gType[0], g_Rang[i], get_name(id), chat);
  88.                     case CS_TEAM_SPECTATOR : ColorChat(0, GREY, gType[0], g_Rang[i], get_name(id), chat);
  89.                 }
  90.                 hasRang = true;
  91.             }
  92.         }
  93.         if(!hasRang)
  94.             get_team(id, chat);
  95.     }
  96.     else
  97.         get_team(id, chat);
  98.    
  99.     return PLUGIN_HANDLED;
  100. }
  101.  
  102. stock get_team(id, chat[]) {
  103.     switch(cs_get_user_team(id)) {
  104.         case CS_TEAM_T : ColorChat(0, RED, "%s%s^x01 : %s", is_user_alive(id) ? "" : "*DEAD*",  get_name(id), chat);
  105.         case CS_TEAM_CT : ColorChat(0, BLUE, "%s%s^x01 : %s", is_user_alive(id) ? "" : "*DEAD*",  get_name(id), chat);
  106.         case CS_TEAM_SPECTATOR : ColorChat(0, GREY, "*SPEC*%s^x01 : %s",  get_name(id), chat);
  107.     }
  108. }
  109.  
  110. public hook_say2(id) {
  111.     if(is_user_bot(id))
  112.         return PLUGIN_CONTINUE;
  113.    
  114.     static chat[192];
  115.     read_args(chat, sizeof(chat) - 1);
  116.     remove_quotes(chat);
  117.    
  118.     if(equali(chat,""))
  119.         return PLUGIN_CONTINUE;
  120.    
  121.     new players[32], num;
  122.     get_players(players, num, "c");
  123.                
  124.     if(is_user_admin(id)) {
  125.         new bool:hasRang = false;
  126.         for(new i = 0; i < MAX_GROUPS; i++) {
  127.             if(get_user_flags(id) == read_flags(g_RangFlag[i])) {
  128.                 for(new x = 0; x < num; x++) {
  129.                     if(get_user_team(players[x]) == get_user_team(id)) {
  130.                         switch(cs_get_user_team(id)) {
  131.                             case CS_TEAM_T : ColorChat(players[x], RED, gType[1], g_Rang[i], "Terrorist", get_name(id), chat);
  132.                             case CS_TEAM_CT : ColorChat(players[x], BLUE, gType[1], g_Rang[i], "Counter-Terrorist",  get_name(id), chat);
  133.                             case CS_TEAM_SPECTATOR : ColorChat(players[x], GREY, gType[1], g_Rang[i], "Spectator", get_name(id), chat);
  134.                         }
  135.                     }
  136.                 }
  137.                 hasRang = true;
  138.             }
  139.         }
  140.         if(!hasRang)
  141.             get_team2(id, num, players, chat);
  142.     }
  143.     else
  144.         get_team2(id, num, players,  chat);
  145.        
  146.     return PLUGIN_HANDLED;
  147. }
  148.  
  149. stock get_team2(id, num, players[],  chat[]) {
  150.     for(new x = 0; x < num; x++) {
  151.         if(get_user_team(players[x]) == get_user_team(id)) {
  152.             switch(cs_get_user_team(id)) {
  153.                 case CS_TEAM_T : ColorChat(players[x], RED, "^x01(Terrorist)^x03 %s^x01 : %s", get_name(id), chat);
  154.                 case CS_TEAM_CT : ColorChat(players[x], BLUE, "^x01(Counter-Terrorist)^x03 %s^x01 : %s", get_name(id), chat);
  155.                 case CS_TEAM_SPECTATOR : ColorChat(players[x], GREY, "^x01(Spectator)^x03 %s^x01 : %s", get_name(id), chat);
  156.             }
  157.         }
  158.     }
  159. }
  160.  
  161. ColorChat(id, Color:type, const msg[], {Float,Sql,Result,_}:...) {
  162.     new message[256];
  163.  
  164.     switch(type) {
  165.         case NORMAL: // clients scr_concolor cvar color
  166.         {
  167.             message[0] = 0x01;
  168.         }
  169.         case GREEN: // Green
  170.         {
  171.             message[0] = 0x04;
  172.         }
  173.         default: // White, Red, Blue
  174.         {
  175.             message[0] = 0x03;
  176.         }
  177.     }
  178.  
  179.     vformat(message[1], 251, msg, 4);
  180.  
  181.     // Make sure message is not longer than 192 character. Will crash the server.
  182.     message[192] = '^0';
  183.  
  184.     new team, ColorChange, index, MSG_Type;
  185.    
  186.     if(id) {
  187.         MSG_Type = MSG_ONE;
  188.         index = id;
  189.     } else {
  190.         index = FindPlayer();
  191.         MSG_Type = MSG_ALL;
  192.     }
  193.    
  194.     team = get_user_team(index);
  195.     ColorChange = ColorSelection(index, MSG_Type, type);
  196.  
  197.     ShowColorMessage(index, MSG_Type, message);
  198.        
  199.     if(ColorChange) {
  200.         Team_Info(index, MSG_Type, TeamName[team]);
  201.     }
  202. }
  203.  
  204. ShowColorMessage(id, type, message[]) {
  205.     static bool:saytext_used;
  206.     static get_user_msgid_saytext;
  207.     if(!saytext_used)
  208.     {
  209.         get_user_msgid_saytext = get_user_msgid("SayText");
  210.         saytext_used = true;
  211.     }
  212.     message_begin(type, get_user_msgid_saytext, _, id);
  213.     write_byte(id);
  214.     write_string(message);
  215.     message_end()
  216. }
  217.  
  218. Team_Info(id, type, team[]) {
  219.     static bool:teaminfo_used;
  220.     static get_user_msgid_teaminfo;
  221.    
  222.     if(!teaminfo_used) {
  223.         get_user_msgid_teaminfo = get_user_msgid("TeamInfo");
  224.         teaminfo_used = true;
  225.     }
  226.     message_begin(type, get_user_msgid_teaminfo, _, id);
  227.     write_byte(id);
  228.     write_string(team);
  229.     message_end();
  230.  
  231.     return 1;
  232. }
  233.  
  234. ColorSelection(index, type, Color:Type) {
  235.     switch(Type) {
  236.         case RED:
  237.         {
  238.             return Team_Info(index, type, TeamName[1]);
  239.         }
  240.         case BLUE:
  241.         {
  242.             return Team_Info(index, type, TeamName[2]);
  243.         }
  244.         case GREY:
  245.         {
  246.             return Team_Info(index, type, TeamName[0]);
  247.         }
  248.     }
  249.  
  250.     return 0;
  251. }
  252.  
  253. FindPlayer() {
  254.     new i = -1;
  255.  
  256.     while(i <= get_maxplayers()) {
  257.         if(is_user_connected(++i))
  258.             return i;
  259.     }
  260.  
  261.     return -1;
  262. }
  263.  
  264. stock get_name (id) {
  265.     new name[32];
  266.     get_user_name(id, name, 31);
  267.     return name;
  268. }
  269.  
  270. // start amxmisc.inc
  271. stock is_user_admin(id) {
  272.     new __flags=get_user_flags(id);
  273.     return (__flags>0 && !(__flags&ADMIN_USER));
  274. }
  275. // end amxmisc.inc
Add Comment
Please, Sign In to add comment