hope this works
This commit is contained in:
1 parent
5b6641fc60
commit
e06e04a2c6
6 files changed
+138
-102
No files matched your search
@@ -1,61 +0,0 @@
|
||||
Behaviors = {
|
||||
All = {},
|
||||
isSetup = false,
|
||||
}
|
||||
|
||||
function Behaviors.Setup()
|
||||
if Behaviors.isSetup then return end
|
||||
Behaviors.isSetup = true
|
||||
local behaviors = Require("lib/entities/client/behaviors/init.lua")
|
||||
for _, behavior in ipairs(behaviors) do
|
||||
Behaviors.Create(behavior.tag, behavior)
|
||||
end
|
||||
end
|
||||
|
||||
function Behaviors.Create(behaviorId, behavior)
|
||||
if not behaviorId or not behavior then return end
|
||||
if Behaviors.All[behaviorId] then
|
||||
print(string.format("[ClientEntity] Behavior %s already exists", behaviorId))
|
||||
return
|
||||
end
|
||||
Behaviors.All[behaviorId] = behavior
|
||||
end
|
||||
|
||||
function Behaviors.Get(behaviorId)
|
||||
return Behaviors.All[behaviorId]
|
||||
end
|
||||
|
||||
function Behaviors.Remove(behaviorId)
|
||||
if not Behaviors.All[behaviorId] then return end
|
||||
Behaviors.All[behaviorId] = nil
|
||||
return true
|
||||
end
|
||||
|
||||
function Behaviors.Trigger(actionName, clientEntityData, ...)
|
||||
if not clientEntityData or not actionName then return end
|
||||
for tag, behavior in pairs(Behaviors.All) do
|
||||
local hasBehaviorArgs = Behaviors.Has(tag, clientEntityData) -- this is everything that's contained inside the object's individual tag
|
||||
if hasBehaviorArgs and behavior[actionName] then
|
||||
behavior[actionName](clientEntityData, hasBehaviorArgs, ...)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function Behaviors.Inherit(behaviorId, clientEntityData, defaultData)
|
||||
if not Behaviors.All[behaviorId] then
|
||||
print(string.format("[ClientEntity] Behavior %s does not exist", behaviorId))
|
||||
return false
|
||||
end
|
||||
if not clientEntityData or not clientEntityData.id then
|
||||
print("[ClientEntity] Invalid client entity data provided for inheritance")
|
||||
return false
|
||||
end
|
||||
clientEntityData[behaviorId] = defaultData or {} -- Mark the entity as having this behavior
|
||||
return true
|
||||
end
|
||||
|
||||
function Behaviors.Has(behaviorId, clientEntityData)
|
||||
return clientEntityData and clientEntityData[behaviorId]
|
||||
end
|
||||
|
||||
return Behaviors
|
||||
@@ -1,20 +0,0 @@
|
||||
local fileList = {
|
||||
"particles",
|
||||
"targets",
|
||||
}
|
||||
|
||||
local path = "lib/entities/client/behaviors/"
|
||||
|
||||
local function loadAllResources()
|
||||
local modules = {}
|
||||
for _, fileName in ipairs(fileList) do
|
||||
local filePath = path .. fileName .. ".lua"
|
||||
local required = Require(filePath)
|
||||
if required then
|
||||
table.insert(modules, required)
|
||||
end
|
||||
end
|
||||
return modules
|
||||
end
|
||||
|
||||
return loadAllResources()
|
||||
@@ -282,12 +282,21 @@ RegisterNetEvent("community_bridge:client:DeleteEntity", function(id)
|
||||
end)
|
||||
|
||||
RegisterNetEvent("community_bridge:client:UpdateEntity", function(id, data)
|
||||
ClientEntity.Update(id, data)
|
||||
for k, v in pairs(data) do
|
||||
ClientEntity.Set(id, k, v)
|
||||
end
|
||||
end)
|
||||
|
||||
local Loaded = false
|
||||
AddEventHandler('community_bridge:Client:OnPlayerLoaded', function(resourceName)
|
||||
if Loaded then return end
|
||||
Loaded = true
|
||||
end)
|
||||
|
||||
AddEventHandler('onResourceStart', function(resourceName)
|
||||
if resourceName ~= GetCurrentResourceName() then return end
|
||||
Behaviors.Setup()
|
||||
if Loaded then return end
|
||||
Loaded = true
|
||||
end)
|
||||
|
||||
-- Resource Stop Cleanup
|
||||
|
||||
Reference in new issue
Block a user