Advertisement
Guest User

Untitled

a guest
May 20th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.23 KB | None | 0 0
  1. function handleColors(text, processColor)
  2.     local Process = {
  3.         None = 0,
  4.         Colors = 1,
  5.         Strip = 2,
  6.     }
  7.     if (processColor == Process.None) then return text end
  8.     local colors = {
  9.         ["{D"] = "\027[30;1m", ["{R"] = "\027[31;1m", ["{G"] = "\027[32;1m", ["{Y"] = "\027[33;1m",
  10.         ["{B"] = "\027[34;1m", ["{M"] = "\027[35;1m", ["{C"] = "\027[36;1m", ["{W"] = "\027[37;1m",
  11.         ["{d"] = "\027[30m", ["{r"] = "\027[31m", ["{g"] = "\027[32m", ["{y"] = "\027[33m",
  12.         ["{b"] = "\027[34m", ["{m"] = "\027[35m", ["{c"] = "\027[36m", ["{w"] = "\027[37m",
  13.         ["{x"] = "\027[0m",
  14.     }
  15.     local colorKeys = {}
  16.     for k,v in pairs(colors) do
  17.         table.insert(colorKeys,k)
  18.         if (processColor == Process.Colors) then
  19.             text = text:gsub(k,v)
  20.         elseif (processColor == Process.Strip) then
  21.             text = text:gsub(k,"")
  22.         end
  23.     end
  24.     while (text:match("{?")) do
  25.         if (processColor == Process.Colors) then
  26.             text = text:gsub("{?",colorKeys[math.random[#colorKeys]],1)
  27.         elseif (processColor == Process.Strip) then
  28.             text = text:gsub("{?","")
  29.         end
  30.     end
  31.     text = text:gsub("{|","{")
  32.     return text
  33. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement