feat(addCommand): longString (#597)

This commit is contained in:
BerkieBb
2024-07-01 03:42:21 +02:00
committed by GitHub
parent cdf840fc68
commit 64615a671e
2 changed files with 12 additions and 3 deletions

View File

@@ -1,7 +1,7 @@
---@class OxCommandParams
---@field name string
---@field help? string
---@field type? 'number' | 'playerId' | 'string'
---@field type? 'number' | 'playerId' | 'string' | 'longString'
---@field optional? boolean
---@class OxCommandProperties
@@ -30,7 +30,8 @@ end)
local function parseArguments(source, args, raw, params)
if not params then return args end
for i = 1, #params do
local paramsNum = #params
for i = 1, paramsNum do
local arg, param = args[i], params[i]
local value
@@ -44,6 +45,9 @@ local function parseArguments(source, args, raw, params)
if not value or not DoesPlayerExist(value--[[@as string]]) then
value = false
end
elseif param.type == 'longString' and i == paramsNum then
local start = raw:find(arg, 1, true)
value = start and raw:sub(start)
else
value = arg
end
@@ -131,6 +135,7 @@ function lib.addCommand(commandName, properties, cb, ...)
end
if properties then
---@diagnostic disable-next-line: inject-field
properties.name = ('/%s'):format(commandName)
properties.restricted = nil
registeredCommands[totalCommands] = properties

View File

@@ -5,7 +5,7 @@ type OxCommandArguments = Record<string | number, string | number | boolean>;
interface OxCommandParams {
name: string;
help?: string;
paramType?: 'number' | 'playerId' | 'string';
paramType?: 'number' | 'playerId' | 'string' | 'longString';
optional?: boolean;
}
@@ -55,6 +55,10 @@ function parseArguments(
break;
case 'longString':
value = raw.substring(raw.indexOf(arg as string));
break;
default:
value = arg;
break;