mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-17 06:56:03 +01:00
fix(addCommand): catch errors in command handler
+ additional minor changes. Use DoesPlayerExist native. Mark addCommand cb as async.
This commit is contained in:
@@ -41,7 +41,7 @@ local function parseArguments(source, args, raw, params)
|
||||
elseif param.type == 'playerId' then
|
||||
value = arg == 'me' and source or tonumber(arg)
|
||||
|
||||
if not value or not GetPlayerGuid(value--[[@as string]]) then
|
||||
if not value or not DoesPlayerExist(value--[[@as string]]) then
|
||||
value = false
|
||||
end
|
||||
else
|
||||
@@ -102,7 +102,11 @@ function lib.addCommand(commandName, properties, cb, ...)
|
||||
|
||||
if not args then return end
|
||||
|
||||
cb(source, args, raw)
|
||||
local success, resp = pcall(cb, source, args, raw)
|
||||
|
||||
if not success then
|
||||
Citizen.Trace(("^1command '%s' failed to execute!\n%s"):format(string.strsplit(' ', raw) or raw, resp))
|
||||
end
|
||||
end
|
||||
|
||||
for i = 1, numCommands do
|
||||
|
||||
Reference in New Issue
Block a user