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-05-01 17:49:37 +01:00
|
|
|
|
2025-03-01 12:58:43 +00:00
|
|
|
if isStarted(OXLibExport) then
|
|
|
|
|
debugPrint("^6Bridge^7: ^2Registering ^3Command^2 with ^7"..OXLibExport, command)
|
|
|
|
|
lib.addCommand(command, { help = options[1], restricted = options[5] and "group."..options[5] or nil }, options[4])
|
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-03-08 13:44:05 +00:00
|
|
|
debugPrint("^6Bridge^7: ^2Registering ^3Command^2 with ^7"..QBExport, command)
|
|
|
|
|
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
|
|
|
|
|
debugPrint("^6Bridge^7: ^2Registering ^3Command^2 with ^7"..RSGExport, command)
|
|
|
|
|
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-03-08 13:44:05 +00:00
|
|
|
debugPrint("^6Bridge^7: ^2Registering ^3Command^2 with ^7ESX Legacy", command)
|
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
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--- Registers a stash with the active inventory system.
|
2025-03-08 13:44:05 +00:00
|
|
|
--- Supports either OXInv or QSInv.
|
|
|
|
|
---
|
|
|
|
|
--- @param name string Unique stash identifier.
|
|
|
|
|
--- @param label string Display name for the stash.
|
|
|
|
|
--- @param slots number|nil (Optional) Number of slots (default 50).
|
|
|
|
|
--- @param weight number|nil (Optional) Maximum weight (default 4000000).
|
|
|
|
|
--- @param owner string|nil (Optional) Owner identifier for personal stashes.
|
|
|
|
|
--- @param coords table|nil (Optional) Coordinates for the stash location.
|
2025-03-01 12:58:43 +00:00
|
|
|
--- @usage
|
|
|
|
|
--- ```lua
|
2025-03-08 13:44:05 +00:00
|
|
|
--- registerStash(
|
|
|
|
|
--- "playerStash",
|
|
|
|
|
--- "Player Stash",
|
|
|
|
|
--- 100,
|
|
|
|
|
--- 8000000,
|
|
|
|
|
--- "player123",
|
|
|
|
|
--- { x = 100.0, y = 200.0, z = 30.0 }
|
|
|
|
|
--- )
|
2025-03-01 12:58:43 +00:00
|
|
|
--- ```
|
|
|
|
|
function registerStash(name, label, slots, weight, owner, coords)
|
|
|
|
|
if isStarted(OXInv) then
|
|
|
|
|
debugPrint("^6Bridge^7: ^2Registering ^3OX ^2Stash^7:", name, label, owner or nil)
|
|
|
|
|
exports[OXInv]:RegisterStash(name, label, slots or 50, weight or 4000000, owner or nil)
|
2025-05-01 17:49:37 +01:00
|
|
|
|
2025-03-01 12:58:43 +00:00
|
|
|
elseif isStarted(QSInv) then
|
|
|
|
|
debugPrint("^6Bridge^7: ^2Registering ^3QS ^2Stash^7:", name, label)
|
2025-04-29 17:43:37 +01:00
|
|
|
exports[QSInv]:RegisterStash(name, label, slots or 50, weight or 4000000)
|
2025-03-08 13:44:05 +00:00
|
|
|
|
|
|
|
|
--elseif isStarted(CoreInv) then
|
|
|
|
|
-- debugPrint("^6Bridge^7: ^2Registering ^3CoreInv ^2Stash^7:", name, label)
|
|
|
|
|
-- exports[CoreInv]:openHolder(nil, name, 'stash', nil, nil, false, nil)
|
|
|
|
|
|
|
|
|
|
elseif isStarted(OrigenInv) then
|
|
|
|
|
debugPrint("^6Bridge^7: ^2Registering ^3OrigenInv ^2Stash^7:", name, label)
|
|
|
|
|
exports["origen_inventory"]:registerStash(name, label, slots or 50, weight or 4000000)
|
2025-04-30 17:53:26 +01:00
|
|
|
|
|
|
|
|
elseif isStarted(TgiannInv) then
|
|
|
|
|
debugPrint("^6Bridge^7: ^2Registering ^3TgiannInv ^2Stash^7:", name, label)
|
|
|
|
|
exports[TgiannInv]:RegisterStash(name, label, slots or 50, weight or 4000000)
|
2025-05-01 17:49:37 +01:00
|
|
|
|
2025-03-01 12:58:43 +00:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if isServer() then
|
|
|
|
|
--- Registers an event to create an OX stash from the server.
|
2025-03-08 13:44:05 +00:00
|
|
|
--- When triggered, it calls registerStash with the provided parameters.
|
2025-03-01 12:58:43 +00:00
|
|
|
---
|
2025-03-08 13:44:05 +00:00
|
|
|
--- @event server:makeOXStash
|
|
|
|
|
--- @param name string Unique stash identifier.
|
|
|
|
|
--- @param label string Display name for the stash.
|
|
|
|
|
--- @param slots number|nil (Optional) Number of slots.
|
|
|
|
|
--- @param weight number|nil (Optional) Maximum weight.
|
|
|
|
|
--- @param owner string|nil (Optional) Owner identifier.
|
|
|
|
|
--- @param coords table|nil (Optional) Stash coordinates.
|
2025-03-01 12:58:43 +00:00
|
|
|
--- @usage
|
|
|
|
|
--- ```lua
|
2025-05-04 15:40:20 +01:00
|
|
|
--- TriggerEvent(getScript()..":server:makeOXStash", name, label, slots, weight, owner, coords, token)
|
2025-03-01 12:58:43 +00:00
|
|
|
--- ```
|
2025-03-26 21:43:48 +00:00
|
|
|
RegisterNetEvent(getScript()..":server:makeOXStash", function(name, label, slots, weight, owner, coords, token)
|
|
|
|
|
local src = source or nil
|
|
|
|
|
if src then
|
2025-05-05 11:44:51 +01:00
|
|
|
if not checkToken(src, token, "stash", name) then
|
|
|
|
|
return
|
2025-03-26 21:43:48 +00:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2025-03-01 12:58:43 +00:00
|
|
|
registerStash(name, label, slots, weight, owner, coords)
|
|
|
|
|
end)
|
2025-03-08 13:44:05 +00:00
|
|
|
end
|