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,18 +1,79 @@
|
||||
Utility = Utility or Require("lib/utility/client/utility.lua")
|
||||
Ids = Ids or Require("lib/utility/shared/ids.lua")
|
||||
Point = Point or Require("lib/points/client/points.lua")
|
||||
Behaviors = Behaviors or Require("lib/entities/shared/behaviors.lua")
|
||||
local Entities = {} -- Stores entity data received from server
|
||||
ClientEntity = {
|
||||
Invoked = {}
|
||||
All = {},
|
||||
Invoked = {},
|
||||
OnCreates = {}
|
||||
} -- Renamed from BaseEntity
|
||||
ClientEntity.Behaviors = Behaviors
|
||||
----------------------------------------
|
||||
|
||||
--------------------
|
||||
---@alias ClientEntityId string|number
|
||||
---@alias EntityHandle number
|
||||
|
||||
---@class ClientEntityAnim
|
||||
---@field dict string
|
||||
---@field name string
|
||||
---@field blendIn number|nil
|
||||
---@field blendOut number|nil
|
||||
---@field duration number|nil
|
||||
---@field flags number|nil
|
||||
---@field playbackRate number|nil
|
||||
---@field onComplete function|nil
|
||||
|
||||
---@class ClientEntityAttach
|
||||
---@field target string|number Target reference. String may be a Bridge.Entity id; number may be a player server id; either may also be a FiveM entity handle.
|
||||
---@field bone number|nil
|
||||
---@field offset vector3|nil
|
||||
---@field rotation vector3|nil
|
||||
|
||||
---@class EntityData
|
||||
---@field id ClientEntityId|nil If omitted, one is generated.
|
||||
---@field coords vector3
|
||||
---@field entityType 'object'|'ped'|'vehicle'
|
||||
---@field model string|number
|
||||
---@field heading number|nil
|
||||
---@field rotation vector3|nil
|
||||
---@field spawnDistance number|nil
|
||||
---@field freeze boolean|nil
|
||||
---@field invincible boolean|nil
|
||||
---@field targets table|nil Target options passed to Bridge.Target.AddLocalEntity.
|
||||
---@field anim ClientEntityAnim|nil
|
||||
---@field attach ClientEntityAttach|nil
|
||||
---@field OnSpawn fun(entityData: EntityData)|nil
|
||||
---@field OnRemove fun(entityData: EntityData)|nil
|
||||
---@field spawned EntityHandle|nil FiveM entity handle created when the entry is in-range.
|
||||
|
||||
-- Set the entity and apply any relevant properties such as freezing and targets.
|
||||
local function SetEntityProperties(id)
|
||||
local entityData = ClientEntity.Get(id)
|
||||
if not entityData then return end
|
||||
local entity = entityData.spawned
|
||||
if not entity or not DoesEntityExist(entity) then return end
|
||||
|
||||
if entityData.freeze == nil or entityData.freeze then
|
||||
FreezeEntityPosition(entity, true)
|
||||
end
|
||||
if entityData.invincible then
|
||||
SetEntityInvincible(entity, entityData.invincible)
|
||||
end
|
||||
if entityData.targets then
|
||||
for k, v in pairs(entityData.targets) do
|
||||
print(v.label)
|
||||
end
|
||||
ClientEntity.SetTargets(id, entityData.targets)
|
||||
end
|
||||
if entityData.anim then
|
||||
ClientEntity.SetAnim(id, entityData.anim)
|
||||
end
|
||||
if entityData.attach then
|
||||
ClientEntity.SetAttach(id, entityData.attach)
|
||||
end
|
||||
end
|
||||
|
||||
local function SpawnEntity(entityData)
|
||||
if entityData.spawned and DoesEntityExist(entityData.spawned) then return end -- Already spawned
|
||||
if entityData.model then
|
||||
if entityData.model then
|
||||
local loaded, model = Utility.LoadModel(entityData.model)
|
||||
if not loaded then
|
||||
print(string.format("[ClientEntity] Failed to load model %s for entity %s", entityData.model, entityData.id))
|
||||
@@ -33,27 +94,19 @@ local function SpawnEntity(entityData)
|
||||
else
|
||||
print(string.format("[ClientEntity] Unknown entity type '%s' for entity %s", entityData.entityType, entityData.id))
|
||||
end
|
||||
if entity and model then
|
||||
entityData.spawned = entity
|
||||
SetModelAsNoLongerNeeded(model)
|
||||
SetEntityAsMissionEntity(entity, true, true)
|
||||
FreezeEntityPosition(entity, true)
|
||||
else
|
||||
SetModelAsNoLongerNeeded(model)
|
||||
end
|
||||
entityData.spawned = entity
|
||||
SetEntityProperties(entityData.id)
|
||||
SetModelAsNoLongerNeeded(model)
|
||||
end
|
||||
if entityData.OnSpawn then
|
||||
pcall(function (...)
|
||||
return entityData.OnSpawn(entityData)
|
||||
end)
|
||||
end
|
||||
Behaviors.Trigger("OnSpawn", entityData)
|
||||
if not entityData.OnSpawn then return end
|
||||
pcall(function (...)
|
||||
return entityData.OnSpawn(entityData)
|
||||
end)
|
||||
end
|
||||
|
||||
local function RemoveEntity(entityData)
|
||||
entityData = entityData and entityData.args or entityData
|
||||
if not entityData then return end
|
||||
Behaviors.Trigger("OnRemove", entityData)
|
||||
if entityData.OnRemove then
|
||||
pcall(function (...)
|
||||
return entityData.OnRemove(entityData)
|
||||
@@ -67,70 +120,54 @@ local function RemoveEntity(entityData)
|
||||
end
|
||||
end
|
||||
|
||||
local function UpdateEntity(_entityData)
|
||||
local entityData = ClientEntity.Get(_entityData.id)
|
||||
if not entityData then return end
|
||||
if entityData.OnUpdate then
|
||||
pcall(function (...)
|
||||
return entityData.OnUpdate(entityData)
|
||||
end)
|
||||
end
|
||||
Behaviors.Trigger("OnUpdate", entityData)
|
||||
local coords = vector3(entityData.coords.x, entityData.coords.y, entityData.coords.z)
|
||||
entityData.oldCoords = entityData.oldCoords and vector3(entityData.oldCoords.x, entityData.oldCoords.y, entityData.oldCoords.z) or coords
|
||||
local dist = #(coords - entityData.oldCoords)
|
||||
if entityData.oldCoords and dist > 0.5 then
|
||||
-- if entityData.spawned then
|
||||
-- SetEntityCoords(entityData.spawned, coords.x, coords.y, coords.z, false, false, false, false)
|
||||
-- end
|
||||
-- ClientEntity.UpdateCoords(entityData.id, entityData.coords)
|
||||
if entityData.OnMove then
|
||||
pcall(function (...)
|
||||
return entityData.OnMove(entityData)
|
||||
end)
|
||||
end
|
||||
Behaviors.Trigger("OnMove", entityData, entityData.oldCoords, entityData.coords)
|
||||
end
|
||||
--- Registers a ClientEntity definition and a proximity trigger that spawns/despawns it.
|
||||
---
|
||||
--- Note: When in-range, the spawned FiveM entity handle is stored on `entityData.spawned`.
|
||||
--- @param entityData EntityData
|
||||
--- @return table Registered point/entity entry (the value stored in ClientEntity.All[entityData.id]).
|
||||
function ClientEntity.Create(entityData)
|
||||
entityData.id = entityData.id or Ids.CreateUniqueId(ClientEntity.All)
|
||||
if ClientEntity.All[entityData.id] then return ClientEntity.All[entityData.id] end
|
||||
entityData.rotation = entityData.rotation or vector3(0.0, 0.0, entityData.heading or 0.0)
|
||||
entityData.invoked = entityData.invoked or GetInvokingResource() or "community_bridge"
|
||||
|
||||
if not entityData.oldRotation or entityData.oldRotation ~= entityData.rotation then
|
||||
if entityData.spawned and DoesEntityExist(entityData.spawned) then
|
||||
if entityData.entityType == 'object' then
|
||||
SetEntityRotation(entityData.spawned, entityData.rotation.x, entityData.rotation.y, entityData.rotation.z, 2, true)
|
||||
else -- Ped/Vehicle heading
|
||||
SetEntityHeading(entityData.spawned, type(entityData.rotation) == 'number' and entityData.rotation or entityData.rotation.z)
|
||||
for k, v in pairs(ClientEntity.OnCreates) do
|
||||
if entityData[k] ~= nil then
|
||||
local success, results = pcall(function()
|
||||
return v(entityData)
|
||||
end)
|
||||
if success then
|
||||
entityData = results or entityData
|
||||
end
|
||||
end
|
||||
entityData.oldRotation = entityData.rotation
|
||||
end
|
||||
|
||||
if entityData.freeze ~= nil and entityData.spawned and IsEntityPositionFrozen(entityData.spawned) then
|
||||
FreezeEntityPosition(entityData.spawned, entityData.freeze)
|
||||
end
|
||||
end
|
||||
|
||||
--- Registers an entity received from the server and sets up proximity spawning.
|
||||
-- @param entityData table Data received from the server via 'community_bridge:client:CreateEntity'
|
||||
function ClientEntity.Create(entityData)
|
||||
entityData.id = entityData.id or Ids.CreateUniqueId(Entities)
|
||||
if Entities[entityData.id] then return Entities[entityData.id] end
|
||||
entityData.rotation = entityData.rotation or vector3(0.0, 0.0, entityData.heading or 0.0)
|
||||
entityData.oldCoords = entityData.oldCoords or vector3(0.0, 0.0, 0.0)
|
||||
entityData.oldRotation = entityData.rotation
|
||||
entityData.invoked = entityData.invoked or GetInvokingResource() or "community_bridge"
|
||||
local entityPoint = Point.Register(entityData.id, entityData.coords, entityData.spawnDistance or 50.0, entityData, SpawnEntity, RemoveEntity, UpdateEntity)
|
||||
Entities[entityData.id] = entityPoint
|
||||
|
||||
ClientEntity.All[entityData.id] = entityPoint
|
||||
ClientEntity.Invoked[entityData.invoked] = ClientEntity.Invoked[entityData.invoked] or {}
|
||||
ClientEntity.Invoked[entityData.invoked][entityData.id] = entityData
|
||||
Behaviors.Trigger("OnCreate", entityPoint)
|
||||
|
||||
for k, v in pairs(entityPoint) do
|
||||
ClientEntity.SetKey(entityData.id, k, v)
|
||||
end
|
||||
return entityPoint
|
||||
end
|
||||
|
||||
--Depricated use ClientEntity.Create instead
|
||||
--- Registers an entity and spawns it in the world if not already spawned.
|
||||
--- Gets the entity that was spawned or nil if player is not in range
|
||||
---@param id ClientEntityId
|
||||
---@return EntityHandle|nil
|
||||
function ClientEntity.GetEntity(id)
|
||||
local entityData = ClientEntity.Get(id)
|
||||
if not entityData then return nil end
|
||||
return entityData.spawned
|
||||
end
|
||||
---Deprecated use ClientEntity.Create instead
|
||||
ClientEntity.Register = ClientEntity.Create
|
||||
|
||||
|
||||
--- Registers multiple entities.
|
||||
--- @param entities table<number, EntityData> List of ClientEntity definitions.
|
||||
--- @return table<ClientEntityId, table> Map of ClientEntity id to registered entries.
|
||||
function ClientEntity.CreateBulk(entities)
|
||||
local registeredEntities = {}
|
||||
for _, entityData in pairs(entities) do
|
||||
@@ -139,96 +176,127 @@ function ClientEntity.CreateBulk(entities)
|
||||
end
|
||||
return registeredEntities
|
||||
end
|
||||
|
||||
-- Depricated use ClientEntity.CreateBulk instead
|
||||
ClientEntity.RegisterBulk = ClientEntity.CreateBulk
|
||||
|
||||
--- Unregisters an entity and removes it from the world if spawned.
|
||||
-- @param id string|number The ID of the entity to unregister.
|
||||
--- Unregisters a ClientEntity registration and deletes its spawned FiveM entity (if any).
|
||||
--- @param id ClientEntityId ClientEntity id (key used in ClientEntity.All / Point system), not a FiveM entity handle.
|
||||
function ClientEntity.Destroy(id)
|
||||
local entityData = Entities[id]
|
||||
local entityData = ClientEntity.All[id]
|
||||
if not entityData then return end
|
||||
Behaviors.Trigger("OnDestroy", entityData)
|
||||
Point.Remove(id)
|
||||
RemoveEntity(entityData)
|
||||
Entities[id] = nil
|
||||
RemoveEntity(entityData)
|
||||
ClientEntity.All[id] = nil
|
||||
end
|
||||
ClientEntity.Unregister = ClientEntity.Destroy
|
||||
|
||||
function ClientEntity.RegisterBehavior(id, behavior)
|
||||
Behaviors.Create(id, behavior)
|
||||
end
|
||||
|
||||
--- Sets a key-value pair for a client entity.
|
||||
---@param id any
|
||||
---@param key any
|
||||
---@param value any
|
||||
---@return nil
|
||||
function ClientEntity.Set(id, key, value)
|
||||
--- Sets a property on a registered ClientEntity entry.
|
||||
--- If the entry defines an On<Key> handler (example: key='coords' -> OnCoords), it will be called.
|
||||
--- @param id ClientEntityId ClientEntity id (key used in ClientEntity.All), not a FiveM entity handle.
|
||||
--- @param key string Field name on the stored entity data table.
|
||||
--- @param value any Value to set.
|
||||
--- @return nil
|
||||
function ClientEntity.SetKey(id, key, value)
|
||||
local entityData = ClientEntity.Get(id)
|
||||
if not entityData then return print(string.format("[ClientEntity] SetKey: Entity %s does not exist", id)) end
|
||||
|
||||
local oldData = entityData[key]
|
||||
if oldData == value then return end
|
||||
if entityData.OnSet then
|
||||
pcall(function (...)
|
||||
return entityData.OnSet(entityData, key, value, oldData)
|
||||
local handlerKey = "On" .. key:sub(1, 1):upper() .. key:sub(2)
|
||||
local handler = rawget(entityData, handlerKey)
|
||||
if handler then
|
||||
pcall(function()
|
||||
handler(entityData, key, value, oldData)
|
||||
end)
|
||||
end
|
||||
if value then
|
||||
entityData[key] = value
|
||||
Behaviors.Trigger("OnSet", entityData, key, value, oldData)
|
||||
return
|
||||
end
|
||||
Behaviors.Trigger("OnSet", entityData, key, value, oldData)
|
||||
entityData[key] = nil
|
||||
entityData[key] = value
|
||||
end
|
||||
|
||||
--- Gets a registered ClientEntity entry.
|
||||
--- @param id ClientEntityId ClientEntity id (key used in ClientEntity.All), not a FiveM entity handle.
|
||||
--- @return EntityData|nil The registered entry; when spawned, entityData.spawned is the FiveM entity handle.
|
||||
function ClientEntity.Get(id)
|
||||
return Entities[id]
|
||||
return ClientEntity.All[id]
|
||||
end
|
||||
|
||||
--- Gets all registered ClientEntity entries keyed by ClientEntity id.
|
||||
--- @return table<ClientEntityId, EntityData>
|
||||
function ClientEntity.GetAll()
|
||||
return Entities
|
||||
return ClientEntity.All
|
||||
end
|
||||
|
||||
function ClientEntity.OnCreate(_type, func)
|
||||
ClientEntity.OnCreates = ClientEntity.OnCreates or {}
|
||||
if not ClientEntity.OnCreates[_type] then
|
||||
ClientEntity.OnCreates[_type] = {}
|
||||
--- Plays or stops an animation on the spawned FiveM entity for a ClientEntity.
|
||||
--- @param id ClientEntityId ClientEntity id.
|
||||
--- @param anim ClientEntityAnim|nil Animation data; pass nil to stop.
|
||||
function ClientEntity.SetAnim(id, anim)
|
||||
local entityData = ClientEntity.Get(id)
|
||||
if not entityData then return print(string.format("[ClientEntity] SetAnim: Entity %s does not exist", id)) end
|
||||
local entity = entityData.spawned
|
||||
if not entity or not DoesEntityExist(entity) then return end
|
||||
if not anim then
|
||||
return Bridge.Anim.Stop(nil, entity)
|
||||
end
|
||||
table.insert(ClientEntity.OnCreates[_type], func)
|
||||
Bridge.Anim.Play(nil, entity, anim.dict, anim.name, anim.blendIn or 8.0, anim.blendOut or -8.0, anim.duration, anim.flags, anim.playbackRate or 0.0, anim.onComplete)
|
||||
end
|
||||
|
||||
function ClientEntity.SetOnSpawn(id, func)
|
||||
local entityData = Entities[id]
|
||||
if not entityData then
|
||||
print(string.format("[ClientEntity] SetOnSpawn: Entity %s does not exist", id))
|
||||
--- Attaches the spawned FiveM entity for a ClientEntity to a target, or detaches when nil.
|
||||
--- @param id ClientEntityId ClientEntity id.
|
||||
--- @param attachData ClientEntityAttach|nil Attachment data; pass nil to detach.
|
||||
function ClientEntity.SetAttach(id, attachData)
|
||||
local entityData = ClientEntity.Get(id)
|
||||
if not entityData then return print(string.format("[ClientEntity] Attach: Entity %s does not exist", id)) end
|
||||
local entity = entityData.spawned
|
||||
if not attachData then
|
||||
if not entityData.spawned or not IsEntityAttached(entityData.spawned) then return end
|
||||
DetachEntity(entityData.spawned, true, true)
|
||||
return
|
||||
end
|
||||
entityData.OnSpawn = func
|
||||
end
|
||||
|
||||
function ClientEntity.SetOnRemove(id, func)
|
||||
local entityData = Entities[id]
|
||||
if not entityData then
|
||||
print(string.format("[ClientEntity] SetOnRemove: Entity %s does not exist", id))
|
||||
return
|
||||
local targetEntity = attachData.target
|
||||
if type(targetEntity) == "string" then
|
||||
targetEntity = Bridge.Entity.Get(targetEntity)?.spawned or targetEntity
|
||||
else
|
||||
local player = GetPlayerFromServerId(targetEntity)
|
||||
if player and player ~= -1 then
|
||||
targetEntity = GetPlayerPed(player)
|
||||
end
|
||||
end
|
||||
entityData.OnRemove = func
|
||||
targetEntity = tonumber(targetEntity)
|
||||
if not targetEntity then return end
|
||||
local bone = attachData.bone or 0
|
||||
local offset = attachData.offset or vector3(0.0, 0.0, 0.0)
|
||||
local rotation = attachData.rotation or vector3(0.0, 0.0, 0.0)
|
||||
AttachEntityToEntity(entity, targetEntity, GetPedBoneIndex(targetEntity, bone), offset.x, offset.y, offset.z, rotation.x, rotation.y, rotation.z, true, true, false, true, 1, true)
|
||||
end
|
||||
|
||||
--- Adds target options to the spawned FiveM entity for a ClientEntity.
|
||||
--- @param id ClientEntityId ClientEntity id.
|
||||
--- @param options table Target config passed to Bridge.Target.AddLocalEntity.
|
||||
function ClientEntity.SetTargets(id, options)
|
||||
local entityData = ClientEntity.Get(id)
|
||||
if not entityData then return end
|
||||
Bridge.Target.RemoveLocalEntity(entityData.spawned)
|
||||
entityData.targets = options
|
||||
if not options then return end
|
||||
Bridge.Target.AddLocalEntity(entityData.spawned, options)
|
||||
end
|
||||
|
||||
--- Updates the stored coords for a ClientEntity and updates its proximity trigger.
|
||||
--- @param id ClientEntityId ClientEntity id.
|
||||
--- @param coords vector3 New coords.
|
||||
function ClientEntity.UpdateCoords(id, coords)
|
||||
local entityData = Entities[id]
|
||||
local entityData = ClientEntity.All[id]
|
||||
if not entityData then
|
||||
print(string.format("[ClientEntity] UpdateCoords: Entity %s does not exist", id))
|
||||
return
|
||||
end
|
||||
entityData.coords = coords
|
||||
Point.UpdateCoords(id, coords)
|
||||
Point.UpdateCoords(id, coords)
|
||||
end
|
||||
|
||||
--- Changes the model used by a ClientEntity and respawns it if currently spawned.
|
||||
--- @param id ClientEntityId ClientEntity id.
|
||||
--- @param model string|number Model name or hash.
|
||||
function ClientEntity.ChangeModel(id, model)
|
||||
local entityData = Entities[id]
|
||||
local entityData = ClientEntity.All[id]
|
||||
if not entityData then return print(string.format("[ClientEntity] ChangeModel: Entity %s does not exist", id)) end
|
||||
|
||||
entityData.model = model
|
||||
@@ -238,51 +306,78 @@ function ClientEntity.ChangeModel(id, model)
|
||||
SpawnEntity(entityData)
|
||||
end
|
||||
|
||||
--- Hooks onto entity creation by checking for a property on the entityData. Includes ServerEntity creations.
|
||||
--- func = function(entityData) return modifiedEntityData end
|
||||
--- @param property any property to look for when creating the entity
|
||||
--- @param func any
|
||||
function ClientEntity.SetOnCreate(property, func)
|
||||
ClientEntity.OnCreates[property] = func
|
||||
end
|
||||
|
||||
--- Sets the OnSpawn callback for a ClientEntity.
|
||||
--- @param id ClientEntityId ClientEntity id.
|
||||
--- @param func fun(entityData: EntityData) Called when in-range spawn happens; entityData.spawned is the FiveM entity handle.
|
||||
function ClientEntity.SetOnSpawn(id, func)
|
||||
local entityData = ClientEntity.All[id]
|
||||
if not entityData then
|
||||
print(string.format("[ClientEntity] SetOnSpawn: Entity %s does not exist", id))
|
||||
return
|
||||
end
|
||||
entityData.OnSpawn = func
|
||||
end
|
||||
|
||||
--- Sets the OnRemove callback for a ClientEntity.
|
||||
--- @param id ClientEntityId ClientEntity id.
|
||||
--- @param func fun(entityData: EntityData) Called when out-of-range removal happens (and before deleting the spawned entity).
|
||||
function ClientEntity.SetOnRemove(id, func)
|
||||
local entityData = ClientEntity.All[id]
|
||||
if not entityData then
|
||||
print(string.format("[ClientEntity] SetOnRemove: Entity %s does not exist", id))
|
||||
return
|
||||
end
|
||||
entityData.OnRemove = func
|
||||
end
|
||||
|
||||
-- Network Event Handlers
|
||||
RegisterNetEvent("community_bridge:client:CreateEntity", function(entityData)
|
||||
local src = source
|
||||
if src ~= 65535 then return end -- Server only
|
||||
ClientEntity.Create(entityData)
|
||||
end)
|
||||
|
||||
RegisterNetEvent("community_bridge:client:CreateEntities", function(entities)
|
||||
local src = source
|
||||
if src ~= 65535 then return end -- Server only
|
||||
ClientEntity.CreateBulk(entities)
|
||||
end)
|
||||
|
||||
RegisterNetEvent("community_bridge:client:DeleteEntity", function(id)
|
||||
ClientEntity.Unregister(id)
|
||||
local src = source
|
||||
if src ~= 65535 then return end -- Server only
|
||||
ClientEntity.Destroy(id)
|
||||
end)
|
||||
|
||||
RegisterNetEvent("community_bridge:client:UpdateEntity", function(id, data)
|
||||
local src = source
|
||||
if src ~= 65535 then return end -- Server only
|
||||
for k, v in pairs(data) do
|
||||
ClientEntity.Set(id, k, v)
|
||||
ClientEntity.SetKey(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
|
||||
if Loaded then return end
|
||||
Loaded = true
|
||||
end)
|
||||
|
||||
-- Resource Stop Cleanup
|
||||
AddEventHandler('onResourceStop', function(resourceName)
|
||||
if resourceName == GetCurrentResourceName() then
|
||||
for id, entityData in pairs(Entities) do
|
||||
Point.Remove(id) -- Clean up point registration
|
||||
RemoveEntity(entityData) -- Clean up spawned game entity
|
||||
for id, entityData in pairs(ClientEntity.All) do
|
||||
Point.Remove(id)
|
||||
RemoveEntity(entityData)
|
||||
end
|
||||
Entities = {} -- Clear local cache
|
||||
ClientEntity.All = {}
|
||||
else
|
||||
for id, entityData in pairs(ClientEntity.Invoked[resourceName] or {}) do
|
||||
Point.Remove(id) -- Clean up point registration
|
||||
RemoveEntity(entityData) -- Clean up spawned game entity
|
||||
Entities[id] = nil
|
||||
Point.Remove(id)
|
||||
RemoveEntity(entityData)
|
||||
ClientEntity.All[id] = nil
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
Reference in new issue
Block a user