Advertisement
DropSquad

Binary Chat

Sep 7th, 2015
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.63 KB | None | 0 0
  1. -- Binary Chat (JimmyChance)
  2.  
  3. local module = {}
  4.  
  5. module.toByte = function(v)
  6.     if type(v) == "number" then return tostring(v) end
  7.     return v:gsub(".", function(t) return " " .. t:byte() end):gsub("^%s*", "")
  8. end
  9.  
  10. module.toChar = function(v)
  11.     if type(v) == "number" then return v end
  12.     return (" " .. v):gsub("(%s*)(%d+)", function(_, char)
  13.         return char:char()
  14.     end)
  15. end
  16.  
  17. module.toDecimal = function(v)
  18.     return tostring(v):gsub("%d+", function(bin)
  19.         local returned = 0
  20.         for i = 1, #bin do
  21.             local place = 2^(i - 1)
  22.             returned = returned + place * tonumber(bin:sub(-i, -i))
  23.         end
  24.         return returned
  25.     end)
  26. end
  27.  
  28. module.toBinary = function(v)
  29.     return module.toByte(v):gsub("%d+", function(char)
  30.         local number = tonumber(char)
  31.         local returned = ""
  32.         while math.floor(number/2) > 0 do
  33.             local remainder = number % 2
  34.             returned = returned .. remainder
  35.             number = math.floor(number/2)
  36.         end returned = returned .. number
  37.         return ("%08d"):format(tonumber(returned:reverse()))
  38.     end)
  39. end
  40.  
  41. _G.module = module
  42.  
  43. onChatted = function(speaker, message)
  44.     local head = speaker.Character and speaker.Character:FindFirstChild("Head")
  45.     if head then
  46.         game:GetService("Chat"):Chat(head, module.toBinary(message), "Red")
  47.     end
  48. end
  49.  
  50. for _, player in next, game.Players:GetPlayers() do
  51.     player.Chatted:connect(function(message)
  52.         onChatted(player, message)
  53.     end)
  54. end
  55.  
  56. game.Players.PlayerAdded:connect(function(player)
  57.     player.Chatted:connect(function(message)
  58.         onChatted(player, message)
  59.     end)
  60. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement