From a345489a1a61192bfead01322ac5db5b2f84049e Mon Sep 17 00:00:00 2001 From: WLVF <65689785+WLVF@users.noreply.github.com> Date: Fri, 4 Nov 2022 22:02:59 -0400 Subject: [PATCH] New Command Loader Pog --- server/commands.lua | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 server/commands.lua diff --git a/server/commands.lua b/server/commands.lua new file mode 100644 index 0000000..6c284b9 --- /dev/null +++ b/server/commands.lua @@ -0,0 +1,39 @@ +NDCore.Commands = {} +NDCore.Commands.Registry = {} + +function NDCore.Commands.Add(name, help, arguments, argsrequired, callback, ...) + RegisterCommand(name, function(source, args, rawCommand) + if argsrequired and #args < #arguments then + return TriggerClientEvent("chat:addMessage", source, { + color = {255, 0, 0}, + multiline = true, + args = {"System", "All arguments must be filled out!"} + }) + end + callback(source, args, rawCommand) + end, false) + + NDCore.Commands.Registry[name:lower()] = { + name = name:lower(), + help = help, + arguments = arguments, + argsrequired = argsrequired, + callback = callback + } +end + +function NDCore.Commands.Refresh(source) + local src = source + local Player = NDCore.Functions.GetPlayer(src) + local suggestions = {} + if Player then + for command, info in pairs(NDCore.Commands.Registry) do + suggestions[#suggestions + 1] = { + name = "/" .. command, + help = info.help, + params = info.arguments + } + end + TriggerClientEvent("chat:addSuggestions", src, suggestions) + end +end \ No newline at end of file