Guest User

Untitled

a guest
Jun 18th, 2020
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.14 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. end
  126.  
  127. if success then
  128. return result
  129. end
  130.  
  131. local messageField = {["Player"] = cPlayer,["Message"] = filterString(message, cPlayer.UserId)}
  132.  
  133. if coroutine.status(Chat.MessageThread) == "dead" then
  134. table.insert(Chat.Messages_List, messageField)
  135. Chat.MessageThread = coroutine.create(function ()
  136. for i = 1, #Chat.Messages_List do
  137. local field = Chat.Messages_List[i]
  138. Chat:CreateMessage(field["Player"], field["Message"])
  139. end
  140. Chat.Messages_List = {}
  141. end)
  142. coroutine.resume(Chat.MessageThread)
  143. else
  144. table.insert(Chat.Messages_List, messageField)
  145. end
  146. end
  147.  
  148. function Chat:CreateMessage(cPlayer, message)
  149. local pName = cPlayer ~= nil and cPlayer.Name or "GAME"
  150. message = message:gsub("^%s*(.-)%s*$", "%1")
  151. self.MessageQueue[#self.MessageQueue] = (#self.MessageQueue > self.Configuration.HistoryLength) and nil or self.MessageQueue[#self.MessageQueue]
  152. local pLabel = self.Templates.pLabel:clone()
  153. pLabel.Name = pName;
  154. pLabel.Text = pName .. ";";
  155. pLabel.Parent = self.RenderFrame;
  156. pLabel.TextColor3 = (cPlayer.Neutral) and Chat:ComputeChatColor(pName) or cPlayer.TeamColor.Color
  157. local nString = self.CachedSpaceStrings_List[pName] or Chat:ComputeSpaceString(pLabel)
  158. local mLabel = self.Templates.mLabel:clone()
  159. mLabel.Name = pName .. " - message";
  160. mLabel.TextColor3 = Chat.Configuration.MessageColor;
  161. mLabel.Text = nString .. message;
  162. mLabel.Parent = self.RenderFrame;
  163. local heightField = mLabel.TextBounds.Y
  164. mLabel.Size = UDim2.new(1, 0, heightField/self.RenderFrame.AbsoluteSize.Y, 0)
  165. pLabel.Size = mLabel.Size
  166. local yPixels = self.RenderFrame.AbsoluteSize.Y
  167. local yFieldSize = mLabel.TextBounds.Y
  168. local queueField = {}
  169. queueField["Player"] = pLabel
  170. queueField["Message"] = mLabel
  171. queueField["SpawnTime"] = tick()
  172. table.insert(self.MessageQueue, 1, queueField)
  173. Chat:UpdateQueue(queueField)
  174. end
  175.  
  176. function Chat:CreateChatBar()
  177. self.ClickToChatButton = self.Gui:WaitForChild("ClickToChat")
  178. self.ChatBar = self.Gui:WaitForChild("ChatBar")
  179. local mouse = game.Players.LocalPlayer:GetMouse()
  180. mouse.KeyDown:connect(function (key)
  181. if key:byte() == 47 or key == "/" then
  182. self.ClickToChatButton.Visible = false
  183. if year > 2007 then
  184. self.ChatBar.BackgroundColor3 = Color3.new(255/255, 255/255, 255/255)
  185. end
  186. self.ChatBar:CaptureFocus()
  187. end
  188. end)
  189. self.ClickToChatButton.MouseButton1Click:connect(function ()
  190. self.ClickToChatButton.Visible = false
  191. if year > 2007 then
  192. self.ChatBar.BackgroundColor3 = Color3.new(255/255, 255/255, 255/255)
  193. end
  194. self.ChatBar:CaptureFocus()
  195. end)
  196. end
  197.  
  198. function Chat:PlayerChat(message)
  199. local m = Instance.new("StringValue")
  200. m.Name = "NewMessage"
  201. m.Value = message
  202. m.Parent = game.Players.LocalPlayer
  203. game:GetService("Debris"):AddItem(m, 2)
  204. end
  205.  
  206. function Chat:CreateGui()
  207. self.Gui = script.Parent
  208. self.Frame = self.Gui:WaitForChild("ChatFrame")
  209. self.RenderFrame = self.Frame:WaitForChild("ChatRenderFrame")
  210. self.Templates = self.Gui:WaitForChild("Templates")
  211. Chat:CreateChatBar()
  212. self.ChatBar.FocusLost:connect(function(enterPressed)
  213. if year > 2007 then
  214. self.ChatBar.BackgroundColor3 = Color3.new(64/255, 64/255, 64/255)
  215. end
  216. if enterPressed and self.ChatBar.Text ~= "" then
  217. local cText = self.ChatBar.Text
  218. if string.sub(self.ChatBar.Text, 1, 1) == "%" then
  219. cText = "(TEAM) " .. string.sub(cText, 2, #cText)
  220. end
  221. Chat:PlayerChat(cText)
  222. if self.ClickToChatButton then
  223. self.ClickToChatButton.Visible = true
  224. end
  225. self.ChatBar.Text = ""
  226. self.ClickToChatButton.Visible = true
  227. end
  228. end)
  229. end
  230.  
  231. function Chat:TrackPlayerChats()
  232. local function chatRegister(p)
  233. p.ChildAdded:connect(function (obj)
  234. if obj:IsA("StringValue") and obj.Name == "NewMessage" then
  235. if game.Players.LocalPlayer.Neutral or p.TeamColor == game.Players.LocalPlayer.TeamColor then
  236. Chat:UpdateChat(p, obj.Value)
  237. end
  238. end
  239. end)
  240. end
  241. for _,v in pairs(game.Players:GetPlayers()) do
  242. chatRegister(v)
  243. end
  244. game.Players.PlayerAdded:connect(chatRegister)
  245. end
  246.  
  247. function Chat:CullThread()
  248. Spawn(function ()
  249. while true do
  250. if #self.MessageQueue > 0 then
  251. for _, field in pairs(self.MessageQueue) do
  252. if field["SpawnTime"] and field["Player"] and field["Message"] and tick() - field["SpawnTime"] > self.Configuration.LifeTime then
  253. field["Player"].Visible = false
  254. field["Message"].Visible = false
  255. end
  256. end
  257. end
  258. wait(5)
  259. end
  260. end)
  261. end
  262.  
  263. function Chat:Initialize()
  264. Chat:CreateGui()
  265. Chat:TrackPlayerChats()
  266. self.MessageThread = coroutine.create(function () end)
  267. coroutine.resume(self.MessageThread)
  268. Chat:CullThread()
  269. end
  270.  
  271. Chat:Initialize()
Advertisement
Add Comment
Please, Sign In to add comment