mirror of
https://github.com/qbcore-fivem/qb-core.git
synced 2026-09-04 17:23:31 +00:00
Merge pull request #737 from BerkieBb/main
feat(server/commands): multiple permission support and fix argsrequired
This commit is contained in:
+31
-5
@@ -13,17 +13,43 @@ end)
|
|||||||
|
|
||||||
-- Register & Refresh Commands
|
-- 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
|
local restricted = true -- Default to restricted for all commands
|
||||||
if not permission then permission = 'user' end -- some commands don't pass permission level
|
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
|
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
|
RegisterCommand(name, function(source, args, rawCommand) -- Register command within fivem
|
||||||
ExecuteCommand(('add_ace qbcore.%s command.%s allow'):format(permission, name))
|
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
|
end
|
||||||
|
|
||||||
QBCore.Commands.List[name:lower()] = {
|
QBCore.Commands.List[name:lower()] = {
|
||||||
name = name:lower(),
|
name = name:lower(),
|
||||||
permission = tostring(permission:lower()),
|
permission = permission,
|
||||||
help = help,
|
help = help,
|
||||||
arguments = arguments,
|
arguments = arguments,
|
||||||
argsrequired = argsrequired,
|
argsrequired = argsrequired,
|
||||||
|
|||||||
Reference in New Issue
Block a user