Vaeb

Process Whisper Chats

Jun 13th, 2016
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.79 KB | None | 0 0
  1. local LP = game:GetService("Players").LocalPlayer
  2. local UIS = game:GetService("UserInputService")
  3. local PlrGui = LP:WaitForChild("PlayerGui")
  4. local isChatting = false
  5. local typeStr = ""
  6. local isChatting = false
  7. local isShift = false
  8.  
  9. local recentMessages = {}
  10.  
  11. local enumToChar = {
  12.     ["Tab"] = {"  "};
  13.     ["Space"] = {" "};
  14.     ["Hash"] = {"#", "~"};
  15.     ["Quote"] = {"'", "@"};
  16.     ["Comma"] = {",", "<"};
  17.     ["Minus"] = {"-", "_"};
  18.     ["Period"] = {".", ">"};
  19.     ["Slash"] = {"/", "?"};
  20.     ["Zero"] = {"0", ")"};
  21.     ["One"] = {"1", "!"};
  22.     ["Two"] = {"2", "\""};
  23.     ["Three"] = {"3", "£"};
  24.     ["Four"] = {"4", "$"};
  25.     ["Five"] = {"5", "%"};
  26.     ["Six"] = {"6", "^"};
  27.     ["Seven"] = {"7", "&"};
  28.     ["Eight"] = {"8", "*"};
  29.     ["Nine"] = {"9", "("};
  30.     ["Semicolon"] = {";", ":"};
  31.     ["Equals"] = {"=", "+"};
  32.     ["LeftBracket"] = {"[", "{"};
  33.     ["BackSlash"] = {"\\", "|"};
  34.     ["RightBracket"] = {"]", "}"};
  35.     ["Backquote"] = {"`"};
  36. }
  37.  
  38. local realProcess = {
  39.     [""] = true;
  40.     ["Tab"] = true;
  41.     ["`"] = true;
  42. }
  43.  
  44. local function isBox(Obj, Msg)
  45.     if Obj.ClassName == "TextBox" and Obj.Text == Msg then
  46.         return true
  47.     end
  48.     for _,v in pairs(Obj:GetChildren()) do
  49.         local childVal = isBox(v, Msg)
  50.         if childVal then
  51.             return true
  52.         end
  53.     end
  54. end
  55.  
  56. UIS.InputEnded:connect(function(input, processed)
  57.     input = input.KeyCode
  58.     if input == Enum.KeyCode.LeftShift or input == Enum.KeyCode.RightShift then
  59.         isShift = false
  60.     end
  61. end)
  62.  
  63. UIS.InputBegan:connect(function(input, processed)
  64.     input = input.KeyCode
  65.     if input == Enum.KeyCode.LeftShift or input == Enum.KeyCode.RightShift then
  66.         isShift = true
  67.         return
  68.     end
  69.     if not processed then
  70.         isChatting = false
  71.         typeStr = ""
  72.         return
  73.     end
  74.     local key = tostring(input):sub(14)
  75.     local keyReal = enumToChar[key] or (#key == 1 and {key:lower(), key}) or {""}
  76.     keyReal = isShift and keyReal[2] or keyReal[1]
  77.     if input == Enum.KeyCode.Backspace then
  78.         typeStr = typeStr:sub(1, #typeStr-1)
  79.     elseif #typeStr == 0 and isChatting == false and keyReal == "/" then
  80.         isChatting = true
  81.     else
  82.         typeStr = typeStr .. keyReal
  83.     end
  84.     if input == Enum.KeyCode.Return then
  85.         if isChatting and typeStr ~= "" then
  86.             local lastMessage = typeStr
  87.             typeStr = ""
  88.             isChatting = false
  89.             wait(1/30)
  90.             local hasFound = false
  91.             for _,v in pairs(recentMessages) do
  92.                 if v == lastMessage then
  93.                     hasFound = true
  94.                     break
  95.                 end
  96.             end
  97.             if not hasFound then
  98.                 print("Whisper:", lastMessage)
  99.             end
  100.             lastMessage = ""
  101.         else
  102.             typeStr = ""
  103.             isChatting = false
  104.         end
  105.     elseif not isChatting and not realProcess[keyReal] and not tonumber(keyReal) then
  106.         if not isBox(PlrGui, typeStr) then
  107.             isChatting = true
  108.         end
  109.     end
  110.     --print(key, keyReal, typeStr)
  111. end)
  112.  
  113. LP.Chatted:connect(function(Msg)
  114.     recentMessages[#recentMessages+1] = Msg
  115.     wait(1)
  116.     table.remove(recentMessages, 1)
  117. end)
Advertisement
Add Comment
Please, Sign In to add comment