Files
community_bridge/lib/particles/client/particles.lua
T

53 lines
1.9 KiB
Lua
Raw Normal View History

2025-04-08 16:47:27 -05:00
Particle = {}
Particles = {}
2025-02-10 01:01:32 -06:00
2025-04-08 16:47:27 -05:00
--- Load a particle dictionary. This function will block until the dictionary is loaded.
--- @param dict string -- The name of the particle dictionary to load.
--- @return boolean -- Returns true if the dictionary was loaded successfully, false otherwise.
--- @throws string -- Throws an error if the dictionary fails to load after 100 attempts.
function Particle.LoadDict(dict)
RequestNamedPtfxAsset(dict)
local failed = 100
2025-02-10 01:01:32 -06:00
while not HasNamedPtfxAssetLoaded(dict) and failed >= 0 do
failed = failed - 1
2025-04-08 16:47:27 -05:00
Wait(50)
2025-02-10 01:01:32 -06:00
end
2025-04-08 16:47:27 -05:00
assert(failed >= 0, "Failed to load particle dictionary: " .. dict)
return true
end
2025-02-10 01:01:32 -06:00
2025-04-08 16:47:27 -05:00
--- Create a particle effect at the specified position and rotation.
--- @param dict string
--- @param ptfx string
--- @param pos vector3
--- @param rot vector3
--- @param scale number
--- @param color vector3
--- @param looped boolean
--- @param loopLength number|nil
--- @return number|nil ptfxHandle -- The handle of the particle effect, or nil if it failed to create.
function Particle.Create(dict, ptfx, pos, rot, scale, color, looped, loopLength)
if not Particle.LoadDict(dict) then return end
2025-02-10 01:01:32 -06:00
UseParticleFxAssetNextCall(dict)
2025-04-08 16:47:27 -05:00
local handle = nil
2025-02-10 01:01:32 -06:00
if looped then
2025-04-08 16:47:27 -05:00
handle = StartParticleFxLoopedAtCoord(ptfx, pos.x, pos.y, pos.z, rot.x, rot.y, rot.z, scale, false, false, false, false)
SetParticleFxLoopedColour(handle, color.x, color.y, color.z, false)
2025-02-10 01:01:32 -06:00
if loopLength then
Wait(loopLength)
2025-04-08 16:47:27 -05:00
StopParticleFxLooped(handle, 0)
RemoveParticleFx(handle, false)
2025-02-10 01:01:32 -06:00
end
else
2025-04-08 16:47:27 -05:00
SetParticleFxNonLoopedColour(color.x, color.y, color.z)
handle = StartParticleFxNonLoopedAtCoord(ptfx, pos.x, pos.y, pos.z, rot.x, rot.y, rot.z, scale, false, false, false)
RemoveParticleFx(handle, false)
2025-02-10 01:01:32 -06:00
end
2025-04-08 16:47:27 -05:00
return handle
2025-02-10 01:01:32 -06:00
end
2025-04-08 16:47:27 -05:00
-- need to add looping effects (regarless of if its a looped particle or not)
return Particle