Guest User

Untitled

a guest
Jun 18th, 2020
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 10.13 KB | None | 0 0
  1. local year = script.Parent:WaitForChild("Year").Value
  2.  
  3.  
  4.  
  5. --Code
  6.  
  7. if year == 2007 then
  8.     script.Parent.ClickToChat.TextColor3 = Color3.new(0, 0, 0)
  9.     script.Parent.ChatBar.BackgroundColor3 = Color3.new(255/255, 255/255, 255/255)
  10. end
  11.  
  12. local Chat = {
  13.     ChatColors = {
  14.         BrickColor.new("Bright red"),
  15.         BrickColor.new("Bright blue"),
  16.         BrickColor.new("Earth green"),
  17.         BrickColor.new("Bright violet"),
  18.         BrickColor.new("Bright orange"),
  19.         BrickColor.new("Bright yellow"),
  20.         BrickColor.new("Light reddish violet"),
  21.         BrickColor.new("Brick yellow"),
  22.     };
  23.  
  24.     Gui = nil,
  25.     Frame = nil,
  26.     RenderFrame = nil,
  27.     TapToChatLabel = nil,
  28.     ClickToChatButton = nil,
  29.     Templates = nil,
  30.     EventListener = nil,
  31.     MessageQueue = {},
  32.  
  33.     Configuration = {                              
  34.         FontSize = Enum.FontSize.Size12,    
  35.         NumFontSize = 12,
  36.         HistoryLength = 20,
  37.         Size = UDim2.new(0.38, 0, 0.20, 0),
  38.         MessageColor = Color3.new(1, 1, 1),
  39.         AdminMessageColor = Color3.new(1, 215/255, 0),
  40.         XScale = 0.025,
  41.         LifeTime = 45,
  42.         Position = UDim2.new(0, 2, 0.05, 0),
  43.         DefaultTweenSpeed = 0.15,                          
  44.     };
  45.  
  46.     CachedSpaceStrings_List = {},
  47.     Messages_List = {},
  48.     MessageThread = nil,
  49.     TempSpaceLabel = nil,
  50. }
  51.  
  52. function GetNameValue(pName)
  53.     local value = 0
  54.     for index = 1, #pName do
  55.         local cValue = string.byte(string.sub(pName, index, index))
  56.         local reverseIndex = #pName - index + 1
  57.         if #pName%2 == 1 then
  58.             reverseIndex = reverseIndex - 1        
  59.         end
  60.         if reverseIndex%4 >= 2 then
  61.             cValue = -cValue            
  62.         end
  63.         value = value + cValue
  64.     end
  65.     return value%8
  66. end
  67.  
  68. function Chat:ComputeChatColor(pName)
  69.     return self.ChatColors[GetNameValue(pName) + 1].Color
  70. end
  71.  
  72. function Chat:UpdateQueue(field, diff)                  
  73.     for i = #self.MessageQueue, 1, -1 do            
  74.         if self.MessageQueue[i] then                        
  75.             for _, label in pairs(self.MessageQueue[i]) do                      
  76.                 if label and type(label) ~= "table" and type(label) ~= "number" then                    
  77.                     if label:IsA("TextLabel") or label:IsA("TextButton") then  
  78.                         if diff then
  79.                             label.Position = label.Position - UDim2.new(0, 0, diff, 0)
  80.                         else                                            
  81.                             if field == self.MessageQueue[i] then                      
  82.                                 label.Position = UDim2.new(self.Configuration.XScale, 0, label.Position.Y.Scale - field["Message"].Size.Y.Scale , 0)
  83.                             else                            
  84.                                 label.Position = UDim2.new(self.Configuration.XScale, 0, label.Position.Y.Scale - field["Message"].Size.Y.Scale, 0)                        
  85.                             end  
  86.                             if label.Position.Y.Scale < -0.01 then                          
  87.                                 label.Visible = false                      
  88.                                 label:Destroy()
  89.                             end
  90.                         end
  91.                     end
  92.                 end                        
  93.             end
  94.         end
  95.     end
  96. end
  97.  
  98. function Chat:ComputeSpaceString(pLabel)
  99.     local nString = " "
  100.     if not self.TempSpaceLabel then
  101.         self.TempSpaceLabel = self.Templates.SpaceButton
  102.         self.TempSpaceLabel.Size = UDim2.new(0, pLabel.AbsoluteSize.X, 0, pLabel.AbsoluteSize.Y);
  103.     end
  104.     self.TempSpaceLabel.Text = nString
  105.     while self.TempSpaceLabel.TextBounds.X < pLabel.TextBounds.X do
  106.         nString = nString .. " "
  107.         self.TempSpaceLabel.Text = nString              
  108.     end
  109.     nString = nString .. " "
  110.     self.CachedSpaceStrings_List[pLabel.Text] = nString
  111.     self.TempSpaceLabel.Text = ""
  112.     return nString  
  113. end
  114.  
  115.  
  116. function Chat:UpdateChat(cPlayer, message)
  117.     local textService = game:GetService("TextService")
  118.     local textToFilter = nil -- This is the text you want to filter
  119.  
  120.     local function filterString(str, playerId)
  121.     local result = ""
  122.     local success, failure = pcall(function()
  123.         textService:FilterStringAsync(str, playerId)
  124.     end)
  125.  
  126.     if success then
  127.         return result
  128.     end
  129.     local messageField = {["Player"] = cPlayer,["Message"] = filterString(message, cPlayer.UserId)}  
  130.     if coroutine.status(Chat.MessageThread) == "dead" then              
  131.         table.insert(Chat.Messages_List, messageField)              
  132.         Chat.MessageThread = coroutine.create(function ()
  133.             for i = 1, #Chat.Messages_List do  
  134.                 local field = Chat.Messages_List[i]                                                                                                                    
  135.                 Chat:CreateMessage(field["Player"], field["Message"])                      
  136.             end
  137.             Chat.Messages_List = {}                                
  138.         end)
  139.         coroutine.resume(Chat.MessageThread)
  140.     else
  141.         table.insert(Chat.Messages_List, messageField)
  142.     end
  143. end
  144.  
  145. function Chat:CreateMessage(cPlayer, message)      
  146.     local pName = cPlayer ~= nil and cPlayer.Name or "GAME"
  147.     message = message:gsub("^%s*(.-)%s*$", "%1")        
  148.     self.MessageQueue[#self.MessageQueue] = (#self.MessageQueue > self.Configuration.HistoryLength) and nil or self.MessageQueue[#self.MessageQueue]
  149.     local pLabel = self.Templates.pLabel:clone()
  150.     pLabel.Name = pName;
  151.     pLabel.Text = pName .. ";";
  152.     pLabel.Parent = self.RenderFrame;          
  153.     pLabel.TextColor3 = (cPlayer.Neutral) and Chat:ComputeChatColor(pName) or cPlayer.TeamColor.Color
  154.     local nString = self.CachedSpaceStrings_List[pName] or Chat:ComputeSpaceString(pLabel)
  155.     local mLabel = self.Templates.mLabel:clone()
  156.     mLabel.Name = pName .. " - message";                    
  157.     mLabel.TextColor3 = Chat.Configuration.MessageColor;                    
  158.     mLabel.Text = nString .. message;
  159.     mLabel.Parent = self.RenderFrame;  
  160.     local heightField = mLabel.TextBounds.Y
  161.     mLabel.Size = UDim2.new(1, 0, heightField/self.RenderFrame.AbsoluteSize.Y, 0)  
  162.     pLabel.Size = mLabel.Size
  163.     local yPixels = self.RenderFrame.AbsoluteSize.Y
  164.     local yFieldSize = mLabel.TextBounds.Y
  165.     local queueField = {}  
  166.     queueField["Player"] = pLabel
  167.     queueField["Message"] = mLabel
  168.     queueField["SpawnTime"] = tick()
  169.     table.insert(self.MessageQueue, 1, queueField)      
  170.     Chat:UpdateQueue(queueField)
  171. end
  172.  
  173. function Chat:CreateChatBar()  
  174.     self.ClickToChatButton = self.Gui:WaitForChild("ClickToChat")
  175.     self.ChatBar = self.Gui:WaitForChild("ChatBar")
  176.     local mouse = game.Players.LocalPlayer:GetMouse()
  177.     mouse.KeyDown:connect(function (key)
  178.         if key:byte() == 47 or key == "/" then
  179.             self.ClickToChatButton.Visible = false
  180.             if year > 2007 then
  181.                 self.ChatBar.BackgroundColor3 = Color3.new(255/255, 255/255, 255/255)
  182.             end
  183.             self.ChatBar:CaptureFocus()
  184.         end
  185.     end)
  186.     self.ClickToChatButton.MouseButton1Click:connect(function ()
  187.         self.ClickToChatButton.Visible = false
  188.         if year > 2007 then
  189.             self.ChatBar.BackgroundColor3 = Color3.new(255/255, 255/255, 255/255)
  190.         end
  191.         self.ChatBar:CaptureFocus()
  192.     end)    
  193. end
  194.  
  195. function Chat:PlayerChat(message)
  196.     local m = Instance.new("StringValue")
  197.     m.Name = "NewMessage"
  198.     m.Value = message
  199.     m.Parent = game.Players.LocalPlayer
  200.     game:GetService("Debris"):AddItem(m, 2)
  201. end
  202.  
  203. function Chat:CreateGui()
  204.     self.Gui = script.Parent
  205.     self.Frame = self.Gui:WaitForChild("ChatFrame")
  206.     self.RenderFrame = self.Frame:WaitForChild("ChatRenderFrame")
  207.     self.Templates = self.Gui:WaitForChild("Templates")
  208.     Chat:CreateChatBar()
  209.     self.ChatBar.FocusLost:connect(function(enterPressed)
  210.         if year > 2007 then
  211.             self.ChatBar.BackgroundColor3 = Color3.new(64/255, 64/255, 64/255)
  212.         end
  213.         if enterPressed and self.ChatBar.Text ~= "" then
  214.             local cText = self.ChatBar.Text
  215.             if string.sub(self.ChatBar.Text, 1, 1)  == "%" then
  216.                 cText = "(TEAM) " .. string.sub(cText, 2, #cText)
  217.             end
  218.             Chat:PlayerChat(cText)                                          
  219.             if self.ClickToChatButton then
  220.                 self.ClickToChatButton.Visible = true
  221.             end
  222.             self.ChatBar.Text = ""  
  223.             self.ClickToChatButton.Visible = true                          
  224.         end
  225.     end)    
  226. end
  227.  
  228. function Chat:TrackPlayerChats()
  229.     local function chatRegister(p)
  230.         p.ChildAdded:connect(function (obj)
  231.             if obj:IsA("StringValue") and obj.Name == "NewMessage" then
  232.                 if game.Players.LocalPlayer.Neutral or p.TeamColor == game.Players.LocalPlayer.TeamColor then
  233.                     Chat:UpdateChat(p, obj.Value)
  234.                 end
  235.             end
  236.         end)
  237.     end
  238.     for _,v in pairs(game.Players:GetPlayers()) do
  239.         chatRegister(v)
  240.     end
  241.     game.Players.PlayerAdded:connect(chatRegister)
  242. end
  243.  
  244. function Chat:CullThread()
  245.     Spawn(function ()
  246.         while true do
  247.             if #self.MessageQueue > 0 then
  248.                 for _, field in pairs(self.MessageQueue) do                
  249.                     if field["SpawnTime"] and field["Player"] and field["Message"] and tick() - field["SpawnTime"] > self.Configuration.LifeTime then
  250.                         field["Player"].Visible = false
  251.                         field["Message"].Visible = false
  252.                     end
  253.                 end
  254.             end
  255.             wait(5)
  256.         end
  257.     end)
  258. end
  259.  
  260. function Chat:Initialize()          
  261.     Chat:CreateGui()
  262.     Chat:TrackPlayerChats()
  263.     self.MessageThread = coroutine.create(function () end)
  264.                          coroutine.resume(self.MessageThread)
  265.     Chat:CullThread()
  266. end
  267.  
  268. Chat:Initialize()
Advertisement
Add Comment
Please, Sign In to add comment