structure

arrangement's moved around, easier to find. Touched up the notes
This commit is contained in:
MrNewb committed 2025-04-08 19:27:34 -04:00
1 parent 526516031d
commit 24cb04a01b
2 files changed
+104 -73

No files matched your search

+40 -44
View File
@@ -17,6 +17,9 @@ local targetZones = {}
Target = Target or {} Target = Target or {}
---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) Target.FixOptions = function(options)
for k, v in pairs(options) do for k, v in pairs(options) do
local action = v.onSelect or v.action local action = v.onSelect or v.action
@@ -31,29 +34,34 @@ Target.FixOptions = function(options)
return options return options
end end
---comment ---This will add target options to players.
---@param options table ---@param options table
---@return nil
Target.AddGlobalPlayer = function(options) Target.AddGlobalPlayer = function(options)
options = Target.FixOptions(options) options = Target.FixOptions(options)
ox_target:addGlobalPlayer(options) ox_target:addGlobalPlayer(options)
end end
---This will remove target options from all players.
Target.RemoveGlobalPlayer = function()
---@diagnostic disable-next-line: missing-parameter
ox_target:removeGlobalPlayer()
end
---This will toggle the targeting system on or off. This is useful for when you want to disable the targeting system for a specific player entirely.
---@param bool boolean
Target.DisableTargeting = function(bool) Target.DisableTargeting = function(bool)
ox_target:disableTargeting(bool) ox_target:disableTargeting(bool)
end end
---comment ---This will add taget options to all vehicles.
---@param options table ---@param options table
---@return nil
Target.AddGlobalVehicle = function(options) Target.AddGlobalVehicle = function(options)
options = Target.FixOptions(options) options = Target.FixOptions(options)
ox_target:addGlobalVehicle(options) ox_target:addGlobalVehicle(options)
end end
---comment ---This will remove target options from all vehicles.
---@param options table ---@param options table
---@return nil
Target.RemoveGlobalVehicle = function(options) Target.RemoveGlobalVehicle = function(options)
local assembledLables = {} local assembledLables = {}
for k, v in pairs(options) do for k, v in pairs(options) do
@@ -62,31 +70,40 @@ Target.RemoveGlobalVehicle = function(options)
ox_target:removeGlobalVehicle(assembledLables) ox_target:removeGlobalVehicle(assembledLables)
end end
---comment ---This will generate targets on non networked entites with the passed options.
---@param entities table ---@param entities number | table
---@param options table ---@param options table
---@return nil
Target.AddLocalEntity = function(entities, options) Target.AddLocalEntity = function(entities, options)
options = Target.FixOptions(options) options = Target.FixOptions(options)
ox_target:addLocalEntity(entities, options) ox_target:addLocalEntity(entities, options)
end end
---comment ---This will remove the target options from a local entity. This is useful for when you want to remove target options from a specific entity.
---@param models table ---@param entity any
Target.RemoveLocalEntity = function(entity)
ox_target:removeLocalEntity(entity)
end
---This will add target options to all specified models. This is useful for when you want to add target options to all models of a specific type.
---@param models number | table
---@param options table ---@param options table
---@return nil
Target.AddModel = function(models, options) Target.AddModel = function(models, options)
options = Target.FixOptions(options) options = Target.FixOptions(options)
ox_target:addModel(models, options) ox_target:addModel(models, options)
end end
---comment ---This will remove target options from all specified models.
---@param model number
Target.RemoveModel = function(model)
ox_target:removeModel(model)
end
---This will add a box zone to the target system. This is useful for when you want to add target options to a specific area.
---@param name string ---@param name string
---@param coords table ---@param coords table
---@param size table ---@param size table
---@param heading number ---@param heading number
---@param options table ---@param options table
---@return number
Target.AddBoxZone = function(name, coords, size, heading, options) Target.AddBoxZone = function(name, coords, size, heading, options)
options = Target.FixOptions(options) options = Target.FixOptions(options)
local target = ox_target:addBoxZone({ local target = ox_target:addBoxZone({
@@ -100,13 +117,11 @@ Target.AddBoxZone = function(name, coords, size, heading, options)
return target return target
end end
---comment ---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.
---@param name string ---@param name string
---@param coords vector3 ---@param coords table
---@param radius number ---@param radius number
---@param heading number -- unused, but kept for compatibility
---@param options table ---@param options table
---@return number
Target.AddSphereZone = function(name, coords, radius, heading, options) Target.AddSphereZone = function(name, coords, radius, heading, options)
options = Target.FixOptions(options) options = Target.FixOptions(options)
local target = ox_target:addSphereZone({ local target = ox_target:addSphereZone({
@@ -120,28 +135,10 @@ Target.AddSphereZone = function(name, coords, radius, heading, options)
return target return target
end end
Target.RemoveGlobalPlayer = function() ---This will remove target options from a specific zone.
ox_target:removeGlobalPlayer()
end
---comment
---@param entity number
---@return nil
Target.RemoveLocalEntity = function(entity)
ox_target:removeLocalEntity(entity)
end
---comment
---@param model string
---@return nil
Target.RemoveModel = function(model)
ox_target:removeModel(model)
end
---comment
---@param name string ---@param name string
---@return nil
Target.RemoveZone = function(name) Target.RemoveZone = function(name)
if not name then return end
for _, data in pairs(targetZones) do for _, data in pairs(targetZones) do
if data.name == name then if data.name == name then
ox_target:removeZone(data.id) ox_target:removeZone(data.id)
@@ -152,12 +149,11 @@ Target.RemoveZone = function(name)
end end
AddEventHandler('onResourceStop', function(resource) AddEventHandler('onResourceStop', function(resource)
if resource == GetCurrentResourceName() then if resource ~= GetCurrentResourceName() then return end
for _, target in pairs(targetZones) do for _, target in pairs(targetZones) do
if target.creator == resource then if target.creator == resource then
ox_target:removeZone(target.id) ox_target:removeZone(target.id)
end
end end
targetZones = {}
end end
targetZones = {}
end) end)
+64 -29
View File
@@ -15,7 +15,12 @@ detectDebugEnabled()
local targetZones = {} local targetZones = {}
Target = Target or {} Target = Target or {}
local qb_target = exports['qb-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) Target.FixOptions = function(options)
for k, v in pairs(options) do for k, v in pairs(options) do
local action = v.onSelect or v.action local action = v.onSelect or v.action
@@ -23,7 +28,7 @@ Target.FixOptions = function(options)
if type(entityOrData) == 'table' then if type(entityOrData) == 'table' then
return action(entityOrData.entity) return action(entityOrData.entity)
end end
return action(entityOrData) return action(entityOrData)
end end
options[k].action = select options[k].action = select
options[k].job = v.job or v.groups options[k].job = v.job or v.groups
@@ -31,55 +36,90 @@ Target.FixOptions = function(options)
return options return options
end end
---This will toggle the targeting system on or off. This is useful for when you want to disable the targeting system for a specific player entirely.
---@param bool boolean
Target.DisableTargeting = function(bool) Target.DisableTargeting = function(bool)
exports['qb-target']:AllowTargeting(not bool) qb_target:AllowTargeting(not bool)
end end
---This will add target options to players.
---@param options table
Target.AddGlobalPlayer = function(options) Target.AddGlobalPlayer = function(options)
options = Target.FixOptions(options) options = Target.FixOptions(options)
exports['qb-target']:AddGlobalPlayer({ qb_target:AddGlobalPlayer({
options = options, options = options,
distance = options.distance or 1.5 distance = options.distance or 1.5
}) })
end end
---This will remove target options from all players.
Target.RemoveGlobalPlayer = function()
qb_target:RemoveGlobalPlayer()
end
---This will add taget options to all vehicles.
---@param options table
Target.AddGlobalVehicle = function(options) Target.AddGlobalVehicle = function(options)
options = Target.FixOptions(options) options = Target.FixOptions(options)
exports['qb-target']:AddGlobalVehicle({ qb_target:AddGlobalVehicle({
options = options, options = options,
distance = options.distance or 1.5 distance = options.distance or 1.5
}) })
end end
---This will remove target options from all vehicles.
---@param options table
Target.RemoveGlobalVehicle = function(options) Target.RemoveGlobalVehicle = function(options)
local assembledLables = {} local assembledLables = {}
for k, v in pairs(options) do for k, v in pairs(options) do
table.insert(assembledLables, v.label) table.insert(assembledLables, v.label)
end end
exports['qb-target']:RemoveGlobalVehicle(assembledLables) qb_target:RemoveGlobalVehicle(assembledLables)
end end
---This will generate targets on non networked entites with the passed options.
---@param entities number | table
---@param options table
Target.AddLocalEntity = function(entities, options) Target.AddLocalEntity = function(entities, options)
options = Target.FixOptions(options) options = Target.FixOptions(options)
exports['qb-target']:AddTargetEntity(entities, { qb_target:AddTargetEntity(entities, {
options = options, options = options,
distance = options.distance or 1.5 distance = options.distance or 1.5
}) })
end end
---This will remove the target options from a local entity. This is useful for when you want to remove target options from a specific entity.
---@param entity any
Target.RemoveLocalEntity = function(entity)
qb_target:RemoveTargetEntity(entity)
end
---This will add target options to all specified models. This is useful for when you want to add target options to all models of a specific type.
---@param models number | table
---@param options table
Target.AddModel = function(models, options) Target.AddModel = function(models, options)
options = Target.FixOptions(options) options = Target.FixOptions(options)
exports['qb-target']:AddTargetModel(models, { qb_target:AddTargetModel(models, {
options = options, options = options,
distance = options.distance or 1.5, distance = options.distance or 1.5,
}) })
end end
---This will remove target options from all specified models.
---@param model number
Target.RemoveModel = function(model)
qb_target:RemoveTargetModel(model)
end
---This will add a box zone to the target system. This is useful for when you want to add target options to a specific area.
---@param name string
---@param coords table
---@param size table
---@param heading number
---@param options table
Target.AddBoxZone = function(name, coords, size, heading, options) Target.AddBoxZone = function(name, coords, size, heading, options)
options = Target.FixOptions(options) options = Target.FixOptions(options)
exports['qb-target']:AddBoxZone(name, coords, size.x, size.y, { qb_target:AddBoxZone(name, coords, size.x, size.y, {
name = name, name = name,
debugPoly = targetDebug, debugPoly = targetDebug,
heading = heading, heading = heading,
@@ -92,9 +132,14 @@ Target.AddBoxZone = function(name, coords, size, heading, options)
table.insert(targetZones, { name = name, creator = GetInvokingResource() }) table.insert(targetZones, { name = name, creator = GetInvokingResource() })
end 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.
---@param name string
---@param coords table
---@param radius number
---@param options table
Target.AddSphereZone = function(name, coords, radius, options) Target.AddSphereZone = function(name, coords, radius, options)
options = Target.FixOptions(options) options = Target.FixOptions(options)
exports['qb-target']:AddCircleZone(name, coords, radius, { qb_target:AddCircleZone(name, coords, radius, {
name = name, name = name,
debugPoly = targetDebug, debugPoly = targetDebug,
}, { }, {
@@ -104,22 +149,13 @@ Target.AddSphereZone = function(name, coords, radius, options)
table.insert(targetZones, { name = name, creator = GetInvokingResource() }) table.insert(targetZones, { name = name, creator = GetInvokingResource() })
end end
Target.RemoveGlobalPlayer = function() ---This will remove target options from a specific zone.
exports['qb-target']:RemoveGlobalPlayer() ---@param name string
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) Target.RemoveZone = function(name)
if not name then return end
for _, data in pairs(targetZones) do for _, data in pairs(targetZones) do
if data.name == name then if data.name == name then
exports['qb-target']:RemoveZone(name) qb_target:RemoveZone(name)
table.remove(targetZones, _) table.remove(targetZones, _)
break break
end end
@@ -127,12 +163,11 @@ Target.RemoveZone = function(name)
end end
AddEventHandler('onResourceStop', function(resource) AddEventHandler('onResourceStop', function(resource)
if resource == GetCurrentResourceName() then if resource ~= GetCurrentResourceName() then return end
for _, target in pairs(targetZones) do for _, target in pairs(targetZones) do
if target.creator == resource then if target.creator == resource then
exports['qb-target']:RemoveZone(target.name) qb_target:RemoveZone(target.name)
end
end end
targetZones = {}
end end
targetZones = {}
end) end)