This was crowleys commit and work - Refactor entity behaviors and improve particle handling

Refactored entity behavior triggers to simplify argument passing and added OnSet handler for particle behaviors. Improved particle effect management and event handling, updated locale and lib initialization in several modules, and fixed skill metadata access. Also streamlined point zone logic and menu/zone system initialization for better reliability.
This commit is contained in:
MrNewb committed 2025-10-26 16:20:27 -04:00
1 parent 179c3bad85
commit 444040dd39
13 files changed
+71 -64

No files matched your search

+17 -4
View File
@@ -80,9 +80,9 @@ local function UpdateEntity(_entityData)
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
-- 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 (...)
@@ -167,7 +167,20 @@ end
function ClientEntity.Set(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
entityData[key] = value
local oldData = entityData[key]
if oldData == value then return end
if entityData.OnSet then
pcall(function (...)
return entityData.OnSet(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
end
function ClientEntity.Get(id)
+2 -2
View File
@@ -51,7 +51,7 @@ function Behaviors.Trigger(actionName, clientEntityData, ...)
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
if hasBehaviorArgs and behavior[actionName] then
local success, result = pcall(behavior[actionName], clientEntityData, hasBehaviorArgs, ...)
local success, result = pcall(behavior[actionName], clientEntityData, ...)
if not success then
print(string.format("[ClientEntity] Behavior %s failed: %s", property, result))
end
@@ -60,7 +60,7 @@ function Behaviors.Trigger(actionName, clientEntityData, ...)
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, ...)
local success, result = pcall(behavior[actionName], clientEntityData, ...)
if not success then
print(string.format("[ClientEntity] Behavior %s failed: %s", property, result))
end
+15 -1
View File
@@ -11,7 +11,6 @@ local ParticlesBehaviors = {
color = vector3(255, 255, 255),
loopLength = 5000,
}
}
function ParticlesBehaviors.Start(entityData)
@@ -76,5 +75,20 @@ function ParticlesBehaviors.OnMove(entityData)
end
end
function ParticlesBehaviors.OnSet(entityData, key, value, oldValue)
if key ~= "particles" then return end
if oldValue then
ParticlesBehaviors.OnRemove(entityData)
end
if value then
if value.dict then -- single particle
entityData.particles = {value}
else
entityData.particles = value
end
ParticlesBehaviors.Start(entityData)
end
end
Bridge.Entity.RegisterBehavior("particles", ParticlesBehaviors)
return ParticlesBehaviors
-5
View File
@@ -11,9 +11,6 @@ function Require(modulePath, resourceName)
local id = resourceName .. ":" .. modulePath
if loadedModules[id] then
if BridgeSharedConfig.DebugLevel ~= 0 then
print("^2 Returning cached module [" .. id .. "] ^0")
end
return loadedModules[id]
end
@@ -45,8 +42,6 @@ cLib = {
Prints = Prints or Require("lib/utility/shared/prints.lua"),
Math = Math or Require("lib/utility/shared/math.lua"),
LA = LA or Require("lib/utility/shared/la.lua")
-- Zones = Poly or Require("lib/zones/shared/zones.lua"),
-- Action = Action or Require("lib/entities/shared/actions.lua"),
}
exports('cLib', cLib)
+4 -7
View File
@@ -1,9 +1,8 @@
Particles = {}
Particle = {}
---@diagnostic disable: duplicate-set-field
Ids = Ids or Require("lib/utility/shared/ids.lua")
local point = Require("lib/points/client/points.lua")
---Loads a ptfx asset into memory.
---@param dict string
---@return boolean
@@ -26,7 +25,7 @@ end
--- @param scale number
--- @param color vector3
--- @param looped boolean
--- @param loopLength number|nil
--- @param removeAfter number|nil
--- @return number|nil ptfxHandle -- The handle of the particle effect, or nil if it failed to create.
function Particle.Play(dict, ptfx, pos, rot, scale, color, looped, removeAfter)
LoadPtfxAsset(dict)
@@ -93,8 +92,6 @@ function Particle.Stop(particle)
Particles[tostring(particle)] = nil
end
RegisterNetEvent("community_bridge:Client:Particle", function(data)
if not data then return end
Particle.Create(data)
@@ -110,12 +107,12 @@ end)
RegisterNetEvent("community_bridge:Client:ParticleRemove", function(id)
local particle = Particles[id]
if not particle then return end
Particle.Remove(Drawing[id])
Particle.Stop(id)
end)
RegisterNetEvent("community_bridge:Client:ParticleRemoveBulk", function(ids)
for _, id in pairs(ids) do
Particle.Remove(id)
Particle.Stop(id)
end
end)
+3 -2
View File
@@ -1,9 +1,10 @@
Placeable = Placeable or {}
Utility = Utility or Require("lib/utility/client/utility.lua")
if not lib then Require('init.lua', 'ox_lib') end
local activePlacementProp = nil
lib.locale()
Language = Language or Require("modules/locales/shared.lua")
locale = Language.Locale
-- Object placer --
local placementText = {
locale('placeable_object.place_object_place'),
+6 -19
View File
@@ -1,5 +1,4 @@
local GRIDE_SIZE_X = 8968.83
local GRIDE_SIZE_X = 8968.83
local GRIDE_SIZE_Y = 126200.40
local CELL_SIZE = 500
@@ -48,23 +47,11 @@ function Point.StartLoop()
local coords = GetEntityCoords(playerPed)
local cell = Grid.GetCellByCoords(coords)
for _, point in pairs(cell or {}) do
if point.isEntity then
local entity = point.target
if DoesEntityExist(entity) then
local entityCoords = GetEntityCoords(entity)
local distance = #(coords - entityCoords)
if distance < point.distance then
if not point.inside then
point.inside = true
point.args = point?.onEnter(point, point.args) or point.args
end
elseif point.inside then
point.inside = false
point.args = point?.onExit(point, point.args) or point.args
end
end
else
local distance = #(vector3(coords.x, coords.y, coords.z) - vector3(point.coords.x, point.coords.y, point.coords.z))
local entity = point.target
local targetCoords = point.isEntity and DoesEntityExist(entity) and GetEntityCoords(entity) or point.coords
if not point.disable and targetCoords then
targetCoords = vector3(targetCoords.x, targetCoords.y, targetCoords.z)
local distance = #(coords - targetCoords)
if distance < point.distance then
if not point.inside then
point.inside = true