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:
1 parent
7443695254
commit
debfb06231
2 files changed
+25
-19
No files matched your search
@@ -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
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|||||||
Reference in new issue
Block a user