Chaos_Cash

chat.lua

Nov 13th, 2025 (edited)
365
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.31 KB | None | 0 0
  1. local chat = {
  2.     commands = {}
  3. }
  4.  
  5.  
  6.  
  7.  
  8. function chat.newCommand(commandName, commandFunction)
  9.     local superCommand
  10.     local curPos = 1
  11.     local name
  12.     repeat
  13.         local superName = commandName:match(".-%s", curPos)
  14.         if superName then
  15.             curPos = curPos + #superName
  16.             superName = superName:sub(1,-2)
  17.             --print(superName)
  18.             superCommand = ((superCommand or {}).subCommands or chat.commands)[superName]
  19.         else
  20.             name = commandName:sub(curPos, -1)
  21.         end
  22.     until not superName
  23.     print((superCommand or {}).fullName or "none")
  24.    
  25.     local newCommand = {
  26.         name = name,
  27.         fullName = commandName,
  28.         commandFunction = commandFunction,
  29.         subCommands = {},
  30.         subCommandsCount = 0,
  31.         superCommand = superCommand
  32.     }
  33.     if superCommand then
  34.         superCommand.subCommands[name] = newCommand
  35.     else
  36.         chat.commands[commandName] = newCommand
  37.     end
  38. end
  39.  
  40.  
  41.  
  42. local function printCommands(commands, position)
  43.     position = position or 0
  44.     for k,command in pairs(commands) do
  45.         print(string.rep(" ", position) .. command.name)
  46.         printCommands(command.subCommands, position + 2)
  47.     end
  48. end
  49.  
  50.  
  51.  
  52. local function help()
  53.     printCommands(chat.commands)
  54. end
  55.  
  56.  
  57. chat.newCommand("test")
  58. chat.newCommand("test blub")
  59. chat.newCommand("aha")
  60. chat.newCommand("aha tada")
  61. chat.newCommand("aha nein")
  62. chat.newCommand("aha nein blub")
  63.  
  64. --help()
  65.  
Advertisement
Add Comment
Please, Sign In to add comment