P1xeL

Admin Chat By "AMXX Dev Team"

Dec 14th, 2012
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 11.32 KB | None | 0 0
  1. /* AMX Mod X
  2. *   Admin Chat Plugin
  3. *
  4. * by the AMX Mod X Development Team
  5. *  originally developed by OLO
  6. *
  7. * This file is part of AMX Mod X.
  8. *
  9. *
  10. *  This program is free software; you can redistribute it and/or modify it
  11. *  under the terms of the GNU General Public License as published by the
  12. *  Free Software Foundation; either version 2 of the License, or (at
  13. *  your option) any later version.
  14. *
  15. *  This program is distributed in the hope that it will be useful, but
  16. *  WITHOUT ANY WARRANTY; without even the implied warranty of
  17. *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. *  General Public License for more details.
  19. *
  20. *  You should have received a copy of the GNU General Public License
  21. *  along with this program; if not, write to the Free Software Foundation,
  22. *  Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  23. *
  24. *  In addition, as a special exception, the author gives permission to
  25. *  link the code of this program with the Half-Life Game Engine ("HL
  26. *  Engine") and Modified Game Libraries ("MODs") developed by Valve,
  27. *  L.L.C ("Valve"). You must obey the GNU General Public License in all
  28. *  respects for all of the code used other than the HL Engine and MODs
  29. *  from Valve. If you modify this file, you may extend this exception
  30. *  to your version of the file, but you are not obligated to do so. If
  31. *  you do not wish to do so, delete this exception statement from your
  32. *  version.
  33. */
  34.  
  35. #include <amxmodx>
  36. #include <amxmisc>
  37.  
  38. new g_msgChannel
  39.  
  40. #define MAX_CLR 10
  41.  
  42. new g_Colors[MAX_CLR][] = {"COL_WHITE", "COL_RED", "COL_GREEN", "COL_BLUE", "COL_YELLOW", "COL_MAGENTA", "COL_CYAN", "COL_ORANGE", "COL_OCEAN", "COL_MAROON"}
  43. new g_Values[MAX_CLR][] = {{255, 255, 255}, {255, 0, 0}, {0, 255, 0}, {0, 0, 255}, {255, 255, 0}, {255, 0, 255}, {0, 255, 255}, {227, 96, 8}, {45, 89, 116}, {103, 44, 38}}
  44. new Float:g_Pos[4][] = {{0.0, 0.0}, {0.05, 0.55}, {-1.0, 0.2}, {-1.0, 0.7}}
  45.  
  46. new amx_show_activity;
  47. new g_AdminChatFlag = ADMIN_CHAT;
  48.  
  49. public plugin_init()
  50. {
  51.     new admin_chat_id
  52.  
  53.     register_plugin("Admin Chat", AMXX_VERSION_STR, "AMXX Dev Team")
  54.     register_dictionary("adminchat.txt")
  55.     register_dictionary("common.txt")
  56.     register_clcmd("say", "cmdSayChat", ADMIN_CHAT, "![!|!|!][w|r|g|b|y|m|c]<text> - displays hud message")
  57.     register_clcmd("say_team", "cmdSayAdmin", 0, "!<text> - displays message to admins")
  58.     register_concmd("amx_say", "cmdSay", ADMIN_CHAT, "<message> - sends message to all players")
  59.     admin_chat_id = register_concmd("amx_chat", "cmdChat", ADMIN_CHAT, "<message> - sends message to admins")
  60.     register_concmd("amx_psay", "cmdPsay", ADMIN_CHAT, "<name or #userid> <message> - sends private message")
  61.     register_concmd("amx_tsay", "cmdTsay", ADMIN_CHAT, "<color> <message> - sends left side hud message to all players")
  62.     register_concmd("amx_csay", "cmdTsay", ADMIN_CHAT, "<color> <message> - sends center hud message to all players")
  63.    
  64.     amx_show_activity = get_cvar_pointer("amx_show_activity");
  65.    
  66.     if (amx_show_activity == 0)
  67.     {
  68.         amx_show_activity = register_cvar("amx_show_activity", "2");
  69.     }
  70.  
  71.     new str[1]
  72.     get_concmd(admin_chat_id, str, 0, g_AdminChatFlag, str, 0, -1)
  73. }
  74.  
  75. public cmdSayChat(id)
  76. {
  77.     if (!access(id, g_AdminChatFlag))
  78.     {
  79.         return PLUGIN_CONTINUE
  80.     }
  81.    
  82.     new said[6], i = 0
  83.     read_argv(1, said, 5)
  84.    
  85.     while (said[i] == '!')
  86.     {
  87.         i++
  88.     }
  89.    
  90.     if (!i || i > 3)
  91.     {
  92.         return PLUGIN_CONTINUE
  93.     }
  94.    
  95.     new message[192], a = 0
  96.     read_args(message, 191)
  97.     remove_quotes(message)
  98.    
  99.     switch (said[i])
  100.     {
  101.         case 'r': a = 1
  102.         case 'g': a = 2
  103.         case 'b': a = 3
  104.         case 'y': a = 4
  105.         case 'm': a = 5
  106.         case 'c': a = 6
  107.         case 'o': a = 7
  108.     }
  109.    
  110.     new n, s = i
  111.     if (a)
  112.     {
  113.         n++
  114.         s++
  115.     }
  116.     while (said[s] && isspace(said[s]))
  117.     {
  118.         n++
  119.         s++
  120.     }
  121.    
  122.  
  123.     new name[32], authid[32], userid
  124.    
  125.     get_user_authid(id, authid, 31)
  126.     get_user_name(id, name, 31)
  127.     userid = get_user_userid(id)
  128.    
  129.     log_amx("Chat: ^"%s<%d><%s><>^" tsay ^"%s^"", name, userid, authid, message[i + n])
  130.     log_message("^"%s<%d><%s><>^" triggered ^"amx_tsay^" (text ^"%s^") (color ^"%L^")", name, userid, authid, message[i + n], "en", g_Colors[a])
  131.    
  132.     if (++g_msgChannel > 6 || g_msgChannel < 3)
  133.     {
  134.         g_msgChannel = 3
  135.     }
  136.    
  137.     new Float:verpos = g_Pos[i][1] + float(g_msgChannel) / 35.0
  138.    
  139.     set_hudmessage(g_Values[a][0], g_Values[a][1], g_Values[a][2], g_Pos[i][0], verpos, 0, 6.0, 6.0, 0.5, 0.15, -1)
  140.  
  141.     switch ( get_pcvar_num(amx_show_activity) )
  142.     {
  143.         case 3, 4:
  144.         {
  145.             new maxpl = get_maxplayers();
  146.             for (new pl = 1; pl <= maxpl; pl++)
  147.             {
  148.                 if (is_user_connected(pl) && !is_user_bot(pl))
  149.                 {
  150.                     if (is_user_admin(pl))
  151.                     {
  152.                         show_hudmessage(pl, "%s :   %s", name, message[i + n])
  153.                         client_print(pl, print_notify, "%s :   %s", name, message[i + n])
  154.                     }
  155.                     else
  156.                     {
  157.                         show_hudmessage(pl, "%s", message[i + n])
  158.                         client_print(pl, print_notify, "%s", message[i + n])
  159.                     }
  160.                 }
  161.             }
  162.         }
  163.         case 2:
  164.         {
  165.             client_print(0, print_chat, "%s :   %s", name, message[i + n])
  166.             show_hudmessage(0, "%s :   %s", name, message[i + n])
  167.             client_print(0, print_notify, "%s :   %s", name, message[i + n])
  168.         }
  169.         default:
  170.         {
  171.             show_hudmessage(0, "%s", message[i + n])
  172.             client_print(0, print_notify, "%s", message[i + n])
  173.         }
  174.     }
  175.  
  176.     return PLUGIN_HANDLED
  177. }
  178.  
  179. public cmdSayAdmin(id)
  180. {
  181.     new said[2]
  182.     read_argv(1, said, 1)
  183.    
  184.     if (said[0] != '!')
  185.         return PLUGIN_CONTINUE
  186.    
  187.     new message[192], name[32], authid[32], userid
  188.     new players[32], inum
  189.    
  190.     read_args(message, 191)
  191.     remove_quotes(message)
  192.     get_user_authid(id, authid, 31)
  193.     get_user_name(id, name, 31)
  194.     userid = get_user_userid(id)
  195.    
  196.     log_amx("Chat: ^"%s<%d><%s><>^" chat ^"%s^"", name, userid, authid, message[1])
  197.     log_message("^"%s<%d><%s><>^" triggered ^"amx_chat^" (text ^"%s^")", name, userid, authid, message[1])
  198.    
  199.     if (is_user_admin(id))
  200.         format(message, 191, "(%L) %s :  %s", id, "ADMIN", name, message[1])
  201.     else
  202.         format(message, 191, "(%L) %s :  %s", id, "PLAYER", name, message[1])
  203.  
  204.     get_players(players, inum)
  205.    
  206.     for (new i = 0; i < inum; ++i)
  207.     {
  208.         // dont print the message to the client that used the cmd if he has ADMIN_CHAT to avoid double printing
  209.         if (players[i] != id && get_user_flags(players[i]) & g_AdminChatFlag)
  210.             client_print(players[i], print_chat, "%s", message)
  211.     }
  212.    
  213.     client_print(id, print_chat, "%s", message)
  214.    
  215.     return PLUGIN_HANDLED
  216. }
  217.  
  218. public cmdChat(id, level, cid)
  219. {
  220.     if (!cmd_access(id, level, cid, 2))
  221.         return PLUGIN_HANDLED
  222.  
  223.     new message[192], name[32], players[32], inum, authid[32], userid
  224.    
  225.     read_args(message, 191)
  226.     remove_quotes(message)
  227.     get_user_authid(id, authid, 31)
  228.     get_user_name(id, name, 31)
  229.     userid = get_user_userid(id)
  230.     get_players(players, inum)
  231.    
  232.     log_amx("Chat: ^"%s<%d><%s><>^" chat ^"%s^"", name, userid, authid, message)
  233.     log_message("^"%s<%d><%s><>^" triggered ^"amx_chat^" (text ^"%s^")", name, userid, authid, message)
  234.    
  235.     format(message, 191, "(ADMINS) %s :   %s", name, message)
  236.     console_print(id, "%s", message)
  237.    
  238.     for (new i = 0; i < inum; ++i)
  239.     {
  240.         if (access(players[i], g_AdminChatFlag))
  241.             client_print(players[i], print_chat, "%s", message)
  242.     }
  243.    
  244.     return PLUGIN_HANDLED
  245. }
  246.  
  247. public cmdSay(id, level, cid)
  248. {
  249.     if (!cmd_access(id, level, cid, 2))
  250.         return PLUGIN_HANDLED
  251.  
  252.     new message[192], name[32], authid[32], userid
  253.    
  254.     read_args(message, 191)
  255.     remove_quotes(message)
  256.     get_user_authid(id, authid, 31)
  257.     get_user_name(id, name, 31)
  258.     userid = get_user_userid(id)
  259.     client_print(0, print_chat, "%L", LANG_PLAYER, "PRINT_ALL", name, message)
  260.     console_print(id, "%L", LANG_PLAYER, "PRINT_ALL", name, message)
  261.    
  262.     log_amx("Chat: ^"%s<%d><%s><>^" say ^"%s^"", name, userid, authid, message)
  263.     log_message("^"%s<%d><%s><>^" triggered ^"amx_say^" (text ^"%s^")", name, userid, authid, message)
  264.    
  265.     return PLUGIN_HANDLED
  266. }
  267.  
  268. public cmdPsay(id, level, cid)
  269. {
  270.     if (!cmd_access(id, level, cid, 3))
  271.         return PLUGIN_HANDLED
  272.    
  273.     new name[32]
  274.     read_argv(1, name, 31)
  275.     new priv = cmd_target(id, name, 0)
  276.  
  277.     if (!priv)
  278.         return PLUGIN_HANDLED
  279.    
  280.     new length = strlen(name) + 1
  281.  
  282.     get_user_name(priv, name, 31);
  283.    
  284.     new message[192], name2[32], authid[32], authid2[32], userid, userid2
  285.    
  286.     get_user_authid(id, authid, 31)
  287.     get_user_name(id, name2, 31)
  288.     userid = get_user_userid(id)
  289.     read_args(message, 191)
  290.    
  291.     if (message[0] == '"' && message[length] == '"') // HLSW fix
  292.     {
  293.         message[0] = ' '
  294.         message[length] = ' '
  295.         length += 2
  296.     }
  297.    
  298.     remove_quotes(message[length])
  299.     get_user_name(priv, name, 31)
  300.    
  301.     if (id && id != priv)
  302.         client_print(id, print_chat, "(%s) %s :   %s", name, name2, message[length])
  303.    
  304.     client_print(priv, print_chat, "(%s) %s :   %s", name, name2, message[length])
  305.     console_print(id, "(%s) %s :   %s", name, name2, message[length])
  306.     get_user_authid(priv, authid2, 31)
  307.     userid2 = get_user_userid(priv)
  308.    
  309.     log_amx("Chat: ^"%s<%d><%s><>^" psay ^"%s<%d><%s><>^" ^"%s^"", name2, userid, authid, name, userid2, authid2, message[length])
  310.     log_message("^"%s<%d><%s><>^" triggered ^"amx_psay^" against ^"%s<%d><%s><>^" (text ^"%s^")", name2, userid, authid, name, userid2, authid2, message[length])
  311.    
  312.     return PLUGIN_HANDLED
  313. }
  314.  
  315. public cmdTsay(id, level, cid)
  316. {
  317.     if (!cmd_access(id, level, cid, 3))
  318.         return PLUGIN_HANDLED
  319.    
  320.     new cmd[16], color[16], color2[16], message[192], name[32], authid[32], userid = 0
  321.    
  322.     read_argv(0, cmd, 15)
  323.     new bool:tsay = (tolower(cmd[4]) == 't')
  324.    
  325.     read_args(message, 191)
  326.     remove_quotes(message)
  327.     parse(message, color, 15)
  328.    
  329.     new found = 0, a = 0
  330.     new lang[3], langnum = get_langsnum()
  331.  
  332.     for (new i = 0; i < MAX_CLR; ++i)
  333.     {
  334.         for (new j = 0; j < langnum; j++)
  335.         {
  336.             get_lang(j, lang)
  337.             format(color2, 15, "%L", lang, g_Colors[i])
  338.            
  339.             if (equali(color, color2))
  340.             {
  341.                 a = i
  342.                 found = 1
  343.                 break
  344.             }
  345.         }
  346.         if (found == 1)
  347.             break
  348.     }
  349.    
  350.     new length = found ? (strlen(color) + 1) : 0
  351.    
  352.     if (++g_msgChannel > 6 || g_msgChannel < 3)
  353.         g_msgChannel = 3
  354.  
  355.     new Float:verpos = (tsay ? 0.55 : 0.1) + float(g_msgChannel) / 35.0
  356.    
  357.     get_user_authid(id, authid, 31)
  358.     get_user_name(id, name, 31)
  359.     userid = get_user_userid(id)
  360.     set_hudmessage(g_Values[a][0], g_Values[a][1], g_Values[a][2], tsay ? 0.05 : -1.0, verpos, 0, 6.0, 6.0, 0.5, 0.15, -1)
  361.  
  362.     switch ( get_pcvar_num(amx_show_activity) )
  363.     {
  364.         case 3, 4:
  365.         {
  366.             new maxpl = get_maxplayers();
  367.             for (new pl = 1; pl <= maxpl; pl++)
  368.             {
  369.                 if (is_user_connected(pl) && !is_user_bot(pl))
  370.                 {
  371.                     if (is_user_admin(pl))
  372.                     {
  373.                         show_hudmessage(pl, "%s :   %s", name, message[length])
  374.                         client_print(pl, print_notify, "%s :   %s", name, message[length])
  375.                     }
  376.                     else
  377.                     {
  378.                         show_hudmessage(pl, "%s", message[length])
  379.                         client_print(pl, print_notify, "%s", message[length])
  380.                     }
  381.                 }
  382.             }
  383.             console_print(id, "%s :  %s", name, message[length])
  384.         }
  385.         case 2:
  386.         {
  387.             show_hudmessage(0, "%s :   %s", name, message[length])
  388.             client_print(0, print_notify, "%s :   %s", name, message[length])
  389.             console_print(id, "%s :  %s", name, message[length])
  390.         }
  391.         default:
  392.         {
  393.             show_hudmessage(0, "%s", message[length])
  394.             client_print(0, print_notify, "%s", message[length])
  395.             console_print(id, "%s", message[length])
  396.         }
  397.     }
  398.  
  399.     log_amx("Chat: ^"%s<%d><%s><>^" %s ^"%s^"", name, userid, authid, cmd[4], message[length])
  400.     log_message("^"%s<%d><%s><>^" triggered ^"%s^" (text ^"%s^") (color ^"%s^")", name, userid, authid, cmd, message[length], color2)
  401.  
  402.     return PLUGIN_HANDLED
  403. }
Advertisement
Add Comment
Please, Sign In to add comment