mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-08-29 01:08:54 +00:00
refactor(es_extended/server/functions): rename err var
This commit is contained in:
@@ -64,16 +64,16 @@ function ESX.RegisterCommand(name, group, cb, allowConsole, suggestion)
|
|||||||
if not command.allowConsole and playerId == 0 then
|
if not command.allowConsole and playerId == 0 then
|
||||||
print(("[^3WARNING^7] ^5%s^0"):format(TranslateCap("commanderror_console")))
|
print(("[^3WARNING^7] ^5%s^0"):format(TranslateCap("commanderror_console")))
|
||||||
else
|
else
|
||||||
local xPlayer, error = ESX.Players[playerId], nil
|
local xPlayer, err = ESX.Players[playerId], nil
|
||||||
|
|
||||||
if command.suggestion then
|
if command.suggestion then
|
||||||
if command.suggestion.validate then
|
if command.suggestion.validate then
|
||||||
if #args ~= #command.suggestion.arguments then
|
if #args ~= #command.suggestion.arguments then
|
||||||
error = TranslateCap("commanderror_argumentmismatch", #args, #command.suggestion.arguments)
|
err = TranslateCap("commanderror_argumentmismatch", #args, #command.suggestion.arguments)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if not error and command.suggestion.arguments then
|
if not err and command.suggestion.arguments then
|
||||||
local newArgs = {}
|
local newArgs = {}
|
||||||
|
|
||||||
for k, v in ipairs(command.suggestion.arguments) do
|
for k, v in ipairs(command.suggestion.arguments) do
|
||||||
@@ -84,7 +84,7 @@ function ESX.RegisterCommand(name, group, cb, allowConsole, suggestion)
|
|||||||
if newArg then
|
if newArg then
|
||||||
newArgs[v.name] = newArg
|
newArgs[v.name] = newArg
|
||||||
else
|
else
|
||||||
error = TranslateCap("commanderror_argumentmismatch_number", k)
|
err = TranslateCap("commanderror_argumentmismatch_number", k)
|
||||||
end
|
end
|
||||||
elseif v.type == "player" or v.type == "playerId" then
|
elseif v.type == "player" or v.type == "playerId" then
|
||||||
local targetPlayer = tonumber(args[k])
|
local targetPlayer = tonumber(args[k])
|
||||||
@@ -103,29 +103,29 @@ function ESX.RegisterCommand(name, group, cb, allowConsole, suggestion)
|
|||||||
newArgs[v.name] = targetPlayer
|
newArgs[v.name] = targetPlayer
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
error = TranslateCap("commanderror_invalidplayerid")
|
err = TranslateCap("commanderror_invalidplayerid")
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
error = TranslateCap("commanderror_argumentmismatch_number", k)
|
err = TranslateCap("commanderror_argumentmismatch_number", k)
|
||||||
end
|
end
|
||||||
elseif v.type == "string" then
|
elseif v.type == "string" then
|
||||||
local newArg = tonumber(args[k])
|
local newArg = tonumber(args[k])
|
||||||
if not newArg then
|
if not newArg then
|
||||||
newArgs[v.name] = args[k]
|
newArgs[v.name] = args[k]
|
||||||
else
|
else
|
||||||
error = TranslateCap("commanderror_argumentmismatch_string", k)
|
err = TranslateCap("commanderror_argumentmismatch_string", k)
|
||||||
end
|
end
|
||||||
elseif v.type == "item" then
|
elseif v.type == "item" then
|
||||||
if ESX.Items[args[k]] then
|
if ESX.Items[args[k]] then
|
||||||
newArgs[v.name] = args[k]
|
newArgs[v.name] = args[k]
|
||||||
else
|
else
|
||||||
error = TranslateCap("commanderror_invaliditem")
|
err = TranslateCap("commanderror_invaliditem")
|
||||||
end
|
end
|
||||||
elseif v.type == "weapon" then
|
elseif v.type == "weapon" then
|
||||||
if ESX.GetWeapon(args[k]) then
|
if ESX.GetWeapon(args[k]) then
|
||||||
newArgs[v.name] = string.upper(args[k])
|
newArgs[v.name] = string.upper(args[k])
|
||||||
else
|
else
|
||||||
error = TranslateCap("commanderror_invalidweapon")
|
err = TranslateCap("commanderror_invalidweapon")
|
||||||
end
|
end
|
||||||
elseif v.type == "any" then
|
elseif v.type == "any" then
|
||||||
newArgs[v.name] = args[k]
|
newArgs[v.name] = args[k]
|
||||||
@@ -140,27 +140,27 @@ function ESX.RegisterCommand(name, group, cb, allowConsole, suggestion)
|
|||||||
elseif v.type == "coordinate" then
|
elseif v.type == "coordinate" then
|
||||||
local coord = tonumber(args[k]:match("(-?%d+%.?%d*)"))
|
local coord = tonumber(args[k]:match("(-?%d+%.?%d*)"))
|
||||||
if not coord then
|
if not coord then
|
||||||
error = TranslateCap("commanderror_argumentmismatch_number", k)
|
err = TranslateCap("commanderror_argumentmismatch_number", k)
|
||||||
else
|
else
|
||||||
newArgs[v.name] = coord
|
newArgs[v.name] = coord
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if v.isValid and not error then
|
if v.isValid and not err then
|
||||||
local candidate = newArgs[v.name]
|
local candidate = newArgs[v.name]
|
||||||
local ok, res = pcall(v.isValid, candidate)
|
local ok, res = pcall(v.isValid, candidate)
|
||||||
if not ok or res ~= true then
|
if not ok or res ~= true then
|
||||||
error = v.err or TranslateCap("commanderror_argumentmismatch")
|
err = v.err or TranslateCap("commanderror_argumentmismatch")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--backwards compatibility
|
--backwards compatibility
|
||||||
if v.validate ~= nil and not v.validate then
|
if v.validate ~= nil and not v.validate then
|
||||||
error = nil
|
err = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
if error then
|
if err then
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -169,11 +169,11 @@ function ESX.RegisterCommand(name, group, cb, allowConsole, suggestion)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if error then
|
if err then
|
||||||
if playerId == 0 then
|
if playerId == 0 then
|
||||||
print(("[^3WARNING^7] %s^7"):format(error))
|
print(("[^3WARNING^7] %s^7"):format(err))
|
||||||
else
|
else
|
||||||
xPlayer.showNotification(error)
|
xPlayer.showNotification(err)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
cb(xPlayer or false, args, function(msg)
|
cb(xPlayer or false, args, function(msg)
|
||||||
|
|||||||
Reference in New Issue
Block a user