Add modular entity behaviors and update entity logic

Introduces modular behaviors for entities, including anim, attach, clothing, follow, particles, scenarios, shop, stash, targets, and weapon, each in their own files. Updates client_entity.lua and behaviors.lua to support dynamic behavior registration, initialization, and triggering. Refactors entity update logic to improve movement handling and behavior invocation.
This commit is contained in:
Mr.Crowley committed 2025-09-03 00:28:17 -05:00
1 parent facffe26c5
commit 8346130b00
12 files changed
+693 -11

No files matched your search

+34 -1
View File
@@ -4,6 +4,27 @@ Behaviors = {
invoked = {}
}
Behaviors.init = {
"anim",
"attach",
'clothing',
'follow',
'particles',
'scenarios',
'shop',
'stash',
'targets',
'weapon'
}
function Behaviors.Init()
if Behaviors.isSetup then return end
Behaviors.isSetup = true
for k, v in pairs(Behaviors.init) do
Require(string.format("lib/entities/shared/behaviors/%s.lua", v))
end
end
function Behaviors.Create(behaviorId, behavior)
if not behaviorId or not behavior then return end
Behaviors.All = Behaviors.All or {}
@@ -26,7 +47,6 @@ end
function Behaviors.Trigger(actionName, clientEntityData, ...)
if not clientEntityData or not actionName then return end
local invoking = clientEntityData.invoked or GetInvokingResource() or "community_bridge"
for property, behavior in pairs(Behaviors.All[invoking] or {}) do
local hasBehaviorArgs = Behaviors.Has(property, clientEntityData) -- this is everything that's contained inside the object's individual property
@@ -37,6 +57,15 @@ function Behaviors.Trigger(actionName, clientEntityData, ...)
end
end
end
for property, behavior in pairs(Behaviors.All['community_bridge'] or {}) do
local hasBehaviorArgs = Behaviors.Has(property, clientEntityData) -- this is everything that's contained inside the object's individual property
if hasBehaviorArgs and behavior[actionName] and not Behaviors.All[invoking]?[actionName] then
local success, result = pcall(behavior[actionName], clientEntityData, hasBehaviorArgs, ...)
if not success then
print(string.format("[ClientEntity] Behavior %s failed: %s", property, result))
end
end
end
end
function Behaviors.Inherit(behaviorId, clientEntityData, defaultData)
@@ -75,4 +104,8 @@ AddEventHandler("onResourceStop", function(resourceName)
end
end)
AddEventHandler("onResourceStart", function(resourceName)
Behaviors.Init()
end)
return Behaviors