Stipped away inefficient behavior system
Refactored the entity system to be **property-driven** with automatic `On<Property>` change handlers. Added improved `Bridge.Entity.SetOnCreate` support so clients can identify and attach logic to **server-created entities** based on properties. Introduced standardized default properties on `Bridge.Entity.Create`, including: * `freeze` (defaults to frozen) * `invincible` * `targets` * `attach` * `anim` Added exported helper functions for all of the above to allow runtime updates after creation.
This commit is contained in:
1 parent
7d16eb3cc9
commit
68ca928033
13 files changed
+239
-952
No files matched your search
@@ -1,9 +1,7 @@
|
||||
Ids = Ids or Require("lib/utility/shared/ids.lua")
|
||||
Behaviors = Behaviors or Require("lib/entities/shared/behaviors.lua")
|
||||
|
||||
local Entities = {}
|
||||
ServerEntity = {} -- Renamed from EntityRelay
|
||||
ServerEntity.Behaviors = Behaviors
|
||||
local Invoked = {}
|
||||
|
||||
--- Creates a server-side representation of an entity and notifies clients.
|
||||
@@ -32,7 +30,6 @@ end
|
||||
function ServerEntity.Create(data)
|
||||
local self = ServerEntity.New(data.id, data.entityType, data.model, data.coords, data.rotation or vector3(0.0, 0.0, data.heading or 0.0), data)
|
||||
if not self then return nil end
|
||||
Behaviors.Trigger("OnCreate", self)
|
||||
TriggerClientEvent("community_bridge:client:CreateEntity", -1, self)
|
||||
return self
|
||||
end
|
||||
@@ -43,7 +40,6 @@ function ServerEntity.CreateBulk(entities)
|
||||
local id = entityData.id or Ids.CreateUniqueId(Entities)
|
||||
local entity = ServerEntity.New(id, entityData.entityType, entityData.model, entityData.coords, entityData.rotation, entityData)
|
||||
createdEntities[id] = entity
|
||||
Behaviors.Trigger("OnCreate", entity)
|
||||
end
|
||||
TriggerClientEvent("community_bridge:client:CreateEntities", -1, createdEntities)
|
||||
return createdEntities
|
||||
@@ -54,7 +50,7 @@ end
|
||||
function ServerEntity.Destroy(id)
|
||||
if not Entities[id] then return end
|
||||
ServerEntity.Remove(id)
|
||||
TriggerClientEvent("community_bridge:client:DeleteEntity", -1, id)
|
||||
TriggerClientEvent("community_bridge:client:DeleteEntity", -1, id)
|
||||
end
|
||||
ServerEntity.Delete = ServerEntity.Destroy
|
||||
|
||||
@@ -91,9 +87,6 @@ function ServerEntity.Set(id, data)
|
||||
return true
|
||||
end
|
||||
|
||||
function ServerEntity.RegisterBehavior(id, behavior)
|
||||
Behaviors.Create(id, behavior)
|
||||
end
|
||||
|
||||
-- Clean up entities associated with a stopped resource
|
||||
AddEventHandler('onResourceStop', function(resourceName)
|
||||
|
||||
Reference in new issue
Block a user