mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-16 22:46:03 +01:00
feat(addCommand): longString (#597)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user