tweak: command functions

This commit is contained in:
Andyyy7666
2022-11-30 03:35:03 +01:00
parent 44d1351a5c
commit 97bf116d30
2 changed files with 33 additions and 48 deletions

View File

@@ -1,39 +1,5 @@
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

@@ -345,23 +345,42 @@ function NDCore.Functions.UpdateLastLocation(characterId, location)
return result
end
-- Update the characters clothing into the database.
function NDCore.Functions.UpdateClothes(characterId, clothing)
local result = MySQL.query.await("UPDATE characters SET clothing = ? WHERE character_id = ? LIMIT 1", {json.encode(clothing), characterId})
return result
function NDCore.Functions.AddCommand(name, help, callback, argsrequired, arguments)
local commandName = name:lower()
if NDCore.Commands[commandName] then print("/" .. commandName .. " has already been registered.") return end
local arguments = arguments or {}
RegisterCommand(commandName, 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[commandName] = {
name = commandName,
help = help,
callback = callback,
argsrequired = argsrequired,
arguments = arguments
}
end
-- Updates the player's data
function NDCore.Functions.SetPlayerData(player, key, value)
if not key then return end
local character = NDCore.Players[player]
character[key] = value
if key == "cash" then
MySQL.query.await("UPDATE characters SET cash = ? WHERE character_id = ?", {tonumber(value), character.id})
elseif key == "bank" then
MySQL.query.await("UPDATE characters SET bank = ? WHERE character_id = ?", {tonumber(value), character.id})
function NDCore.Functions.RefreshCommands(source)
local suggestions = {}
for command, info in pairs(NDCore.Commands) do
suggestions[#suggestions + 1] = {
name = "/" .. command,
help = info.help,
params = info.arguments
}
end
TriggerClientEvent("ND:updateCharacter", player, NDCore.Players[player])
TriggerClientEvent("chat:addSuggestions", source, suggestions)
end
function NDCore.Functions.IsPlayerAdmin(src)