mirror of
https://github.com/ND-Framework/ND_Core.git
synced 2026-08-17 05:56:01 +01:00
tweak: command functions
This commit is contained in:
@@ -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
|
||||||
end
|
end
|
||||||
@@ -345,23 +345,42 @@ function NDCore.Functions.UpdateLastLocation(characterId, location)
|
|||||||
return result
|
return result
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Update the characters clothing into the database.
|
function NDCore.Functions.AddCommand(name, help, callback, argsrequired, arguments)
|
||||||
function NDCore.Functions.UpdateClothes(characterId, clothing)
|
local commandName = name:lower()
|
||||||
local result = MySQL.query.await("UPDATE characters SET clothing = ? WHERE character_id = ? LIMIT 1", {json.encode(clothing), characterId})
|
if NDCore.Commands[commandName] then print("/" .. commandName .. " has already been registered.") return end
|
||||||
return result
|
|
||||||
|
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
|
end
|
||||||
|
|
||||||
-- Updates the player's data
|
function NDCore.Functions.RefreshCommands(source)
|
||||||
function NDCore.Functions.SetPlayerData(player, key, value)
|
local suggestions = {}
|
||||||
if not key then return end
|
for command, info in pairs(NDCore.Commands) do
|
||||||
local character = NDCore.Players[player]
|
suggestions[#suggestions + 1] = {
|
||||||
character[key] = value
|
name = "/" .. command,
|
||||||
if key == "cash" then
|
help = info.help,
|
||||||
MySQL.query.await("UPDATE characters SET cash = ? WHERE character_id = ?", {tonumber(value), character.id})
|
params = info.arguments
|
||||||
elseif key == "bank" then
|
}
|
||||||
MySQL.query.await("UPDATE characters SET bank = ? WHERE character_id = ?", {tonumber(value), character.id})
|
|
||||||
end
|
end
|
||||||
TriggerClientEvent("ND:updateCharacter", player, NDCore.Players[player])
|
TriggerClientEvent("chat:addSuggestions", source, suggestions)
|
||||||
end
|
end
|
||||||
|
|
||||||
function NDCore.Functions.IsPlayerAdmin(src)
|
function NDCore.Functions.IsPlayerAdmin(src)
|
||||||
|
|||||||
Reference in New Issue
Block a user