-
Notifications
You must be signed in to change notification settings - Fork 190
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
234 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,233 @@ | ||
local function exportHandler(exportName, func) | ||
AddEventHandler(('__cfx_export_qb-target_%s'):format(exportName), function(setCB) | ||
setCB(func) | ||
end) | ||
end | ||
|
||
---@param options table | ||
---@return table | ||
local function convert(options) | ||
local distance = options.distance | ||
options = options.options | ||
|
||
for _, v in pairs(options) do | ||
v.onSelect = v.action | ||
v.distance = v.distance or distance | ||
v.name = v.name or v.label | ||
v.items = v.item | ||
v.groups = v.job | ||
|
||
local groupType = type(v.groups) | ||
if groupType == 'nil' then | ||
v.groups = {} | ||
groupType = 'table' | ||
end | ||
if groupType == 'string' then | ||
local val = v.gang | ||
if type(v.gang) == 'table' then | ||
if table.type(v.gang) ~= 'array' then | ||
val = {} | ||
for k in pairs(v.gang) do | ||
val[#val + 1] = k | ||
end | ||
end | ||
end | ||
|
||
if val then | ||
v.groups = {v.groups, type(val) == 'table' and table.unpack(val) or val} | ||
end | ||
|
||
val = v.citizenid | ||
if type(v.citizenid) == 'table' then | ||
if table.type(v.citizenid) ~= 'array' then | ||
val = {} | ||
for k in pairs(v.citizenid) do | ||
val[#val+1] = k | ||
end | ||
end | ||
end | ||
|
||
if val then | ||
v.groups = {v.groups, type(val) == 'table' and table.unpack(val) or val} | ||
end | ||
elseif groupType == 'table' then | ||
local val = {} | ||
if table.type(v.groups) ~= 'array' then | ||
for k in pairs(v.groups) do | ||
val[#val + 1] = k | ||
end | ||
v.groups = val | ||
val = nil | ||
end | ||
|
||
val = v.gang | ||
if type(v.gang) == 'table' then | ||
if table.type(v.gang) ~= 'array' then | ||
val = {} | ||
for k in pairs(v.gang) do | ||
val[#val + 1] = k | ||
end | ||
end | ||
end | ||
|
||
if val then | ||
v.groups = {table.unpack(v.groups), type(val) == 'table' and table.unpack(val) or val} | ||
end | ||
|
||
val = v.citizenid | ||
if type(v.citizenid) == 'table' then | ||
if table.type(v.citizenid) ~= 'array' then | ||
val = {} | ||
for k in pairs(v.citizenid) do | ||
val[#val+1] = k | ||
end | ||
end | ||
end | ||
|
||
if val then | ||
v.groups = {table.unpack(v.groups), type(val) == 'table' and table.unpack(val) or val} | ||
end | ||
end | ||
|
||
if type(v.groups) == 'table' and table.type(v.groups) == 'empty' then | ||
v.groups = nil | ||
end | ||
|
||
if v.event and v.type and v.type ~= 'client' then | ||
if v.type == 'server' then | ||
v.serverEvent = v.event | ||
elseif v.type == 'command' then | ||
v.command = v.event | ||
end | ||
|
||
v.event = nil | ||
v.type = nil | ||
end | ||
|
||
v.action = nil | ||
v.job = nil | ||
v.gang = nil | ||
v.citizenid = nil | ||
v.item = nil | ||
v.qtarget = true | ||
end | ||
|
||
return options | ||
end | ||
|
||
exportHandler('AddBoxZone', function(name, center, length, width, options, targetoptions) | ||
return lib.zones.box({ | ||
name = name, | ||
coords = center, | ||
size = vec3(width, length, math.abs(options.maxZ - options.minZ)), | ||
debug = options.debugPoly, | ||
rotation = options.heading, | ||
options = convert(targetoptions), | ||
resource = GetInvokingResource(), | ||
}).id | ||
end) | ||
|
||
exportHandler('AddPolyZone', function(name, points, options, targetoptions) | ||
local newPoints = table.create(#points, 0) | ||
local thickness = math.abs(options.maxZ - options.minZ) | ||
|
||
for i = 1, #points do | ||
local point = points[i] | ||
newPoints[i] = vec3(point.x, point.y, options.maxZ - (thickness / 2)) | ||
end | ||
|
||
return lib.zones.poly({ | ||
name = name, | ||
points = newPoints, | ||
thickness = thickness, | ||
debug = options.debugPoly, | ||
options = convert(targetoptions), | ||
resource = GetInvokingResource(), | ||
}).id | ||
end) | ||
|
||
exportHandler('AddCircleZone', function(name, center, radius, options, targetoptions) | ||
return lib.zones.sphere({ | ||
name = name, | ||
coords = center, | ||
radius = radius, | ||
debug = options.debugPoly, | ||
options = convert(targetoptions), | ||
resource = GetInvokingResource(), | ||
}).id | ||
end) | ||
|
||
exportHandler('RemoveZone', function(id) | ||
if Zones then | ||
if type(id) == 'string' then | ||
for _, v in pairs(Zones) do | ||
if v.name == id then | ||
v:remove() | ||
end | ||
end | ||
end | ||
|
||
if Zones[id] then | ||
Zones[id]:remove() | ||
end | ||
end | ||
end) | ||
|
||
exportHandler('AddTargetBone', function(bones, options) | ||
if type(bones) ~= 'table' then bones = { bones } end | ||
options = convert(options) | ||
|
||
for _, v in pairs(options) do | ||
v.bones = bones | ||
end | ||
|
||
exports.ox_target:addGlobalVehicle(options) | ||
end) | ||
|
||
exportHandler('AddTargetEntity', function(entities, options) | ||
target.addEntity(entities, convert(options)) | ||
end) | ||
|
||
exportHandler('RemoveTargetEntity', function(entities, labels) | ||
target.removeEntity(entities, labels) | ||
end) | ||
|
||
exportHandler('AddTargetModel', function(models, options) | ||
target.addModel(models, convert(options)) | ||
end) | ||
|
||
exportHandler('RemoveTargetModel', function(models, labels) | ||
target.removeModel(models, labels) | ||
end) | ||
|
||
exportHandler('AddGlobalPed', function(options) | ||
target.addGlobalPed(convert(options)) | ||
end) | ||
|
||
exportHandler('RemoveGlobalPed', function(labels) | ||
target.removeGlobalPed(labels) | ||
end) | ||
|
||
exportHandler('AddGlobalVehicle', function(options) | ||
target.addGlobalVehicle(convert(options)) | ||
end) | ||
|
||
exportHandler('RemoveGlobalVehicle', function(labels) | ||
target.removeGlobalVehicle(labels) | ||
end) | ||
|
||
exportHandler('AddGlobalObject', function(options) | ||
target.addGlobalObject(convert(options)) | ||
end) | ||
|
||
exportHandler('RemoveGlobalObject', function(labels) | ||
target.removeGlobalObject(labels) | ||
end) | ||
|
||
exportHandler('AddGlobalPlayer', function(options) | ||
target.addGlobalPlayer(convert(options)) | ||
end) | ||
|
||
exportHandler('RemoveGlobalPlayer', function(labels) | ||
target.removeGlobalPlayer(labels) | ||
end) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,3 +38,4 @@ files { | |
} | ||
|
||
provide 'qtarget' | ||
provide 'qb-target' |