This commit is contained in:
Andyyy7666
2022-11-14 00:53:48 +01:00
4 changed files with 717 additions and 1 deletions

39
server/commands.lua Normal file
View File

@@ -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

View File

@@ -274,6 +274,7 @@ function NDCore.Functions.SetActiveCharacter(player, characterId)
inventory = json.decode(i.inventory)
}
end
NDCore.Commands.Refresh(player)
TriggerEvent("ND:characterLoaded", NDCore.Players[player])
TriggerClientEvent("ND:setCharacter", player, NDCore.Players[player])
end