Advertisement
Guest User

Untitled

a guest
Aug 28th, 2016
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <sourcemod>
  2. #include <sdktools>
  3. #include <chat-processor>
  4. #include <colorvariables>
  5.  
  6. #pragma semicolon 1
  7. #pragma newdecls required
  8.  
  9. #define PLUGIN_VERSION      "1.0.1"
  10.  
  11. public Plugin myinfo = {
  12.     name        = "[Source 2013] Chat-Processor Module: Chat Tags",
  13.     author      = "404 (abrandnewday)",
  14.     description = "Processes chat and provides colors and tags for Source 2013 games",
  15.     version     = PLUGIN_VERSION,
  16.     url         = "http://www.unfgaming.net"
  17. };
  18.  
  19. #define MAXLENGTH_NAME_NEW 256
  20.  
  21. Handle hColorForward;
  22. Handle hNameForward;
  23. Handle hTagForward;
  24. Handle hApplicationForward;
  25. Handle hMessageForward;
  26. Handle hPreLoadedForward;
  27. Handle hLoadedForward;
  28. Handle hConfigReloadedForward;
  29.  
  30. char g_strTag[MAXPLAYERS + 1][32];
  31. char g_strTagColor[MAXPLAYERS + 1][32];
  32. char g_strUsernameColor[MAXPLAYERS + 1][12];
  33. char g_strChatColor[MAXPLAYERS + 1][12];
  34.  
  35. char g_strDefaultTag[MAXPLAYERS + 1][32];
  36. char g_strDefaultTagColor[MAXPLAYERS + 1][32];
  37. char g_strDefaultUsernameColor[MAXPLAYERS + 1][12];
  38. char g_strDefaultChatColor[MAXPLAYERS + 1][12];
  39.  
  40. KeyValues kvConfigFile = null;
  41.  
  42. enum CPT_ColorType {
  43.     CPT_TagColor,
  44.     CPT_NameColor,
  45.     CPT_ChatColor
  46. };
  47.  
  48. #define COLOR_NONE      -1
  49. #define COLOR_GREEN     -2
  50. #define COLOR_OLIVE     -3
  51. #define COLOR_TEAM      -4
  52.  
  53. #define UPDATE_FILE     "chatcolors.txt"
  54.  
  55.  
  56. public APLRes AskPluginLoad2(Handle hMyself, bool bLate, char[] strError, int iErrMax)
  57. {
  58.     CreateNative("CPT_GetColor", Native_GetColor);
  59.     CreateNative("CPT_SetColor", Native_SetColor);
  60.     CreateNative("CPT_GetTag", Native_GetTag);
  61.     CreateNative("CPT_SetTag", Native_SetTag);
  62.     CreateNative("CPT_ResetColor", Native_ResetColor);
  63.     CreateNative("CPT_ResetTag", Native_ResetTag);
  64.    
  65.     RegPluginLibrary("cpt");
  66.    
  67.     return APLRes_Success;
  68. }
  69.  
  70. public void OnPluginStart()
  71. {
  72.     RegAdminCmd("sm_reloadtags", Command_ReloadConfig, ADMFLAG_CONFIG, "Reloads Custom Chat Colors config file");
  73.     hColorForward = CreateGlobalForward("CPT_OnChatColor", ET_Event, Param_Cell);
  74.     hNameForward = CreateGlobalForward("CPT_OnNameColor", ET_Event, Param_Cell);
  75.     hTagForward = CreateGlobalForward("CPT_OnTagApplied", ET_Event, Param_Cell);
  76.     hApplicationForward = CreateGlobalForward("CPT_OnColor", ET_Event, Param_Cell, Param_String, Param_Cell);
  77.     hMessageForward = CreateGlobalForward("CPT_OnChatMessage", ET_Ignore, Param_Cell, Param_String, Param_Cell);
  78.     hPreLoadedForward = CreateGlobalForward("CPT_OnUserConfigPreLoaded", ET_Event, Param_Cell);
  79.     hLoadedForward = CreateGlobalForward("CPT_OnUserConfigLoaded", ET_Ignore, Param_Cell);
  80.     hConfigReloadedForward = CreateGlobalForward("CPT_OnConfigReloaded", ET_Ignore);
  81.     LoadConfig();
  82. }
  83.  
  84. void LoadConfig()
  85. {
  86.     if(kvConfigFile != null)
  87.     {
  88.         delete kvConfigFile;
  89.     }
  90.     kvConfigFile = new KeyValues("chat_processor_tags");
  91.     char strPath[64];
  92.     BuildPath(Path_SM, strPath, sizeof(strPath), "configs/chat-processor-tags.cfg");
  93.     if(!kvConfigFile.ImportFromFile(strPath))
  94.     {
  95.         SetFailState("Config file missing");
  96.     }
  97.     for(int i = 1; i <= MaxClients; i++)
  98.     {
  99.         if(!IsClientInGame(i) || IsFakeClient(i))
  100.         {
  101.             continue;
  102.         }
  103.         ClearValues(i);
  104.         OnClientPostAdminCheck(i);
  105.     }
  106. }
  107.  
  108. public Action Command_ReloadConfig(int iClient, int iArgs)
  109. {
  110.     LoadConfig();
  111.     LogAction(iClient, -1, "Reloaded Chat-Processor Tags config file");
  112.     ReplyToCommand(iClient, "[CPT] Reloaded config file.");
  113.     Call_StartForward(hConfigReloadedForward);
  114.     Call_Finish();
  115.     return Plugin_Handled;
  116. }
  117.  
  118. stock void ClearValues(int iClient)
  119. {
  120.     Format(g_strTag[iClient], sizeof(g_strTag[]), "");
  121.     Format(g_strTagColor[iClient], sizeof(g_strTagColor[]), "");
  122.     Format(g_strUsernameColor[iClient], sizeof(g_strUsernameColor[]), "");
  123.     Format(g_strChatColor[iClient], sizeof(g_strChatColor[]), "");
  124.  
  125.     Format(g_strDefaultTag[iClient], sizeof(g_strDefaultTag[]), "");
  126.     Format(g_strDefaultTagColor[iClient], sizeof(g_strDefaultTagColor[]), "");
  127.     Format(g_strDefaultUsernameColor[iClient], sizeof(g_strDefaultUsernameColor[]), "");
  128.     Format(g_strDefaultChatColor[iClient], sizeof(g_strDefaultChatColor[]), "");
  129. }
  130.  
  131. public void OnClientConnected(int iClient)
  132. {
  133.     ClearValues(iClient);
  134. }
  135.  
  136. public void OnClientDisconnect(int iClient)
  137. {
  138.     ClearValues(iClient); // On connect and on disconnect, just to be safe
  139. }
  140.  
  141. public void OnClientPostAdminCheck(int iClient)
  142. {
  143.     if(!ConfigForward(iClient))
  144.     {
  145.         return; // Another plugin wants to block this
  146.     }
  147.    
  148.     // check the Steam ID first
  149.     char strAuthId2[32];
  150.     GetClientAuthId(iClient, AuthId_Steam2, strAuthId2, sizeof(strAuthId2));
  151.     kvConfigFile.Rewind();
  152.     if(!kvConfigFile.JumpToKey(strAuthId2))
  153.     {
  154.         kvConfigFile.Rewind();
  155.         kvConfigFile.GotoFirstSubKey();
  156.         AdminId iAdmin = GetUserAdmin(iClient);
  157.         AdminFlag fFlag;
  158.         char strConfigFlag[2];
  159.         char strSection[32];
  160.         bool bFound = false;
  161.         do
  162.         {
  163.             kvConfigFile.GetSectionName(strSection, sizeof(strSection));
  164.             kvConfigFile.GetString("flag", strConfigFlag, sizeof(strConfigFlag));
  165.             if(strlen(strConfigFlag) > 1)
  166.             {
  167.                 LogError("Multiple flags given in section \"%s\", which is not allowed. Using first character.", strSection);
  168.             }
  169.             if(strlen(strConfigFlag) == 0 && StrContains(strSection, "STEAM_", false) == -1 && StrContains(strSection, "[U:1:", false) == -1)
  170.             {
  171.                 bFound = true;
  172.                 break;
  173.             }
  174.             if(!FindFlagByChar(strConfigFlag[0], fFlag))
  175.             {
  176.                 if(strlen(strConfigFlag) > 0)
  177.                 {
  178.                     LogError("Invalid flag given for section \"%s\", skipping", strSection);
  179.                 }
  180.                 continue;
  181.             }
  182.             if(GetAdminFlag(iAdmin, fFlag))
  183.             {
  184.                 bFound = true;
  185.                 break;
  186.             }
  187.         } while(kvConfigFile.GotoNextKey());
  188.         if(!bFound)
  189.         {
  190.             return;
  191.         }
  192.     }
  193.     char strClientTagColor[12];
  194.     char strClientNameColor[12];
  195.     char strClientChatColor[12];
  196.     kvConfigFile.GetString("tag", g_strTag[iClient], sizeof(g_strTag[]));
  197.     kvConfigFile.GetString("tagcolor", strClientTagColor, sizeof(strClientTagColor));
  198.     kvConfigFile.GetString("namecolor", strClientNameColor, sizeof(strClientNameColor));
  199.     kvConfigFile.GetString("textcolor", strClientChatColor, sizeof(strClientChatColor));
  200.     ReplaceString(strClientTagColor, sizeof(strClientTagColor), "#", "");
  201.     ReplaceString(strClientNameColor, sizeof(strClientNameColor), "#", "");
  202.     ReplaceString(strClientChatColor, sizeof(strClientChatColor), "#", "");
  203.     int iTagLength = strlen(strClientTagColor);
  204.     int iNameLength = strlen(strClientNameColor);
  205.     int iChatLength = strlen(strClientChatColor);
  206.     if(iTagLength == 6 || iTagLength == 8 || StrEqual(strClientTagColor, "T", false) || StrEqual(strClientTagColor, "G", false) || StrEqual(strClientTagColor, "O", false))
  207.     {
  208.         strcopy(g_strTagColor[iClient], sizeof(g_strTagColor[]), strClientTagColor);
  209.     }
  210.     if(iNameLength == 6 || iNameLength == 8 || StrEqual(strClientNameColor, "G", false) || StrEqual(strClientNameColor, "O", false))
  211.     {
  212.         strcopy(g_strUsernameColor[iClient], sizeof(g_strUsernameColor[]), strClientNameColor);
  213.     }
  214.     if(iChatLength == 6 || iChatLength == 8 || StrEqual(strClientChatColor, "T", false) || StrEqual(strClientChatColor, "G", false) || StrEqual(strClientChatColor, "O", false))
  215.     {
  216.         strcopy(g_strChatColor[iClient], sizeof(g_strChatColor[]), strClientChatColor);
  217.     }
  218.     strcopy(g_strDefaultTag[iClient], sizeof(g_strDefaultTag[]), g_strTag[iClient]);
  219.     strcopy(g_strDefaultTagColor[iClient], sizeof(g_strDefaultTagColor[]), g_strTagColor[iClient]);
  220.     strcopy(g_strDefaultUsernameColor[iClient], sizeof(g_strDefaultUsernameColor[]), g_strUsernameColor[iClient]);
  221.     strcopy(g_strDefaultChatColor[iClient], sizeof(g_strDefaultChatColor[]), g_strChatColor[iClient]);
  222.     Call_StartForward(hLoadedForward);
  223.     Call_PushCell(iClient);
  224.     Call_Finish();
  225. }
  226.  
  227. forward Action OnChatMessage(int& author, Handle recipients, eChatFlags& flag, char[] name, char[] message, bool& bProcessColors, bool& bRemoveColors);
  228. {
  229.     return Plugin_Handled;
  230. }
  231.  
  232. forward void OnChatMessagePost(int author, Handle recipients, eChatFlags flag, const char[] name, const char[] message, bool bProcessColors, bool bRemoveColors);
  233. {
  234.     char strNewName[MAXLENGTH_NAME_NEW];
  235.     strcopy(strNewName, sizeof(strNewName), name);
  236.    
  237.     char strNewMessage[MAXLENGTH_MESSAGE];
  238.     strcopy(strNewMessage, sizeof(strNewMessage), message);
  239.    
  240.     if(CheckForward(iAuthor, strNewMessage, CPT_NameColor))
  241.     {
  242.         if(StrEqual(g_strUsernameColor[iAuthor], "G", false))
  243.         {
  244.             Format(strNewName, MAXLENGTH_NAME_NEW, "\x04%s", strName);
  245.         }
  246.         else if(StrEqual(g_strUsernameColor[iAuthor], "O", false))
  247.         {
  248.             Format(strNewName, MAXLENGTH_NAME_NEW, "\x05%s", strName);
  249.         }
  250.         else if(strlen(g_strUsernameColor[iAuthor]) == 6)
  251.         {
  252.             Format(strNewName, MAXLENGTH_NAME_NEW, "\x07%s%s", g_strUsernameColor[iAuthor], strName);
  253.         }
  254.         else if(strlen(g_strUsernameColor[iAuthor]) == 8)
  255.         {
  256.             Format(strNewName, MAXLENGTH_NAME_NEW, "\x08%s%s", g_strUsernameColor[iAuthor], strName);
  257.         }
  258.         else
  259.         {
  260.             Format(strNewName, MAXLENGTH_NAME_NEW, "\x03%s", strName); // team color by default!
  261.         }
  262.     }
  263.     else
  264.     {
  265.         Format(strNewName, MAXLENGTH_NAME_NEW, "\x03%s", strName); // team color by default!
  266.     }
  267.     if(CheckForward(iAuthor, strNewMessage, CPT_TagColor))
  268.     {
  269.         if(strlen(g_strTag[iAuthor]) > 0)
  270.         {
  271.             if(StrEqual(g_strTagColor[iAuthor], "T", false))
  272.             {
  273.                 Format(strNewName, MAXLENGTH_NAME_NEW, "\x03%s%s", g_strTag[iAuthor], strName);
  274.             }
  275.             else if(StrEqual(g_strTagColor[iAuthor], "G", false))
  276.             {
  277.                 Format(strNewName, MAXLENGTH_NAME_NEW, "\x04%s%s", g_strTag[iAuthor], strName);
  278.             }
  279.             else if(StrEqual(g_strTagColor[iAuthor], "O", false))
  280.             {
  281.                 Format(strNewName, MAXLENGTH_NAME_NEW, "\x05%s%s", g_strTag[iAuthor], strName);
  282.             }
  283.             else if(strlen(g_strTagColor[iAuthor]) == 6)
  284.             {
  285.                 Format(strNewName, MAXLENGTH_NAME_NEW, "\x07%s%s%s", g_strTagColor[iAuthor], g_strTag[iAuthor], strName);
  286.             }
  287.             else if(strlen(g_strTagColor[iAuthor]) == 8)
  288.             {
  289.                 Format(strNewName, MAXLENGTH_NAME_NEW, "\x08%s%s%s", g_strTagColor[iAuthor], g_strTag[iAuthor], strName);
  290.             }
  291.             else
  292.             {
  293.                 Format(strNewName, MAXLENGTH_NAME_NEW, "%s\x01%s", g_strTag[iAuthor], strName);
  294.             }
  295.         }
  296.     }
  297.    
  298.     if(strlen(g_strChatColor[iAuthor]) > 0 && CheckForward(iAuthor, strNewMessage, CPT_ChatColor))
  299.     {
  300.         if(StrEqual(g_strChatColor[iAuthor], "T", false))
  301.         {
  302.             Format(strNewMessage, MAXLENGTH_MESSAGE, "\x03%s", strNewMessage);
  303.         }
  304.         else if(StrEqual(g_strChatColor[iAuthor], "G", false))
  305.         {
  306.             Format(strNewMessage, MAXLENGTH_MESSAGE, "\x04%s", strNewMessage);
  307.         }
  308.         else if(StrEqual(g_strChatColor[iAuthor], "O", false))
  309.         {
  310.             Format(strNewMessage, MAXLENGTH_MESSAGE, "\x05%s", strNewMessage);
  311.         }
  312.         else if(strlen(g_strChatColor[iAuthor]) == 6)
  313.         {
  314.             Format(strNewMessage, MAXLENGTH_MESSAGE, "\x07%s%s", g_strChatColor[iAuthor], strNewMessage);
  315.         }
  316.         else if(strlen(g_strChatColor[iAuthor]) == 8)
  317.         {
  318.             Format(strNewMessage, MAXLENGTH_MESSAGE, "\x08%s%s", g_strChatColor[iAuthor], strNewMessage);
  319.         }
  320.     }
  321.    
  322.     char strGame[64];
  323.     GetGameFolderName(strGame, sizeof(strGame));
  324.     if(StrEqual(strGame, "csgo"))
  325.     {
  326.         Format(strName, MAXLENGTH_NAME_NEW, "\x01\x0B%s", strName);
  327.     }
  328.    
  329.     Call_StartForward(hMessageForward);
  330.     Call_PushCell(iAuthor);
  331.     Call_PushStringEx(strNewMessage, MAXLENGTH_MESSAGE, SM_PARAM_STRING_UTF8|SM_PARAM_STRING_COPY, SM_PARAM_COPYBACK);
  332.     Call_PushCell(MAXLENGTH_MESSAGE);
  333.     Call_Finish();
  334.    
  335.     CPrintToChat(iAuthor, "%s{default} : %s", strNewName, strNewMessage);
  336. }
  337.  
  338. stock bool CheckForward(int iAuthor, const char[] strMessage, CPT_ColorType tType)
  339. {
  340.     Action aResult = Plugin_Continue;
  341.     Call_StartForward(hApplicationForward);
  342.     Call_PushCell(iAuthor);
  343.     Call_PushString(strMessage);
  344.     Call_PushCell(tType);
  345.     Call_Finish(aResult);
  346.     if(aResult >= Plugin_Handled)
  347.     {
  348.         return false;
  349.     }
  350.    
  351.     // Compatibility
  352.     switch(tType)
  353.     {
  354.         case CPT_TagColor:
  355.         {
  356.             return TagForward(iAuthor);
  357.         }
  358.         case CPT_NameColor:
  359.         {
  360.             return NameForward(iAuthor);
  361.         }
  362.         case CPT_ChatColor:
  363.         {
  364.             return ColorForward(iAuthor);
  365.         }
  366.     }
  367.    
  368.     return true;
  369. }
  370.  
  371. stock bool ColorForward(int iAuthor)
  372. {
  373.     Action aResult = Plugin_Continue;
  374.     Call_StartForward(hColorForward);
  375.     Call_PushCell(iAuthor);
  376.     Call_Finish(aResult);
  377.     if(aResult >= Plugin_Handled)
  378.     {
  379.         return false;
  380.     }
  381.    
  382.     return true;
  383. }
  384.  
  385. stock bool NameForward(int iAuthor)
  386. {
  387.     Action aResult = Plugin_Continue;
  388.     Call_StartForward(hNameForward);
  389.     Call_PushCell(iAuthor);
  390.     Call_Finish(aResult);
  391.     if(aResult >= Plugin_Handled)
  392.     {
  393.         return false;
  394.     }
  395.    
  396.     return true;
  397. }
  398.  
  399. stock bool TagForward(int iAuthor)
  400. {
  401.     Action aResult = Plugin_Continue;
  402.     Call_StartForward(hTagForward);
  403.     Call_PushCell(iAuthor);
  404.     Call_Finish(aResult);
  405.     if(aResult >= Plugin_Handled)
  406.     {
  407.         return false;
  408.     }
  409.    
  410.     return true;
  411. }
  412.  
  413. stock bool ConfigForward(int iClient)
  414. {
  415.     Action aResult = Plugin_Continue;
  416.     Call_StartForward(hPreLoadedForward);
  417.     Call_PushCell(iClient);
  418.     Call_Finish(aResult);
  419.     if(aResult >= Plugin_Handled)
  420.     {
  421.         return false;
  422.     }
  423.    
  424.     return true;
  425. }
  426.  
  427. public int Native_GetColor(Handle hPlugin, int NumParams)
  428. {
  429.     int iClient = GetNativeCell(1);
  430.     if(iClient < 1 || iClient > MaxClients || !IsClientInGame(iClient))
  431.     {
  432.         ThrowNativeError(SP_ERROR_PARAM, "Invalid client or client is not in game");
  433.         return COLOR_NONE;
  434.     }
  435.     switch(GetNativeCell(2))
  436.     {
  437.         case CPT_TagColor:
  438.         {
  439.             if(StrEqual(g_strTagColor[iClient], "T", false))
  440.             {
  441.                 SetNativeCellRef(3, false);
  442.                 return COLOR_TEAM;
  443.             }
  444.             else if(StrEqual(g_strTagColor[iClient], "G", false))
  445.             {
  446.                 SetNativeCellRef(3, false);
  447.                 return COLOR_GREEN;
  448.             }
  449.             else if(StrEqual(g_strTagColor[iClient], "O", false))
  450.             {
  451.                 SetNativeCellRef(3, false);
  452.                 return COLOR_OLIVE;
  453.             }
  454.             else if(strlen(g_strTagColor[iClient]) == 6 || strlen(g_strTagColor[iClient]) == 8)
  455.             {
  456.                 SetNativeCellRef(3, strlen(g_strTagColor[iClient]) == 8);
  457.                 return StringToInt(g_strTagColor[iClient], 16);
  458.             }
  459.             else
  460.             {
  461.                 SetNativeCellRef(3, false);
  462.                 return COLOR_NONE;
  463.             }
  464.         }
  465.         case CPT_NameColor:
  466.         {
  467.             if(StrEqual(g_strUsernameColor[iClient], "G", false))
  468.             {
  469.                 SetNativeCellRef(3, false);
  470.                 return COLOR_GREEN;
  471.             }
  472.             else if(StrEqual(g_strUsernameColor[iClient], "O", false))
  473.             {
  474.                 SetNativeCellRef(3, false);
  475.                 return COLOR_OLIVE;
  476.             }
  477.             else if(strlen(g_strUsernameColor[iClient]) == 6 || strlen(g_strUsernameColor[iClient]) == 8)
  478.             {
  479.                 SetNativeCellRef(3, strlen(g_strUsernameColor[iClient]) == 8);
  480.                 return StringToInt(g_strUsernameColor[iClient], 16);
  481.             }
  482.             else
  483.             {
  484.                 SetNativeCellRef(3, false);
  485.                 return COLOR_TEAM;
  486.             }
  487.         }
  488.         case CPT_ChatColor:
  489.         {
  490.             if(StrEqual(g_strChatColor[iClient], "T", false))
  491.             {
  492.                 SetNativeCellRef(3, false);
  493.                 return COLOR_TEAM;
  494.             }
  495.             else if(StrEqual(g_strChatColor[iClient], "G", false))
  496.             {
  497.                 SetNativeCellRef(3, false);
  498.                 return COLOR_GREEN;
  499.             }
  500.             else if(StrEqual(g_strChatColor[iClient], "O", false))
  501.             {
  502.                 SetNativeCellRef(3, false);
  503.                 return COLOR_OLIVE;
  504.             }
  505.             else if(strlen(g_strChatColor[iClient]) == 6 || strlen(g_strChatColor[iClient]) == 8)
  506.             {
  507.                 SetNativeCellRef(3, strlen(g_strChatColor[iClient]) == 8);
  508.                 return StringToInt(g_strChatColor[iClient], 16);
  509.             }
  510.             else
  511.             {
  512.                 SetNativeCellRef(3, false);
  513.                 return COLOR_NONE;
  514.             }
  515.         }
  516.     }
  517.     return COLOR_NONE;
  518. }
  519.  
  520. public int Native_SetColor(Handle hPlugin, int iNumParams)
  521. {
  522.     int iClient = GetNativeCell(1);
  523.     if(iClient < 1 || iClient > MaxClients || !IsClientInGame(iClient))
  524.     {
  525.         ThrowNativeError(SP_ERROR_PARAM, "Invalid client or client is not in game");
  526.         return false;
  527.     }
  528.     char strColor[32];
  529.     if(GetNativeCell(3) < 0)
  530.     {
  531.         switch(GetNativeCell(3))
  532.         {
  533.             case COLOR_GREEN:
  534.             {
  535.                 Format(strColor, sizeof(strColor), "G");
  536.             }
  537.             case COLOR_OLIVE:
  538.             {
  539.                 Format(strColor, sizeof(strColor), "O");
  540.             }
  541.             case COLOR_TEAM:
  542.             {
  543.                 Format(strColor, sizeof(strColor), "T");
  544.             }
  545.             case COLOR_NONE:
  546.             {
  547.                 Format(strColor, sizeof(strColor), "");
  548.             }
  549.         }
  550.     }
  551.     else
  552.     {
  553.         if(!GetNativeCell(4))
  554.         {
  555.             // No alpha
  556.             Format(strColor, sizeof(strColor), "%06X", GetNativeCell(3));
  557.         }
  558.         else
  559.         {
  560.             // Alpha specified
  561.             Format(strColor, sizeof(strColor), "%08X", GetNativeCell(3));
  562.         }
  563.     }
  564.     if(strlen(strColor) != 6 && strlen(strColor) != 8 && !StrEqual(strColor, "G", false) && !StrEqual(strColor, "O", false) && !StrEqual(strColor, "T", false))
  565.     {
  566.         return false;
  567.     }
  568.     switch(GetNativeCell(2))
  569.     {  
  570.         case CPT_TagColor:
  571.         {
  572.             strcopy(g_strTagColor[iClient], sizeof(g_strTagColor[]), strColor);
  573.         }
  574.         case CPT_NameColor:
  575.         {
  576.             strcopy(g_strUsernameColor[iClient], sizeof(g_strUsernameColor[]), strColor);
  577.         }
  578.         case CPT_ChatColor:
  579.         {
  580.             strcopy(g_strChatColor[iClient], sizeof(g_strChatColor[]), strColor);
  581.         }
  582.     }
  583.     return true;
  584. }
  585.  
  586. public int Native_GetTag(Handle hPlugin, int iNumParams)
  587. {
  588.     int iClient = GetNativeCell(1);
  589.     if(iClient < 1 || iClient > MaxClients || !IsClientInGame(iClient))
  590.     {
  591.         ThrowNativeError(SP_ERROR_PARAM, "Invalid client or client is not in game");
  592.         return;
  593.     }
  594.     SetNativeString(2, g_strTag[iClient], GetNativeCell(3));
  595. }
  596.  
  597. public int Native_SetTag(Handle hPlugin, int iNumParams)
  598. {
  599.     int iClient = GetNativeCell(1);
  600.     if(iClient < 1 || iClient > MaxClients || !IsClientInGame(iClient))
  601.     {
  602.         ThrowNativeError(SP_ERROR_PARAM, "Invalid client or client is not in game");
  603.         return;
  604.     }
  605.     GetNativeString(2, g_strTag[iClient], sizeof(g_strTag[]));
  606. }
  607.  
  608. public int Native_ResetColor(Handle hPlugin, int iNumParams)
  609. {
  610.     int iClient = GetNativeCell(1);
  611.     if(iClient < 1 || iClient > MaxClients || !IsClientInGame(iClient))
  612.     {
  613.         ThrowNativeError(SP_ERROR_PARAM, "Invalid client or client is not in game");
  614.         return;
  615.     }
  616.     switch(GetNativeCell(2))
  617.     {
  618.         case CPT_TagColor:
  619.         {
  620.             strcopy(g_strTagColor[iClient], sizeof(g_strTagColor[]), g_strDefaultTagColor[iClient]);
  621.         }
  622.         case CPT_NameColor:
  623.         {
  624.             strcopy(g_strUsernameColor[iClient], sizeof(g_strUsernameColor[]), g_strDefaultUsernameColor[iClient]);
  625.         }
  626.         case CPT_ChatColor:
  627.         {
  628.             strcopy(g_strChatColor[iClient], sizeof(g_strChatColor[]), g_strDefaultChatColor[iClient]);
  629.         }
  630.     }
  631. }
  632.  
  633. public int Native_ResetTag(Handle hPlugin, int iNumParams)
  634. {
  635.     int iClient = GetNativeCell(1);
  636.     if(iClient < 1 || iClient > MaxClients || !IsClientInGame(iClient))
  637.     {
  638.         ThrowNativeError(SP_ERROR_PARAM, "Invalid client or client is not in game");
  639.         return;
  640.     }
  641.     strcopy(g_strTag[iClient], sizeof(g_strTag[]), g_strDefaultTag[iClient]);
  642. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement