Refactor stash and targets behavior logic

Simplifies stash target assignment by returning early when registering a stash, ensuring consistent target setup. Enhances target update logic to check for removed targets and removes debug print statement.
This commit is contained in:
Mr.Crowley committed 2025-09-04 08:21:48 -05:00
1 parent 7443695254
commit debfb06231
2 files changed
+25 -19

No files matched your search

+18 -18
View File
@@ -20,24 +20,24 @@ function Stash.OnCreate(entityData)
local owner = entityData.stash.owner
local groups = entityData.stash.groups
Bridge.Inventory.RegisterStash(entityData.id, label, slots, weight, owner, groups)
else
entityData.targets = entityData.targets or {}
entityData.targets['stash'] = {
label = entityData.stash.target.label or Stash.default.target.label,
icon = entityData.stash.target.icon or Stash.default.target.icon,
description = entityData.stash.target.description,
groups = entityData.stash.target.groups,
canInteract = function(_)
local entData = Bridge.Entity.Get(entityData.id)
return not entData.stash.disable
end,
onSelect = function()
TriggerServerEvent("community_bridge:server:OpenStash", entityData.id)
end
}
Bridge.Entity.Set(entityData.id, 'targets', entityData.targets)
end
return
end
entityData.targets = entityData.targets or {}
entityData.targets['stash'] = {
label = entityData.stash.target.label or Stash.default.target.label,
icon = entityData.stash.target.icon or Stash.default.target.icon,
description = entityData.stash.target.description,
groups = entityData.stash.target.groups,
canInteract = function(_)
local entData = Bridge.Entity.Get(entityData.id)
return not entData.stash.disable
end,
onSelect = function()
TriggerServerEvent("community_bridge:server:OpenStash", entityData.id)
end
}
Bridge.Entity.Set(entityData.id, 'targets', entityData.targets)
end
if not IsDuplicityVersion() then return Bridge.Entity.RegisterBehavior("stash", Stash) end
+7 -1
View File
@@ -61,8 +61,14 @@ function Targets.OnUpdate(entityData)
break
end
end
for k, v in pairs(entityData.oldTargets) do
if not entityData.targets or not entityData.targets[k] then
doesntMatch = true
break
end
end
if doesntMatch then
print("ASDFASDFASDF")
Targets.OnRemove(entityData)
Wait(100)
Targets.OnSpawn(entityData)