2025-03-04 22:28:34 -05:00
local resourceName = "qb-target"
local configValue = BridgeClientConfig.TargetSystem
if ( configValue == "auto" and GetResourceState ( resourceName ) ~= "started" ) or ( configValue ~= "auto" and configValue ~= resourceName ) then return end
2025-03-03 19:09:06 -05:00
if GetResourceState ( 'ox_target' ) == 'started' then return end -- this is for older versions of ox that supported the backwards compatability. As its depricated we dont want to touch that.
2025-01-08 06:33:31 -05:00
local targetDebug = false
local function detectDebugEnabled ()
2025-01-29 01:37:00 +00:00
if BridgeClientConfig.DebugLevel == 2 then
2025-01-08 06:33:31 -05:00
targetDebug = true
end
end
detectDebugEnabled ()
local targetZones = {}
2025-02-24 11:07:52 -05:00
Target = Target or {}
2025-01-08 06:33:31 -05:00
2025-02-05 17:42:50 -06:00
Target.FixOptions = function ( options )
2025-01-08 06:33:31 -05:00
for k , v in pairs ( options ) do
2025-02-05 17:42:50 -06:00
local action = v.onSelect or v.action
local select = function ( entityOrData )
if type ( entityOrData ) == 'table' then
return action ( entityOrData.entity )
end
return action ( entityOrData )
end
2025-02-07 22:38:15 -06:00
options [ k ]. action = select
2025-02-26 12:55:16 -06:00
options [ k ]. job = v.job or v.groups
2025-01-08 06:33:31 -05:00
end
2025-02-05 17:42:50 -06:00
return options
end
Target.AddGlobalPlayer = function ( options )
options = Target.FixOptions ( options )
2025-01-08 06:33:31 -05:00
exports [ 'qb-target' ]: AddGlobalPlayer ({
2025-01-25 17:59:19 -05:00
options = options ,
distance = options.distance or 1.5
})
end
Target.AddGlobalVehicle = function ( options )
2025-02-05 17:42:50 -06:00
options = Target.FixOptions ( options )
2025-01-25 17:59:19 -05:00
exports [ 'qb-target' ]: AddGlobalVehicle ({
2025-01-08 06:33:31 -05:00
options = options ,
distance = options.distance or 1.5
})
end
2025-02-20 14:50:27 -05:00
Target.RemoveGlobalVehicle = function ( options )
local assembledLables = {}
for k , v in pairs ( options ) do
table.insert ( assembledLables , v.label )
end
exports [ 'qb-target' ]: RemoveGlobalVehicle ( assembledLables )
end
2025-01-08 06:33:31 -05:00
Target.AddLocalEntity = function ( entities , options )
2025-02-05 17:42:50 -06:00
options = Target.FixOptions ( options )
2025-01-08 06:33:31 -05:00
exports [ 'qb-target' ]: AddTargetEntity ( entities , {
options = options ,
distance = options.distance or 1.5
})
end
Target.AddModel = function ( models , options )
2025-02-05 17:42:50 -06:00
options = Target.FixOptions ( options )
2025-01-08 06:33:31 -05:00
exports [ 'qb-target' ]: AddTargetModel ( models , {
options = options ,
distance = options.distance or 1.5 ,
})
end
Target.AddBoxZone = function ( name , coords , size , heading , options )
2025-02-05 17:42:50 -06:00
options = Target.FixOptions ( options )
2025-01-08 06:33:31 -05:00
exports [ 'qb-target' ]: AddBoxZone ( name , coords , size.x , size.y , {
name = name ,
debugPoly = targetDebug ,
heading = heading ,
minZ = coords.z - ( size.x * 0.5 ),
maxZ = coords.z + ( size.x * 0.5 ),
}, {
options = options ,
distance = options.distance or 1.5 ,
})
table.insert ( targetZones , { name = name , creator = GetInvokingResource () })
end
Target.RemoveGlobalPlayer = function ()
exports [ 'qb-target' ]: RemoveGlobalPlayer ()
end
Target.RemoveLocalEntity = function ( entity )
exports [ 'qb-target' ]: RemoveTargetEntity ( entity )
end
Target.RemoveModel = function ( model )
exports [ 'qb-target' ]: RemoveTargetModel ( model )
end
Target.RemoveZone = function ( name )
for _ , data in pairs ( targetZones ) do
if data.name == name then
exports [ 'qb-target' ]: RemoveZone ( name )
table.remove ( targetZones , _ )
break
end
end
end
AddEventHandler ( 'onResourceStop' , function ( resource )
2025-01-08 06:53:55 -05:00
if resource == GetCurrentResourceName () then
2025-01-08 06:33:31 -05:00
for _ , target in pairs ( targetZones ) do
if target.creator == resource then
exports [ 'qb-target' ]: RemoveZone ( target.name )
end
end
targetZones = {}
end
end )