Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local chat = {
- commands = {}
- }
- function chat.newCommand(commandName, commandFunction)
- local superCommand
- local curPos = 1
- local name
- repeat
- local superName = commandName:match(".-%s", curPos)
- if superName then
- curPos = curPos + #superName
- superName = superName:sub(1,-2)
- --print(superName)
- superCommand = ((superCommand or {}).subCommands or chat.commands)[superName]
- else
- name = commandName:sub(curPos, -1)
- end
- until not superName
- print((superCommand or {}).fullName or "none")
- local newCommand = {
- name = name,
- fullName = commandName,
- commandFunction = commandFunction,
- subCommands = {},
- subCommandsCount = 0,
- superCommand = superCommand
- }
- if superCommand then
- superCommand.subCommands[name] = newCommand
- else
- chat.commands[commandName] = newCommand
- end
- end
- local function printCommands(commands, position)
- position = position or 0
- for k,command in pairs(commands) do
- print(string.rep(" ", position) .. command.name)
- printCommands(command.subCommands, position + 2)
- end
- end
- local function help()
- printCommands(chat.commands)
- end
- chat.newCommand("test")
- chat.newCommand("test blub")
- chat.newCommand("aha")
- chat.newCommand("aha tada")
- chat.newCommand("aha nein")
- chat.newCommand("aha nein blub")
- --help()
Advertisement
Add Comment
Please, Sign In to add comment