Files
community_bridge/modules/target/ox_target/client.lua
T

95 lines
2.4 KiB
Lua
Raw Normal View History

2025-01-08 06:33:31 -05:00
if GetResourceState('ox_target') ~= 'started' then return end
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 ox_target = exports.ox_target
local targetZones = {}
Target = {}
2025-02-05 17:42:50 -06:00
Target.FixOptions = function(options)
2025-01-14 10:55:14 -06: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
2025-02-07 23:54:15 -05:00
return action(entityOrData)
2025-02-05 17:42:50 -06:00
end
2025-02-07 23:54:15 -05:00
options[k].onSelect = select
2025-01-14 10:55:14 -06: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
ox_target:addGlobalPlayer(options)
end
2025-01-25 17:59:19 -05:00
Target.AddGlobalVehicle = function(options)
2025-02-05 17:42:50 -06:00
options = Target.FixOptions(options)
2025-01-25 17:59:19 -05:00
ox_target:addGlobalVehicle(options)
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
ox_target:addLocalEntity(entities, options)
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
ox_target:addModel(models, options)
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
local target = ox_target:addBoxZone({
coords = coords,
size = size,
rotation = heading,
debug = targetDebug,
options = options,
})
table.insert(targetZones, { name = name, id = target, creator = GetInvokingResource() })
return target
end
Target.RemoveGlobalPlayer = function()
ox_target:removeGlobalPlayer()
end
Target.RemoveLocalEntity = function(entity)
ox_target:removeLocalEntity(entity)
end
Target.RemoveModel = function(model)
ox_target:removeModel(model)
end
Target.RemoveZone = function(name)
for _, data in pairs(targetZones) do
if data.name == name then
ox_target:removeZone(data.id)
table.remove(targetZones, _)
break
end
end
end
AddEventHandler('onResourceStop', function(resource)
if resource == GetCurrentResourceName() then
2025-01-08 06:33:31 -05:00
for _, target in pairs(targetZones) do
if target.creator == resource then
ox_target:removeZone(target.id)
end
end
targetZones = {}
end
end)