Skip to content

Commit

Permalink
feat(client/compat): handle string-indexed options
Browse files Browse the repository at this point in the history
Neither are technically supported, but were possible by design flaw/fluke.
Since somebody at qb decided to utilise this flaw in a recent change, we'll
re-insert the option at the end of the options table.
  • Loading branch information
thelindat committed Mar 12, 2023
1 parent 8d58e85 commit 5532407
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
16 changes: 15 additions & 1 deletion client/compat/qb-target.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,19 @@ local function convert(options)
local distance = options.distance
options = options.options

for _, v in pairs(options) do
-- People may pass options as a hashmap (or mixed, even)
for k, v in pairs(options) do
if type(k) ~= 'number' then
table.insert(options, v)
end
end

for id, v in pairs(options) do
if type(id) ~= 'number' then
options[id] = nil
goto continue
end

v.onSelect = v.action
v.distance = v.distance or distance
v.name = v.name or v.label
Expand Down Expand Up @@ -110,6 +122,8 @@ local function convert(options)
v.citizenid = nil
v.item = nil
v.qtarget = true

::continue::
end

return options
Expand Down
16 changes: 15 additions & 1 deletion client/compat/qtarget.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,19 @@ local function convert(options)
local distance = options.distance
options = options.options

for _, v in pairs(options) do
-- People may pass options as a hashmap (or mixed, even)
for k, v in pairs(options) do
if type(k) ~= 'number' then
table.insert(options, v)
end
end

for id, v in pairs(options) do
if type(id) ~= 'number' then
options[id] = nil
goto continue
end

v.onSelect = v.action
v.distance = v.distance or distance
v.name = v.name or v.label
Expand All @@ -33,6 +45,8 @@ local function convert(options)
v.item = nil
v.required_item = nil
v.qtarget = true

::continue::
end

return options
Expand Down

0 comments on commit 5532407

Please sign in to comment.