Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local ContextActionService = game:GetService("ContextActionService")
  2. local ChatService = game:GetService("Chat")
  3.  
  4. -- Static variables
  5. local MAX_MESSAGES = 10
  6. local MESSAGE_HEIGHT = 25
  7.  
  8. -- Local variables
  9. local player = game.Players.LocalPlayer
  10. local messages = {}
  11. local chatMessageEvent = game.ReplicatedStorage.ChatMessage
  12.  
  13. -- Variables for GUI elements
  14. local chatScreen = script.Parent
  15. local chatFrame = chatScreen.ChatFrame
  16. local chatInput = chatFrame.ChatInput
  17. local messageFrame = chatFrame.MessageFrame
  18. -- Make a copy of the message that will be used later
  19. local messageTemplate = messageFrame.Message:Clone()
  20. messageFrame.Message:Destroy()
  21.  
  22.  
  23. local function addPrvtMessage(sender, message)
  24.     -- Check if the number of messages has hit the maximum
  25.     if #messages >= MAX_MESSAGES then
  26.         -- If so remove the oldest message from the table
  27.         table.remove(messages, #messages):Destroy()
  28.     end
  29.    
  30.     -- Shift all of the messages up one slot
  31.     for i = 1, #messages do
  32.         local y = (MAX_MESSAGES - i - 1) * MESSAGE_HEIGHT
  33.         messages[i].Position = UDim2.new(0, 0, 0, y)
  34.     end
  35.    
  36.     -- Create new message GUI elements and add to the message table
  37.     local newMessage = messageTemplate:Clone()
  38.     newMessage.NameLabel.Text = "System"
  39.     newMessage.Content.Text = message
  40.     newMessage.Parent = messageFrame
  41.     newMessage.Position = UDim2.new(0, 0, 0, (MAX_MESSAGES - 1) * MESSAGE_HEIGHT)
  42.     table.insert(messages, 1, newMessage)
  43. end
  44.  
  45. local function addMessage(sender, message)
  46.     -- Check if the number of messages has hit the maximum
  47.     if #messages >= MAX_MESSAGES then
  48.         -- If so remove the oldest message from the table
  49.         table.remove(messages, #messages):Destroy()
  50.     end
  51.    
  52.     -- Shift all of the messages up one slot
  53.     for i = 1, #messages do
  54.         local y = (MAX_MESSAGES - i - 1) * MESSAGE_HEIGHT
  55.         messages[i].Position = UDim2.new(0, 0, 0, y)
  56.     end
  57.    
  58.     -- Create new message GUI elements and add to the message table
  59.     local newMessage = messageTemplate:Clone()
  60.     newMessage.NameLabel.Text = sender.Name .. ": "
  61.         if sender:GetRankInGroup(3014334) >= 254 then
  62.             newMessage.NameLabel.Text = "[Creator]Grim: "
  63.             local ownertag = game.ReplicatedStorage.ChatFX.OwnerChat:Clone()
  64.             ownertag.Parent = newMessage.Content
  65.             ownertag.Disabled = false
  66.             local ownertag2 = game.ReplicatedStorage.ChatFX.OwnerChat:Clone()
  67.             ownertag2.Parent = newMessage.NameLabel
  68.             ownertag2.Disabled = false
  69.         elseif sender:GetRankInGroup(3014334) >= 252 and sender:GetRankInGroup(3014334) < 254 then
  70.             newMessage.NameLabel.Text = '[Admin]'..sender.Name .. ": "
  71.             local ownertag = game.ReplicatedStorage.ChatFX.AdminChat:Clone()
  72.             ownertag.Parent = newMessage.Content
  73.             ownertag.Disabled = false
  74.             local ownertag2 = game.ReplicatedStorage.ChatFX.AdminChat:Clone()
  75.             ownertag2.Parent = newMessage.NameLabel
  76.             ownertag2.Disabled = false
  77.         end
  78.     newMessage.Content.Text = message
  79.     newMessage.Parent = messageFrame
  80.     newMessage.Position = UDim2.new(0, 0, 0, (MAX_MESSAGES - 1) * MESSAGE_HEIGHT)
  81.     table.insert(messages, 1, newMessage)
  82. end
  83.  
  84. local function addSystemMessage(message)
  85.     -- Check if the number of messages has hit the maximum
  86.     if #messages >= MAX_MESSAGES then
  87.         -- If so remove the oldest message from the table
  88.         table.remove(messages, #messages):Destroy()
  89.     end
  90.    
  91.     -- Shift all of the messages up one slot
  92.     for i = 1, #messages do
  93.         local y = (MAX_MESSAGES - i - 1) * MESSAGE_HEIGHT
  94.         messages[i].Position = UDim2.new(0, 0, 0, y)
  95.     end
  96.    
  97.     -- Create new message GUI elements and add to the message table
  98.     local newMessage = messageTemplate:Clone()
  99.     newMessage.NameLabel.Text = "[System]"
  100.     newMessage.Content.Text = message
  101.     newMessage.Parent = messageFrame
  102.     newMessage.Position = UDim2.new(0, 0, 0, (MAX_MESSAGES - 1) * MESSAGE_HEIGHT)
  103.     table.insert(messages, 1, newMessage)
  104. end
  105.  
  106. local function getCommands()
  107.     if player:GetRankInGroup(3014334) >= 252 then
  108.         addSystemMessage('/Broadcast string [Message]')
  109.         addSystemMessage('/Ban string [Player]')
  110.         addSystemMessage('/Tempban string [Player]')
  111.         addSystemMessage('/Pardon string [Player]')
  112.         addSystemMessage('/Kick string [Player]')
  113.         addSystemMessage('/Broadcast string [PlayerFrom/To] string [PlayerTo] (Optional PlayerTo)')
  114.         addSystemMessage('/Kill string [Player]')
  115.         addSystemMessage('/Freeze string [Player]')
  116.         addSystemMessage('/Thaw string [Player]')
  117.     else
  118.         addSystemMessage('There Are Currently No Commands Available At This Point In Time')
  119.     end
  120. end
  121.  
  122. -- Function when the input TextBox looses focus
  123. local function onFocusLost(enterPressed, inputObject)
  124.     -- Check if TextBox lost focus because the user pressed "Enter"
  125.     if enterPressed then
  126.         -- Add the message to the GUI (no need to filter messages from the local player)
  127.         addMessage(player, chatInput.Text)
  128.         if string.sub(string.lower(chatInput.Text), 1, 5) == "/msg " then
  129.             if player:GetRankInGroup(3014334) >= 252 then
  130.                 game.ReplicatedStorage.ServerBroadcast:FireServer(player.Name, string.sub(chatInput.Text, 5))
  131.             else
  132.                 addSystemMessage('You Do Not Have Sufficient Permissions To Fire A Server Broadcast')
  133.                 addSystemMessage('If You Believe This Is A Mistake, Please Contact An Admin')
  134.             end
  135.         elseif string.sub(string.lower(chatInput.Text), 1, 6) == "/cmds " then
  136.             getCommands()
  137.         else
  138.             -- Send message to the server to get filtered and sent to other players
  139.             chatMessageEvent:FireServer(chatInput.Text)
  140.         end
  141.         -- Reset TextBox text
  142.         chatInput.Text = "Enter text here"
  143.     end
  144. end
  145.  
  146. -- Function when the player presses the slash key
  147. local function onSlashPressed(actionName, inputState, inputObject)
  148.     if inputState == Enum.UserInputState.End then
  149.         -- If key up then capture focus in the TextBox so the user can start typing
  150.         chatInput:CaptureFocus()
  151.     end
  152. end
  153.  
  154. -- Disable ROBLOX default chat
  155. game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Chat, false)
  156.  
  157. -- Bind functions
  158. chatMessageEvent.OnClientEvent:connect(addMessage)
  159. game.ReplicatedStorage.ServerBroadcast.OnClientEvent:connect(addPrvtMessage())
  160. chatInput.FocusLost:connect(onFocusLost)
  161. ContextActionService:BindAction("Chatting", onSlashPressed, false, Enum.KeyCode.Slash)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement