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 owner = entityData.stash.owner
local groups = entityData.stash.groups local groups = entityData.stash.groups
Bridge.Inventory.RegisterStash(entityData.id, label, slots, weight, owner, groups) Bridge.Inventory.RegisterStash(entityData.id, label, slots, weight, owner, groups)
else return
entityData.targets = entityData.targets or {} end
entityData.targets['stash'] = { entityData.targets = entityData.targets or {}
label = entityData.stash.target.label or Stash.default.target.label, entityData.targets['stash'] = {
icon = entityData.stash.target.icon or Stash.default.target.icon, label = entityData.stash.target.label or Stash.default.target.label,
description = entityData.stash.target.description, icon = entityData.stash.target.icon or Stash.default.target.icon,
groups = entityData.stash.target.groups, description = entityData.stash.target.description,
canInteract = function(_) groups = entityData.stash.target.groups,
local entData = Bridge.Entity.Get(entityData.id) canInteract = function(_)
return not entData.stash.disable local entData = Bridge.Entity.Get(entityData.id)
end, return not entData.stash.disable
onSelect = function() end,
TriggerServerEvent("community_bridge:server:OpenStash", entityData.id) onSelect = function()
end TriggerServerEvent("community_bridge:server:OpenStash", entityData.id)
} end
}
Bridge.Entity.Set(entityData.id, 'targets', entityData.targets)
end Bridge.Entity.Set(entityData.id, 'targets', entityData.targets)
end end
if not IsDuplicityVersion() then return Bridge.Entity.RegisterBehavior("stash", Stash) 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 break
end end
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 if doesntMatch then
print("ASDFASDFASDF")
Targets.OnRemove(entityData) Targets.OnRemove(entityData)
Wait(100) Wait(100)
Targets.OnSpawn(entityData) Targets.OnSpawn(entityData)