Refactor entity behavior to use Bridge.Entity

Replaces all usage of Bridge.ClientEntity and Bridge.ServerEntity with Bridge.Entity across shared behavior modules. Updates initialization in lib/init.lua to use cLib.Entity and marks cLib.ClientEntity and cLib.ServerEntity as deprecated for consistency and future maintainability.
This commit is contained in:
Mr.Crowley committed 2025-09-03 04:06:31 -05:00
1 parent cb9dbdf610
commit dff4622a94
11 files changed
+52 -43

No files matched your search

+7 -7
View File
@@ -18,13 +18,13 @@ function Animation.Play(entityData)
local flags = entityData.anim.flags or Animation.default.flags local flags = entityData.anim.flags or Animation.default.flags
local duration = entityData.anim.duration or Animation.default.duration local duration = entityData.anim.duration or Animation.default.duration
entityData.anim.id = Bridge.Anim.Play(nil, entity, dict, name, 8.0, -8.0, duration, flags, 0.0, onComplete) entityData.anim.id = Bridge.Anim.Play(nil, entity, dict, name, 8.0, -8.0, duration, flags, 0.0, onComplete)
Bridge.ClientEntity.Set(entityData.id, "anim", entityData.anim) Bridge.Entity.Set(entityData.id, "anim", entityData.anim)
entityData.oldAnim = entityData.anim entityData.oldAnim = entityData.anim
Bridge.ClientEntity.Set(entityData.id, "oldAnim", entityData.oldAnim) Bridge.Entity.Set(entityData.id, "oldAnim", entityData.oldAnim)
-- SetTimeout(1000, function() -- SetTimeout(1000, function()
-- if entityData.anim then -- if entityData.anim then
-- entityData.anim.disable = false -- entityData.anim.disable = false
-- Bridge.ClientEntity.Set(entityData.id, "anim", entityData.anim) -- Bridge.Entity.Set(entityData.id, "anim", entityData.anim)
-- end -- end
-- end) -- end)
end end
@@ -36,15 +36,15 @@ function Animation.OnSpawn(entityData)
entityData.anim.disable = false entityData.anim.disable = false
TaskSetBlockingOfNonTemporaryEvents(entityData.spawned, true) TaskSetBlockingOfNonTemporaryEvents(entityData.spawned, true)
SetBlockingOfNonTemporaryEvents(entityData.spawned, true) SetBlockingOfNonTemporaryEvents(entityData.spawned, true)
Bridge.ClientEntity.Set(entityData.id, "anim", entityData.anim) Bridge.Entity.Set(entityData.id, "anim", entityData.anim)
end end
function Animation.OnRemove(entityData) function Animation.OnRemove(entityData)
if not entityData.spawned or not entityData.anim then return end if not entityData.spawned or not entityData.anim then return end
entityData.oldAnim = nil entityData.oldAnim = nil
entityData.anim.disable = true entityData.anim.disable = true
Bridge.ClientEntity.Set(entityData.id, "anim", entityData.anim) Bridge.Entity.Set(entityData.id, "anim", entityData.anim)
Bridge.ClientEntity.Set(entityData.id, "oldAnim", entityData.oldAnim) Bridge.Entity.Set(entityData.id, "oldAnim", entityData.oldAnim)
end end
function Animation.OnUpdate(entityData) function Animation.OnUpdate(entityData)
@@ -58,5 +58,5 @@ function Animation.OnUpdate(entityData)
end end
end end
Bridge.ClientEntity.RegisterBehavior("anim", Animation) Bridge.Entity.RegisterBehavior("anim", Animation)
return Animation return Animation
+6 -4
View File
@@ -14,7 +14,7 @@ function Attach.OnSpawn(entityData)
local entity = entityData.spawned local entity = entityData.spawned
local targetEntity = entityData.attach.target local targetEntity = entityData.attach.target
if type(targetEntity) == "string" then if type(targetEntity) == "string" then
targetEntity = Bridge.ClientEntity.Get(targetEntity)?.spawned or targetEntity targetEntity = Bridge.Entity.Get(targetEntity)?.spawned or targetEntity
else else
local player = GetPlayerFromServerId(targetEntity) local player = GetPlayerFromServerId(targetEntity)
if player and player ~= -1 then if player and player ~= -1 then
@@ -27,13 +27,13 @@ function Attach.OnSpawn(entityData)
local offset = entityData.attach.offset or Attach.default.offset local offset = entityData.attach.offset or Attach.default.offset
local rotation = entityData.attach.rotation or Attach.default.rotation local rotation = entityData.attach.rotation or Attach.default.rotation
AttachEntityToEntity(entity, targetEntity, GetPedBoneIndex(targetEntity, bone), offset.x, offset.y, offset.z, rotation.x, rotation.y, rotation.z, true, true, false, true, 1, true) AttachEntityToEntity(entity, targetEntity, GetPedBoneIndex(targetEntity, bone), offset.x, offset.y, offset.z, rotation.x, rotation.y, rotation.z, true, true, false, true, 1, true)
Bridge.ClientEntity.Set(entityData.id, "attach", entityData.attach) Bridge.Entity.Set(entityData.id, "attach", entityData.attach)
end end
function Attach.Detach(entityData) function Attach.Detach(entityData)
if not entityData.spawned or not IsEntityAttached(entityData.spawned) then return end if not entityData.spawned or not IsEntityAttached(entityData.spawned) then return end
DetachEntity(entityData.spawned, true, true) DetachEntity(entityData.spawned, true, true)
Bridge.ClientEntity.Set(entityData.id, "attach", entityData.attach) Bridge.Entity.Set(entityData.id, "attach", entityData.attach)
end end
function Attach.OnUpdate(entityData) function Attach.OnUpdate(entityData)
@@ -42,9 +42,11 @@ function Attach.OnUpdate(entityData)
return Attach.Detach(entityData) return Attach.Detach(entityData)
end end
local entity = entityData.spawned local entity = entityData.spawned
local coords = GetEntityCoords(entity)
Bridge.Entity.Set(entityData.id, "coords", vector3(coords.x, coords.y, coords.z))
if IsEntityAttached(entity) then return end if IsEntityAttached(entity) then return end
Attach.OnSpawn(entityData) Attach.OnSpawn(entityData)
end end
Bridge.ClientEntity.RegisterBehavior("attach", Attach) Bridge.Entity.RegisterBehavior("attach", Attach)
return Attach return Attach
+5 -5
View File
@@ -19,7 +19,7 @@ function Clothing.ChangeClothes(entityData)
clothing = Bridge.Clothing.GetAppearance(GetPlayerPed(player)) clothing = Bridge.Clothing.GetAppearance(GetPlayerPed(player))
end end
elseif type(clothing) == "string" then elseif type(clothing) == "string" then
local targetEntityData = Bridge.ClientEntity.Get(clothing) local targetEntityData = Bridge.Entity.Get(clothing)
if targetEntityData then if targetEntityData then
clothing = Bridge.Clothing.GetAppearance(targetEntityData.spawned) clothing = Bridge.Clothing.GetAppearance(targetEntityData.spawned)
end end
@@ -29,9 +29,9 @@ function Clothing.ChangeClothes(entityData)
end end
Bridge.Clothing.SetAppearance(entity, clothing) Bridge.Clothing.SetAppearance(entity, clothing)
Bridge.ClientEntity.Set(entityData.id, "clothing", clothing) Bridge.Entity.Set(entityData.id, "clothing", clothing)
entityData.oldClothing = clothing entityData.oldClothing = clothing
Bridge.ClientEntity.Set(entityData.id, "oldClothing", clothing) Bridge.Entity.Set(entityData.id, "oldClothing", clothing)
end end
@@ -73,10 +73,10 @@ function Clothing.OnUpdate(entityData)
SetTimeout(1000, function() SetTimeout(1000, function()
if entityData.clothing then if entityData.clothing then
entityData.clothing.updating = false entityData.clothing.updating = false
Bridge.ClientEntity.Set(entityData.id, "clothing", entityData.clothing) Bridge.Entity.Set(entityData.id, "clothing", entityData.clothing)
end end
end) end)
end end
Bridge.ClientEntity.RegisterBehavior("clothing", Clothing) Bridge.Entity.RegisterBehavior("clothing", Clothing)
return Clothing return Clothing
+9 -9
View File
@@ -21,7 +21,7 @@ function Follow.PedWalkToPos(entityData)
targetCoords = GetEntityCoords(targetCoords) targetCoords = GetEntityCoords(targetCoords)
end end
elseif type(targetCoords) == "string" then elseif type(targetCoords) == "string" then
local targetEntityData = Bridge.ClientEntity.Get(targetCoords) local targetEntityData = Bridge.Entity.Get(targetCoords)
if targetEntityData then if targetEntityData then
targetCoords = GetEntityCoords(targetEntityData.spawned) targetCoords = GetEntityCoords(targetEntityData.spawned)
end end
@@ -31,32 +31,32 @@ function Follow.PedWalkToPos(entityData)
if distance > (entityData.follow.distance or Follow.default.distance) then if distance > (entityData.follow.distance or Follow.default.distance) then
if entityData.anim then if entityData.anim then
entityData.anim.disable = true entityData.anim.disable = true
Bridge.ClientEntity.Set(entityData.id, "anim", entityData.anim) Bridge.Entity.Set(entityData.id, "anim", entityData.anim)
end end
if entityData.scenarios then if entityData.scenarios then
entityData.scenarios.disable = true entityData.scenarios.disable = true
Bridge.ClientEntity.Set(entityData.id, "scenarios", entityData.scenarios) Bridge.Entity.Set(entityData.id, "scenarios", entityData.scenarios)
end end
local speed = entityData.follow.speed or Follow.default.speed local speed = entityData.follow.speed or Follow.default.speed
local heading = GetHeadingFromVector_2d(targetCoords.x - entityPos.x, targetCoords.y - entityPos.y) local heading = GetHeadingFromVector_2d(targetCoords.x - entityPos.x, targetCoords.y - entityPos.y)
TaskGoStraightToCoord(entity, targetCoords.x, targetCoords.y, targetCoords.z, speed, -1, heading, 0.0) TaskGoStraightToCoord(entity, targetCoords.x, targetCoords.y, targetCoords.z, speed, -1, heading, 0.0)
entityData.coords = GetEntityCoords(entity) entityData.coords = GetEntityCoords(entity)
entityData.follow.walking = true entityData.follow.walking = true
Bridge.ClientEntity.Set(entityData.id, "coords", entityData.coords - vector3(0,0,1)) Bridge.Entity.Set(entityData.id, "coords", entityData.coords - vector3(0,0,1))
Bridge.ClientEntity.Set(entityData.id, "follow", entityData.follow) Bridge.Entity.Set(entityData.id, "follow", entityData.follow)
if entityData.follow.OnExit then entityData.follow.OnExit(entityData) end if entityData.follow.OnExit then entityData.follow.OnExit(entityData) end
return false return false
end end
if not entityData.follow.walking then return end if not entityData.follow.walking then return end
entityData.follow.walking = false entityData.follow.walking = false
Bridge.ClientEntity.Set(entityData.id, "follow", entityData.follow) Bridge.Entity.Set(entityData.id, "follow", entityData.follow)
if entityData.anim then if entityData.anim then
entityData.anim.disable = false entityData.anim.disable = false
Bridge.ClientEntity.Set(entityData.id, "anim", entityData.anim) Bridge.Entity.Set(entityData.id, "anim", entityData.anim)
end end
if entityData.scenarios then if entityData.scenarios then
entityData.scenarios.disable = false entityData.scenarios.disable = false
Bridge.ClientEntity.Set(entityData.id, "scenarios", entityData.scenarios) Bridge.Entity.Set(entityData.id, "scenarios", entityData.scenarios)
end end
ClearPedTasks(entity) ClearPedTasks(entity)
if entityData.follow.OnEnter then entityData.follow.OnEnter(entityData) end if entityData.follow.OnEnter then entityData.follow.OnEnter(entityData) end
@@ -71,5 +71,5 @@ function Follow.OnUpdate(entityData)
return Follow.PedWalkToPos(entityData) return Follow.PedWalkToPos(entityData)
end end
Bridge.ClientEntity.RegisterBehavior("follow", Follow) Bridge.Entity.RegisterBehavior("follow", Follow)
return Follow return Follow
+1 -1
View File
@@ -76,5 +76,5 @@ function ParticlesBehaviors.OnMove(entityData)
end end
end end
Bridge.ClientEntity.RegisterBehavior("particles", ParticlesBehaviors) Bridge.Entity.RegisterBehavior("particles", ParticlesBehaviors)
return ParticlesBehaviors return ParticlesBehaviors
+2 -2
View File
@@ -23,7 +23,7 @@ function Scenarios.Play(entityData)
ClearPedTasks(entity) ClearPedTasks(entity)
if not entityData.scenarios.onComplete then return end if not entityData.scenarios.onComplete then return end
entityData.scenarios.disabled = true entityData.scenarios.disabled = true
Bridge.ClientEntity.Set(entityData.id, "scenarios", entityData.scenarios) Bridge.Entity.Set(entityData.id, "scenarios", entityData.scenarios)
entityData.scenarios.onComplete(entityData) entityData.scenarios.onComplete(entityData)
end) end)
@@ -60,5 +60,5 @@ function Scenarios.OnUpdate(entityData)
Scenarios.Play(entityData) Scenarios.Play(entityData)
end end
Bridge.ClientEntity.RegisterBehavior("scenarios", Scenarios) Bridge.Entity.RegisterBehavior("scenarios", Scenarios)
return Scenarios return Scenarios
+2 -2
View File
@@ -36,12 +36,12 @@ function Shop.OnCreate(entityData)
) )
end end
if not IsDuplicityVersion() then return Bridge.ClientEntity.RegisterBehavior("shop", Shop) end if not IsDuplicityVersion() then return Bridge.Entity.RegisterBehavior("shop", Shop) end
RegisterNetEvent("community_bridge:server:OpenShop", function(id) RegisterNetEvent("community_bridge:server:OpenShop", function(id)
local src = source local src = source
if not src then return end if not src then return end
local entityData = Bridge.ServerEntity.Get(id) local entityData = Bridge.Entity.Get(id)
if not entityData or not entityData.shop then if not entityData or not entityData.shop then
return print(string.format("[Shop] OpenShop: Entity %s does not exist or has no shop", id)) return print(string.format("[Shop] OpenShop: Entity %s does not exist or has no shop", id))
end end
+5 -5
View File
@@ -26,7 +26,7 @@ function Stash.OnCreate(entityData)
label = entityData.stash.target.label or Stash.default.target.label, label = entityData.stash.target.label or Stash.default.target.label,
icon = entityData.stash.target.icon or Stash.default.target.icon, icon = entityData.stash.target.icon or Stash.default.target.icon,
canInteract = function(_) canInteract = function(_)
local entData = Bridge.ClientEntity.Get(entityData.id) local entData = Bridge.Entity.Get(entityData.id)
return not entData.stash.disable return not entData.stash.disable
end, end,
onSelect = function() onSelect = function()
@@ -34,16 +34,16 @@ function Stash.OnCreate(entityData)
end end
} }
Bridge.ClientEntity.Set(entityData.id, 'targets', entityData.targets) Bridge.Entity.Set(entityData.id, 'targets', entityData.targets)
end end
end end
if not IsDuplicityVersion() then return Bridge.ClientEntity.RegisterBehavior("stash", Stash) end if not IsDuplicityVersion() then return Bridge.Entity.RegisterBehavior("stash", Stash) end
RegisterNetEvent("community_bridge:server:OpenStash", function(id) RegisterNetEvent("community_bridge:server:OpenStash", function(id)
local src = source local src = source
if not src then return end if not src then return end
local entityData = Bridge.ServerEntity.Get(id) local entityData = Bridge.Entity.Get(id)
if not entityData or not entityData.stash then if not entityData or not entityData.stash then
return print(string.format("[Stash] OpenStash: Entity %s does not exist or has no stash", id)) return print(string.format("[Stash] OpenStash: Entity %s does not exist or has no stash", id))
end end
@@ -56,4 +56,4 @@ RegisterNetEvent("community_bridge:server:OpenStash", function(id)
Bridge.Inventory.OpenStash(src, "stash", id) Bridge.Inventory.OpenStash(src, "stash", id)
end) end)
Bridge.ServerEntity.RegisterBehavior("stash", Stash) Bridge.Entity.RegisterBehavior("stash", Stash)
+2 -2
View File
@@ -26,7 +26,7 @@ function Targets.OnSpawn(entityData)
table.sort(numberedTargets, function(a, b) return (a.label < b.label) end) table.sort(numberedTargets, function(a, b) return (a.label < b.label) end)
Bridge.Target.AddLocalEntity(entityData.spawned, numberedTargets) Bridge.Target.AddLocalEntity(entityData.spawned, numberedTargets)
entityData.oldTargets = entityData.targets entityData.oldTargets = entityData.targets
Bridge.ClientEntity.Set(entityData.id, "oldTargets", entityData.oldTargets) Bridge.Entity.Set(entityData.id, "oldTargets", entityData.oldTargets)
end end
function Targets.OnRemove(entityData) function Targets.OnRemove(entityData)
@@ -57,5 +57,5 @@ function Targets.OnUpdate(entityData)
Targets.OnSpawn(entityData) Targets.OnSpawn(entityData)
end end
end end
Bridge.ClientEntity.RegisterBehavior("targets", Targets) Bridge.Entity.RegisterBehavior("targets", Targets)
return Targets return Targets
+4 -4
View File
@@ -19,7 +19,7 @@ function Weapon.GiveWeapon(entityData)
TaskSwapWeapon(entity, true) TaskSwapWeapon(entity, true)
end end
entityData.oldWeapon = entityData.weapon entityData.oldWeapon = entityData.weapon
Bridge.ClientEntity.Set(entityData.id, "oldWeapon", entityData.oldWeapon) Bridge.Entity.Set(entityData.id, "oldWeapon", entityData.oldWeapon)
end end
function Weapon.OnSpawn(entityData) function Weapon.OnSpawn(entityData)
@@ -44,11 +44,11 @@ function Weapon.OnUpdate(entityData)
SetTimeout(1000, function() SetTimeout(1000, function()
if entityData.weapon then if entityData.weapon then
entityData.weapon.updating = false entityData.weapon.updating = false
Bridge.ClientEntity.Set(entityData.id, "weapon", entityData.weapon) Bridge.Entity.Set(entityData.id, "weapon", entityData.weapon)
end end
end) end)
Bridge.ClientEntity.Set(entityData.id, "weapon", entityData.weapon) Bridge.Entity.Set(entityData.id, "weapon", entityData.weapon)
end end
Bridge.ClientEntity.RegisterBehavior("weapon", Weapon) Bridge.Entity.RegisterBehavior("weapon", Weapon)
return Weapon return Weapon
+9 -2
View File
@@ -59,7 +59,11 @@ cLib.Cache = Cache or Require("lib/cache/shared/cache.lua")
cLib.Marker = Marker or Require("lib/markers/server/server.lua") cLib.Marker = Marker or Require("lib/markers/server/server.lua")
cLib.Particle = Particle or Require("lib/particles/server/particles.lua") cLib.Particle = Particle or Require("lib/particles/server/particles.lua")
cLib.Shell = Shells or Require("lib/shells/server/shells.lua") cLib.Shell = Shells or Require("lib/shells/server/shells.lua")
cLib.ServerEntity = ServerEntity or Require("lib/entities/server/server_entity.lua") cLib.Entity = ServerEntity or Require("lib/entities/server/server_entity.lua")
-- Depricated
cLib.ServerEntity = cLib.Entity
if IsDuplicityVersion() then return cLib end if IsDuplicityVersion() then return cLib end
::client:: ::client::
@@ -71,10 +75,13 @@ cLib.Raycast = Raycast or Require("lib/raycast/client/raycast.lua")
cLib.Point = Point or Require("lib/points/client/points.lua") cLib.Point = Point or Require("lib/points/client/points.lua")
cLib.Particle = Particle or Require("lib/particles/client/particles.lua") cLib.Particle = Particle or Require("lib/particles/client/particles.lua")
cLib.Cache = Cache or Require("lib/cache/client/cache.lua") cLib.Cache = Cache or Require("lib/cache/client/cache.lua")
cLib.ClientEntity = ClientEntity or Require("lib/entities/client/client_entity.lua")
cLib.Marker = Marker or Require("lib/markers/client/markers.lua") cLib.Marker = Marker or Require("lib/markers/client/markers.lua")
cLib.Anim = Anim or Require("lib/anim/client/client.lua") cLib.Anim = Anim or Require("lib/anim/client/client.lua")
cLib.Cutscene = Cutscene or Require("lib/cutscenes/client/cutscene.lua") cLib.Cutscene = Cutscene or Require("lib/cutscenes/client/cutscene.lua")
cLib.Particle = Particle or Require("lib/particles/client/particles.lua") cLib.Particle = Particle or Require("lib/particles/client/particles.lua")
cLib.Entity = ClientEntity or Require("lib/entities/client/client_entity.lua")
-- Deprecated
cLib.ClientEntity = cLib.Entity
return cLib return cLib