Added behaviors and documentation to oxlibs zones

Will provide file in example when more features are implimented
This commit is contained in:
Mr.Crowley committed 2025-08-23 22:53:49 -05:00
1 parent 59fa75a618
commit 8c309e248e
11 files changed
+418 -134

No files matched your search

+20
View File
@@ -0,0 +1,20 @@
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()
@@ -0,0 +1,56 @@
Utility = Utility or Require("lib/utility/client/utility.lua")
local ParticlesBehaviors = {
tag = "particles",
default = {
dict = "cut_exile3",
ptfx = "cs_ex3_wheel_spin",
offset = vector3(0, 0, 0),
rotation = vector3(0, 0, 0),
size = 1.0,
color = vector3(255, 255, 255),
loopLength = 5000,
}
}
function ParticlesBehaviors.OnSpawn(entityData)
if not entityData.particles then return end
if entityData.particles.dict then -- single particle
entityData.particles = {entityData.particles}
end
for _, particleData in ipairs(entityData.particles) do
local position = vector3(entityData.coords.x, entityData.coords.y, entityData.coords.z)
local rotation = vector3(entityData.rotation.x, entityData.rotation.y, entityData.rotation.z)
position = position + (particleData.offset?.xyz or vector3(0, 0, 0))
rotation = rotation + (particleData.rotation?.xyz or vector3(0, 0, 0))
particleData.playing = Particle.Play(
particleData.dict or ParticlesBehaviors.default.dict,
particleData.ptfx or ParticlesBehaviors.default.ptfx,
position,
rotation,
particleData.size or ParticlesBehaviors.default.size,
particleData.color or ParticlesBehaviors.default.color,
particleData.looped,
particleData.loopLength or ParticlesBehaviors.default.loopLength
)
end
end
function ParticlesBehaviors.OnRemove(entityData)
if not entityData.particles then return end
for _, particleData in ipairs(entityData.particles) do
if particleData.playing then
Particle.Stop(particleData.playing)
particleData.playing = nil
end
end
end
-- function ParticlesBehaviors.OnUpdate(entityData)
-- if not entityData.particles then return end
-- end
return ParticlesBehaviors
+54
View File
@@ -0,0 +1,54 @@
local Targets = {
tag = "targets",
default = {
label = "Default Target Label",
distance = 2,
}
}
function Targets.OnSpawn(entityData)
if not entityData.spawned or not entityData.target then return end
if entityData.targets?.label then
entityData.newTargets = {entityData.targets}
else
entityData.newTargets = entityData.targets or {}
end
for k, v in pairs(entityData.newTargets) do
local onSelect = v.onSelect
if onSelect then
v.onSelect = function(entity)
onSelect(entityData, entity)
end
end
end
Target.AddLocalEntity(entityData.spawned, entityData.newTargets)
entityData.oldTargets = entityData.newTargets
end
function Targets.OnRemove(entityData)
if not entityData.spawned or not entityData.newTargets then return end
Target.RemoveLocalEntity(entityData.spawned)
end
function Targets.OnUpdate(entityData)
if not entityData.spawned or not entityData.newTargets then return end
for i, target in ipairs(entityData.oldTargets) do
local newTarget = entityData.targets.label
if newTarget then
entityData.newTargets = {entityData.targets}
end
newTarget = entityData.newTargets[i]
if newTarget
and target.label ~= newTarget.label
or target.distance ~= newTarget.distance
or target.description ~= newTarget.description
then
Targets.OnRemove(entityData)
Targets.OnSpawn(entityData)
end
end
end
return Targets