mirror of
https://github.com/qbcore-fivem/qb-core.git
synced 2026-08-29 01:01:24 +00:00
feat(server/commands): multiple permission support and fix argsrequired
This commit is contained in:
+31
-5
@@ -13,17 +13,43 @@ end)
|
||||
|
||||
-- Register & Refresh Commands
|
||||
|
||||
function QBCore.Commands.Add(name, help, arguments, argsrequired, callback, permission)
|
||||
function QBCore.Commands.Add(name, help, arguments, argsrequired, callback, permission, ...)
|
||||
local restricted = true -- Default to restricted for all commands
|
||||
if not permission then permission = 'user' end -- some commands don't pass permission level
|
||||
if permission == 'user' then restricted = false end -- allow all users to use command
|
||||
RegisterCommand(name, callback, restricted) -- Register command within fivem
|
||||
if not QBCore.Commands.IgnoreList[permission] then -- only create aces for extra perm levels
|
||||
ExecuteCommand(('add_ace qbcore.%s command.%s allow'):format(permission, name))
|
||||
|
||||
RegisterCommand(name, function(source, args, rawCommand) -- Register command within fivem
|
||||
if argsrequired and #args < #arguments then
|
||||
return TriggerClientEvent('chat:addMessage', source, {
|
||||
color = {255, 0, 0},
|
||||
multiline = true,
|
||||
args = {"System", Lang:t("error.missing_args2")}
|
||||
})
|
||||
end
|
||||
callback(source, args, rawCommand)
|
||||
end, restricted)
|
||||
|
||||
local extraPerms = ... and table.pack(...) or nil
|
||||
if extraPerms then
|
||||
extraPerms[extraPerms.n + 1] = permission -- The `n` field is the number of arguments in the packed table
|
||||
extraPerms.n += 1
|
||||
permission = extraPerms
|
||||
for i = 1, permission.n do
|
||||
if not QBCore.Commands.IgnoreList[permission[i]] then -- only create aces for extra perm levels
|
||||
ExecuteCommand(('add_ace qbcore.%s command.%s allow'):format(permission[i], name))
|
||||
end
|
||||
end
|
||||
permission.n = nil
|
||||
else
|
||||
permission = tostring(permission:lower())
|
||||
if not QBCore.Commands.IgnoreList[permission] then -- only create aces for extra perm levels
|
||||
ExecuteCommand(('add_ace qbcore.%s command.%s allow'):format(permission, name))
|
||||
end
|
||||
end
|
||||
|
||||
QBCore.Commands.List[name:lower()] = {
|
||||
name = name:lower(),
|
||||
permission = tostring(permission:lower()),
|
||||
permission = permission,
|
||||
help = help,
|
||||
arguments = arguments,
|
||||
argsrequired = argsrequired,
|
||||
|
||||
Reference in New Issue
Block a user