Jamazzz update to particles
Huge shout out to jamazzz for fixing particles. Pending CreateOnEntity and CreateOnEntityBone (untested)
This commit is contained in:
1 parent
bd0074a156
commit
7d43d65058
2 files changed
+58
-29
No files matched your search
@@ -110,7 +110,7 @@ Bridge.RegisterModule("Raycast", cLib.Raycast)
|
|||||||
Bridge.RegisterModule("PlaceableObject", cLib.PlaceableObject)
|
Bridge.RegisterModule("PlaceableObject", cLib.PlaceableObject)
|
||||||
Bridge.RegisterModule("Point", cLib.Point)
|
Bridge.RegisterModule("Point", cLib.Point)
|
||||||
Bridge.RegisterModule("Object", cLib.Object)
|
Bridge.RegisterModule("Object", cLib.Object)
|
||||||
|
Bridge.RegisterModule("Particle", cLib.Particle)
|
||||||
|
|
||||||
|
|
||||||
-- Fill the bridge tables with player data.
|
-- Fill the bridge tables with player data.
|
||||||
|
|||||||
@@ -1,22 +1,20 @@
|
|||||||
Particle = {}
|
Particle = {}
|
||||||
Particles = {}
|
|
||||||
|
|
||||||
|
---Loads a ptfx asset into memory.
|
||||||
--- Load a particle dictionary. This function will block until the dictionary is loaded.
|
---@param dict string
|
||||||
--- @param dict string -- The name of the particle dictionary to load.
|
---@return boolean
|
||||||
--- @return boolean -- Returns true if the dictionary was loaded successfully, false otherwise.
|
function LoadPtfxAsset(dict)
|
||||||
--- @throws string -- Throws an error if the dictionary fails to load after 100 attempts.
|
|
||||||
function Particle.LoadDict(dict)
|
|
||||||
RequestNamedPtfxAsset(dict)
|
|
||||||
local failed = 100
|
local failed = 100
|
||||||
while not HasNamedPtfxAssetLoaded(dict) and failed >= 0 do
|
while not HasNamedPtfxAssetLoaded(dict) and failed >= 0 do
|
||||||
|
RequestNamedPtfxAsset(dict)
|
||||||
failed = failed - 1
|
failed = failed - 1
|
||||||
Wait(50)
|
Wait(100)
|
||||||
end
|
end
|
||||||
assert(failed >= 0, "Failed to load particle dictionary: " .. dict)
|
assert(failed > 0, "Failed to load dict asset: " .. dict)
|
||||||
return true
|
return HasNamedPtfxAssetLoaded(dict)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Create a particle effect at the specified position and rotation.
|
--- Create a particle effect at the specified position and rotation.
|
||||||
--- @param dict string
|
--- @param dict string
|
||||||
--- @param ptfx string
|
--- @param ptfx string
|
||||||
@@ -28,26 +26,57 @@ end
|
|||||||
--- @param loopLength number|nil
|
--- @param loopLength number|nil
|
||||||
--- @return number|nil ptfxHandle -- The handle of the particle effect, or nil if it failed to create.
|
--- @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)
|
function Particle.Create(dict, ptfx, pos, rot, scale, color, looped, loopLength)
|
||||||
if not Particle.LoadDict(dict) then return end
|
LoadPtfxAsset(dict)
|
||||||
UseParticleFxAssetNextCall(dict)
|
CreateThread(function()
|
||||||
local handle = nil
|
UseParticleFxAssetNextCall(dict)
|
||||||
if looped then
|
|
||||||
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)
|
|
||||||
if loopLength then
|
|
||||||
Wait(loopLength)
|
|
||||||
StopParticleFxLooped(handle, 0)
|
|
||||||
RemoveParticleFx(handle, false)
|
|
||||||
end
|
|
||||||
else
|
|
||||||
SetParticleFxNonLoopedColour(color.x, color.y, color.z)
|
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)
|
if looped then
|
||||||
RemoveParticleFx(handle, false)
|
StartParticleFxLoopedAtCoord(ptfx, pos.x, pos.y, pos.z, rot.x, rot.y, rot.z, scale, false, false, false, false)
|
||||||
end
|
if loopLength then
|
||||||
return handle
|
Wait(loopLength)
|
||||||
|
RemoveParticleFxInRange(pos.x, pos.y, pos.z, 0.01)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
StartParticleFxNonLoopedAtCoord(ptfx, pos.x, pos.y, pos.z, rot.x, rot.y, rot.z, scale, false, false, false, false)
|
||||||
|
end
|
||||||
|
RemoveNamedPtfxAsset(ptfx)
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- need to add looping effects (regarless of if its a looped particle or not)
|
function Particle.CreateOnEntity(dict, ptfx, entity, offset, rot, scale, color, looped, loopLength)
|
||||||
|
LoadPtfxAsset(dict)
|
||||||
|
UseParticleFxAssetNextCall(dict)
|
||||||
|
SetParticleFxNonLoopedColour(color.x, color.y, color.z)
|
||||||
|
local particle = nil
|
||||||
|
if looped then
|
||||||
|
particle = StartNetworkedParticleFxLoopedOnEntity(ptfx, entity, offset.x, offset.y, offset.z, rot.x, rot.y, rot.z, scale, false, false, false)
|
||||||
|
if loopLength then
|
||||||
|
Wait(loopLength)
|
||||||
|
RemoveParticleFxFromEntity(entity)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
particle = StartNetworkedParticleFxLoopedOnEntity(ptfx, entity, offset.x, offset.y, offset.z, rot.x, rot.y, rot.z, scale, false, false, false)
|
||||||
|
end
|
||||||
|
RemoveNamedPtfxAsset(ptfx)
|
||||||
|
return particle
|
||||||
|
end
|
||||||
|
|
||||||
|
function Particle.CreateOnEntityBone(dict, ptfx, entity, bone, offset, rot, scale, color, looped, loopLength)
|
||||||
|
LoadPtfxAsset(dict)
|
||||||
|
UseParticleFxAssetNextCall(dict)
|
||||||
|
SetParticleFxNonLoopedColour(color.x, color.y, color.z)
|
||||||
|
local particle = nil
|
||||||
|
if looped then
|
||||||
|
particle = StartNetworkedParticleFxLoopedOnEntityBone(ptfx, entity, offset.x, offset.y, offset.z, rot.x, rot.y, rot.z, bone, scale, false, false, false)
|
||||||
|
if loopLength then
|
||||||
|
Wait(loopLength)
|
||||||
|
RemoveParticleFxFromEntity(entity)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
particle = StartNetworkedParticleFxNonLoopedOnEntityBone(ptfx, entity, offset.x, offset.y, offset.z, rot.x, rot.y, rot.z, bone, scale, false, false, false)
|
||||||
|
end
|
||||||
|
RemoveNamedPtfxAsset(ptfx)
|
||||||
|
return particle
|
||||||
|
end
|
||||||
|
|
||||||
return Particle
|
return Particle
|
||||||
Reference in new issue
Block a user