Skip to content

Commit

Permalink
feat(addCommand): longString (#597)
Browse files Browse the repository at this point in the history
  • Loading branch information
BerkieBb authored Jul 1, 2024
1 parent cdf840f commit 64615a6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
9 changes: 7 additions & 2 deletions imports/addCommand/server.lua
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion package/server/resource/addCommand/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -55,6 +55,10 @@ function parseArguments(

break;

case 'longString':
value = raw.substring(raw.indexOf(arg as string));
break;

default:
value = arg;
break;
Expand Down

0 comments on commit 64615a6

Please sign in to comment.