Advertisement
RomashkaHEHE

Chat Commands

Nov 11th, 2022 (edited)
908
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.01 KB | Gaming | 0 0
  1. _G.CCSession = (_G.CCSession or 0) + 1
  2. returnList = {
  3.     session = _G.CCSession,
  4.     commandSymbol = ';',
  5.     commandsList = {},
  6.     started = false,
  7.     enabled = true,
  8.     deleteMessages = true
  9. }
  10.  
  11. function returnList:setCommand(commandName, ...) --lowerString, helpText, Callback
  12.     local settings;
  13.     local Callback;
  14.     local lowerString;
  15.     local description;
  16.     local helpText;
  17.     if type(commandName) == 'table' then
  18.         settings = commandName
  19.         commandName = settings.Name
  20.         Callback = settings.Callback
  21.         lowerString = settings.lowerString
  22.         description = settings.description or ''
  23.         helpText = settings.helpText or description
  24.     else
  25.         settings = {...}
  26.         Callback = settings[#settings]
  27.         settings[#settings] = nil
  28.         lowerString = settings[1]
  29.         description = settings[2] or ''
  30.         helpText = settings[3] or description
  31.     end
  32.     if type(commandName) == 'string' and type(Callback) == 'function' then
  33.         if commandName ~= '' then
  34.             returnList.commandsList[commandName] = {Callback = Callback, lowerString = lowerString, description = description, helpText = helpText}
  35.             return returnList.commandsList[commandName]
  36.         end
  37.     end
  38.     return 'error'
  39. end
  40. function returnList:getCommand(commandName)
  41.     if commandName then
  42.         if returnList.commandsList[commandName] then
  43.             return returnList.commandsList[commandName]
  44.         end
  45.         for cmdName, settings in pairs(returnList.commandsList) do
  46.             if string.lower(cmdName) == string.lower(commandName) and settings.lowerString then
  47.                 return returnList.commandsList[cmdName]
  48.             end
  49.         end
  50.     end
  51.     return nil
  52. end
  53.  
  54. function returnList:systemMessage(msg)
  55.     game.StarterGui:SetCore("ChatMakeSystemMessage", {
  56.         Text = "[CC] "..tostring(msg),
  57.         Color = Color3.fromRGB(255,255,255),
  58.         Font = Enum.Font.Cartoon,
  59.         FontSize = Enum.FontSize.Size24,
  60.     })
  61. end
  62.  
  63. function returnList:Start()
  64.     returnList.started = true
  65.     returnList.Start = function() returnList:systemMessage('Alredy started') end
  66.     returnList.commandsList[''] = {Callback = function() returnList:systemMessage('Chat Commands by RomashkaHEHE') end}
  67.     returnList:setCommand('list', true, 'print all commands', function()
  68.         print()
  69.         for cmdName, settings in pairs(returnList.commandsList) do
  70.             if cmdName ~= '' then
  71.                 print(cmdName, settings.description ~= '' and '- '..settings.description or '')
  72.             end
  73.         end
  74.         print()
  75.     end)
  76.     returnList:setCommand('help', true, 'saying helpText', function(command)
  77.         local command = returnList:getCommand(command)
  78.         if command then
  79.             returnList:systemMessage(command.helpText ~= '' and command.helpText or "There's no helpText :(")
  80.         else
  81.             returnList:systemMessage('Wrong command name :( U can use list for more information')
  82.         end
  83.     end)
  84.  
  85.     returnList:systemMessage('Command symbole: '..returnList.commandSymbol)
  86.     returnList:systemMessage('Use the "list" to print all commands in DEV console (F9)')
  87.     returnList:systemMessage('Use the "help Command_Name" to get a description of the command')
  88.  
  89.     _G.chatHookFunc = function(self, ...)
  90.         local arguments = {...}
  91.         if returnList.enabled and self.Name == 'SayMessageRequest' and string.lower(getnamecallmethod()) == 'fireserver' and type(returnList.commandSymbol) == 'string' and arguments[1] then
  92.             local message = arguments[1]
  93.             if string.sub(message, 1, #returnList.commandSymbol) == returnList.commandSymbol then
  94.                 message = string.sub(message, #returnList.commandSymbol+1, #message)
  95.                 local gmatch = string.gmatch(message, '%S+')
  96.                 local command = gmatch() or ''
  97.                 local commandArguments = {}
  98.                 for word in gmatch do
  99.                     table.insert(commandArguments, word)
  100.                 end
  101.                 local command = returnList:getCommand(command)
  102.                 if command then
  103.                     command.Callback(unpack(commandArguments))
  104.                 end
  105.                 if returnList.deleteMessages then
  106.                     return nil
  107.                 end
  108.             end
  109.         end
  110.         return _G.chatHook(self, ...)
  111.     end
  112.     if not _G.chatHook then
  113.         _G.chatHook = hookmetamethod(game, '__namecall', function(self, ...)
  114.             if _G.chatHookFunc then
  115.                 return _G.chatHookFunc(self, ...)
  116.             end
  117.             return _G.chatHook(self, ...)
  118.         end)
  119.     end
  120. end
  121.  
  122. return returnList
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement