Refactor target system client logic and zone functions
Simplifies debug flag initialization and resource state checks in both ox_target and qb-target client scripts. Updates Target.FixOptions to streamline option handling and canInteract logic. Target.AddBoxZone and Target.AddSphereZone now return the zone name for improved usability.
This commit is contained in:
1 parent
05bee5e743
commit
19911d9173
2 files changed
+14
-34
No files matched your search
@@ -2,33 +2,23 @@
|
||||
local resourceName = "ox_target"
|
||||
if GetResourceState(resourceName) == 'missing' then return end
|
||||
|
||||
local targetDebug = false
|
||||
local function detectDebugEnabled()
|
||||
if BridgeSharedConfig.DebugLevel == 2 then
|
||||
targetDebug = true
|
||||
end
|
||||
end
|
||||
|
||||
detectDebugEnabled()
|
||||
|
||||
local ox_target = exports.ox_target
|
||||
local targetZones = {}
|
||||
|
||||
Target = Target or {}
|
||||
local targetDebug = BridgeSharedConfig and BridgeSharedConfig.DebugLevel == 2 or false
|
||||
local targetZones = {}
|
||||
local ox_target = exports.ox_target
|
||||
|
||||
---This is an internal function that is used to fix the options passed to fit alternative target systems, for example qb-ox or ox-qb etc.
|
||||
---@param options table
|
||||
---@return table
|
||||
Target.FixOptions = function(options)
|
||||
for k, v in pairs(options) do
|
||||
for _, v in pairs(options) do
|
||||
local action = v.onSelect or v.action
|
||||
if not action then
|
||||
if not action then
|
||||
local _type = v.type
|
||||
if _type and _type == "server" then
|
||||
v.serverEvent = v.event
|
||||
v.event = nil
|
||||
end
|
||||
|
||||
else
|
||||
local select = function(entityOrData)
|
||||
if type(entityOrData) == 'table' then
|
||||
@@ -37,17 +27,15 @@ Target.FixOptions = function(options)
|
||||
return action(entityOrData)
|
||||
end
|
||||
v.onSelect = select
|
||||
|
||||
end
|
||||
v.groups = v.job or v.groups
|
||||
local optionsCanInteract = v.canInteract
|
||||
if optionsCanInteract then
|
||||
local optionsCanInteract = v.canInteract
|
||||
if optionsCanInteract then
|
||||
local id = Target.CreateCanInteract(optionsCanInteract)
|
||||
v.canInteract = function(...)
|
||||
return Target.CanInteract(id, ...)
|
||||
end
|
||||
end
|
||||
-- print(json.encode(v))
|
||||
end
|
||||
return options
|
||||
end
|
||||
|
||||
@@ -1,20 +1,11 @@
|
||||
---@diagnostic disable: duplicate-set-field
|
||||
local resourceName = "qb-target"
|
||||
if GetResourceState(resourceName) == 'missing' then return end
|
||||
if GetResourceState("ox_target") == 'started' then return end
|
||||
|
||||
local targetDebug = false
|
||||
local function detectDebugEnabled()
|
||||
if BridgeSharedConfig.DebugLevel == 2 then
|
||||
targetDebug = true
|
||||
end
|
||||
end
|
||||
|
||||
detectDebugEnabled()
|
||||
|
||||
local targetZones = {}
|
||||
if GetResourceState("ox_target") ~= 'missing' then return end
|
||||
|
||||
Target = Target or {}
|
||||
local targetDebug = BridgeSharedConfig and BridgeSharedConfig.DebugLevel == 2 or false
|
||||
local targetZones = {}
|
||||
local qb_target = exports['qb-target']
|
||||
|
||||
function GetLargestDistance(data)
|
||||
@@ -27,7 +18,6 @@ function GetLargestDistance(data)
|
||||
return largestDistance ~= -1 and largestDistance or 2.0
|
||||
end
|
||||
|
||||
|
||||
---This is an internal function that is used to fix the options passed to fit alternative target systems, for example qb-ox or ox-qb etc.
|
||||
---@param options table
|
||||
---@return table
|
||||
@@ -50,8 +40,8 @@ Target.FixOptions = function(options)
|
||||
options[k].action = select
|
||||
options[k].job = v.job or v.groups
|
||||
options[k].jobType = v.jobType
|
||||
local optionsCanInteract = v.canInteract
|
||||
if optionsCanInteract then
|
||||
local optionsCanInteract = v.canInteract
|
||||
if optionsCanInteract then
|
||||
local id = Target.CreateCanInteract(optionsCanInteract)
|
||||
v.canInteract = function(...)
|
||||
return Target.CanInteract(id, ...)
|
||||
@@ -188,6 +178,7 @@ Target.AddBoxZone = function(name, coords, size, heading, options, debug)
|
||||
distance = GetLargestDistance(options),
|
||||
})
|
||||
table.insert(targetZones, { name = name, creator = GetInvokingResource() })
|
||||
return name
|
||||
end
|
||||
|
||||
---This will add a circle zone to the target system. This is useful for when you want to add target options to a specific area.
|
||||
@@ -205,6 +196,7 @@ Target.AddSphereZone = function(name, coords, radius, options, debug)
|
||||
distance = GetLargestDistance(options),
|
||||
})
|
||||
table.insert(targetZones, { name = name, creator = GetInvokingResource() })
|
||||
return name
|
||||
end
|
||||
|
||||
---This will remove target options from a specific zone.
|
||||
|
||||
Reference in new issue
Block a user