2025-03-01 12:58:43 +00:00
|
|
|
|
|
|
|
|
--- Registers a command with the active command system.
|
2025-03-08 13:44:05 +00:00
|
|
|
--- This function supports multiple command systems (OXLib, qb-core, ESX Legacy).
|
2025-03-01 12:58:43 +00:00
|
|
|
---
|
|
|
|
|
--- @param command string The name of the command to register.
|
|
|
|
|
--- @param options table A table containing command options.
|
2025-03-08 13:44:05 +00:00
|
|
|
--- - help (`string`): The help description for the command.
|
|
|
|
|
--- - params (`table`): A table of parameters for the command.
|
|
|
|
|
--- - callback (`function`): The function to execute when the command is called.
|
|
|
|
|
--- - autocomplete (`function|nil`): (Optional) A function for autocompletion.
|
|
|
|
|
--- - restrictedGroup (`string|nil`): (Optional) The user group required to execute the command.
|
2025-03-01 12:58:43 +00:00
|
|
|
---
|
|
|
|
|
--- @usage
|
2025-03-08 13:44:05 +00:00
|
|
|
--- ```lua
|
2025-03-01 12:58:43 +00:00
|
|
|
--- registerCommand("greet", {
|
|
|
|
|
--- "Greets the player",
|
|
|
|
|
--- { name = "name", help = "Name of the player to greet" },
|
2025-03-08 13:44:05 +00:00
|
|
|
--- function(source, args) print("Hello, "..args[1].."!") end,
|
2025-03-01 12:58:43 +00:00
|
|
|
--- nil,
|
|
|
|
|
--- "admin"
|
|
|
|
|
--- })
|
|
|
|
|
--- ```
|
|
|
|
|
function registerCommand(command, options)
|
2025-06-20 18:03:08 +01:00
|
|
|
local commandResource = ""
|
2025-03-01 12:58:43 +00:00
|
|
|
if isStarted(OXLibExport) then
|
2025-06-20 18:03:08 +01:00
|
|
|
commandResource = OXLibExport
|
2025-08-14 16:33:02 +01:00
|
|
|
lib.addCommand(command, { help = options[1], restricted = options[5] and "group."..options[5] or nil }, options[3])
|
2025-05-01 17:49:37 +01:00
|
|
|
|
2025-03-01 12:58:43 +00:00
|
|
|
elseif isStarted(QBExport) and not isStarted(QBXExport) then
|
2025-06-20 18:03:08 +01:00
|
|
|
commandResource = QBExport
|
2025-03-08 13:44:05 +00:00
|
|
|
Core.Commands.Add(command, options[1], options[2], options[3], options[4], options[5] or nil)
|
2025-05-01 17:49:37 +01:00
|
|
|
|
|
|
|
|
elseif isStarted(RSGExport) then
|
2025-06-20 18:03:08 +01:00
|
|
|
commandResource = RSGExport
|
2025-05-01 17:49:37 +01:00
|
|
|
Core.Commands.Add(command, options[1], options[2], options[3], options[4], options[5] or nil)
|
|
|
|
|
|
2025-03-01 12:58:43 +00:00
|
|
|
elseif isStarted(ESXExport) then
|
2025-06-20 18:03:08 +01:00
|
|
|
commandResource = ESXExport
|
2025-03-01 12:58:43 +00:00
|
|
|
ESX.RegisterCommand(command, options[5] or 'admin', function(xPlayer, args, showError)
|
|
|
|
|
options[4](xPlayer.source, args, showError)
|
|
|
|
|
end, false, { help = options[1] })
|
2025-05-01 17:49:37 +01:00
|
|
|
|
2025-03-01 12:58:43 +00:00
|
|
|
end
|
2025-06-20 18:03:08 +01:00
|
|
|
if commandResource ~= "" then
|
|
|
|
|
debugPrint("^6Bridge^7: ^2Registering ^3Command^2 with ^4"..commandResource.."^7:", "^7/"..command)
|
|
|
|
|
else
|
|
|
|
|
print("^1ERROR^7: ^1Couldn't find supported framework to register command^7:", "/"..command)
|
|
|
|
|
end
|
2025-05-07 12:58:39 +01:00
|
|
|
end
|