2025-09-03 00:28:17 -05:00
|
|
|
if IsDuplicityVersion() then return end
|
|
|
|
|
local Targets = {
|
|
|
|
|
property = "targets",
|
|
|
|
|
default = {
|
|
|
|
|
label = "Default Target Label",
|
|
|
|
|
distance = 2,
|
2025-09-03 08:57:39 -05:00
|
|
|
size = vector3(2.0, 2.0, 2.0),
|
2025-09-03 00:28:17 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function Targets.OnSpawn(entityData)
|
2025-09-03 08:57:39 -05:00
|
|
|
if not entityData.targets then return end
|
2025-09-03 00:28:17 -05:00
|
|
|
if entityData.targets?.label then
|
|
|
|
|
local temp = entityData.targets
|
|
|
|
|
entityData.targets = {temp}
|
|
|
|
|
end
|
2025-09-03 08:57:39 -05:00
|
|
|
print("Spawned targets:", entityData.targets)
|
2025-09-03 00:28:17 -05:00
|
|
|
local numberedTargets = {}
|
|
|
|
|
for k, v in pairs(entityData.targets) do
|
|
|
|
|
local onSelect = v.onSelect
|
|
|
|
|
if onSelect then
|
|
|
|
|
v.onSelect = function(entity)
|
|
|
|
|
onSelect(entityData, entity)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
table.insert(numberedTargets, v)
|
|
|
|
|
end
|
|
|
|
|
table.sort(numberedTargets, function(a, b) return (a.label < b.label) end)
|
2025-09-03 08:57:39 -05:00
|
|
|
if not entityData.spawned then
|
|
|
|
|
local size = Targets.default.size
|
|
|
|
|
Bridge.Target.AddBoxZone(entityData.id, entityData.coords, entityData.size, entityData.heading, numberedTargets, entityData.debug)
|
|
|
|
|
else
|
|
|
|
|
Bridge.Target.AddLocalEntity(entityData.spawned, numberedTargets)
|
|
|
|
|
end
|
2025-09-03 00:28:17 -05:00
|
|
|
entityData.oldTargets = entityData.targets
|
2025-09-03 04:06:31 -05:00
|
|
|
Bridge.Entity.Set(entityData.id, "oldTargets", entityData.oldTargets)
|
2025-09-03 00:28:17 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function Targets.OnRemove(entityData)
|
2025-09-03 08:57:39 -05:00
|
|
|
if not entityData.oldTargets then return end
|
|
|
|
|
if not entityData.spawned then
|
|
|
|
|
return Bridge.Target.RemoveZone(entityData.id)
|
|
|
|
|
end
|
2025-09-03 00:28:17 -05:00
|
|
|
Bridge.Target.RemoveLocalEntity(entityData.spawned)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function Targets.OnUpdate(entityData)
|
2025-09-03 08:57:39 -05:00
|
|
|
if not entityData.oldTargets then return end
|
2025-09-03 00:28:17 -05:00
|
|
|
local doesntMatch = false
|
|
|
|
|
for k, v in pairs(entityData.targets) do
|
|
|
|
|
if not entityData.oldTargets or not entityData.oldTargets[k] then
|
|
|
|
|
doesntMatch = true
|
|
|
|
|
break
|
|
|
|
|
end
|
|
|
|
|
local old = entityData.oldTargets[k]
|
|
|
|
|
if old.label ~= v.label
|
|
|
|
|
or old.distance ~= v.distance
|
|
|
|
|
or old.description ~= v.description
|
|
|
|
|
then
|
|
|
|
|
doesntMatch = true
|
|
|
|
|
break
|
|
|
|
|
end
|
|
|
|
|
end
|
2025-09-04 08:21:48 -05:00
|
|
|
|
|
|
|
|
for k, v in pairs(entityData.oldTargets) do
|
|
|
|
|
if not entityData.targets or not entityData.targets[k] then
|
|
|
|
|
doesntMatch = true
|
|
|
|
|
break
|
|
|
|
|
end
|
|
|
|
|
end
|
2025-09-03 00:28:17 -05:00
|
|
|
if doesntMatch then
|
|
|
|
|
Targets.OnRemove(entityData)
|
|
|
|
|
Wait(100)
|
|
|
|
|
Targets.OnSpawn(entityData)
|
|
|
|
|
end
|
|
|
|
|
end
|
2025-09-03 04:06:31 -05:00
|
|
|
Bridge.Entity.RegisterBehavior("targets", Targets)
|
2025-09-03 00:28:17 -05:00
|
|
|
return Targets
|