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