From bfdd76898701be6926e0536767dba9f0d4295f8b Mon Sep 17 00:00:00 2001 From: gononono64 <96976330+gononono64@users.noreply.github.com> Date: Mon, 10 Feb 2025 01:01:32 -0600 Subject: [PATCH] fixing playerjoining boo boo woopsie doodles. My bad --- lib/client/particles.lua | 64 ++++++++++++++++++++++++ lib/shared/la.lua | 86 +++++++++++++++++++++++++++++++++ lib/shared/rebound_entities.lua | 3 +- 3 files changed, 152 insertions(+), 1 deletion(-) create mode 100644 lib/client/particles.lua diff --git a/lib/client/particles.lua b/lib/client/particles.lua new file mode 100644 index 0000000..7fa6463 --- /dev/null +++ b/lib/client/particles.lua @@ -0,0 +1,64 @@ + +function CreateParticleFX(dict, ptfx, pos, rot, scale, color, looped, loopLength) + CreateThread(function() + local failed = 5 + while not HasNamedPtfxAssetLoaded(dict) and failed >= 0 do + RequestNamedPtfxAsset(ptfx) + failed = failed - 1 + Wait(0) + end + + UseParticleFxAssetNextCall(dict) + SetParticleFxNonLoopedColour(color.x, color.y, color.z) + if looped then + StartParticleFxLoopedAtCoord(ptfx, pos.x, pos.y, pos.z, rot.x, rot.y, rot.z, scale, false, false, false, false) + Wait(loopLength) + RemoveParticleFxInRange(pos.x, pos.y, pos.z, 0.01) + 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 + +function CreateParticleFXOnEntityBone(dict, ptfx, entity, bone, offset, rot, scale, color, looped, loopLength) + local failed = 5 + while not HasNamedPtfxAssetLoaded(dict) and failed >= 0 do + RequestNamedPtfxAsset(ptfx) + failed = failed - 1 + Wait(0) + end + + UseParticleFxAssetNextCall(dict) + SetParticleFxNonLoopedColour(color.x, color.y, color.z) + local bleh = nil + if looped then + bleh = 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 + bleh = StartNetworkedParticleFxNonLoopedOnEntityBone(ptfx, entity, offset.x, offset.y, offset.z, rot.x, rot.y, rot.z, bone, scale, false, false, false) + end + RemoveNamedPtfxAsset(ptfx) + return bleh +end + + + +function PlayParticleFX(dict, name, looped, x, y, z, rotX, rotY, rotZ, scale) + RequestNamedPtfxAsset(dict) + while not HasNamedPtfxAssetLoaded(dict) do + Wait(0) + end + SetPtfxAssetNextCall(dict) + UseParticleFxAssetNextCall(dict) + local particle = nil + if looped then + particle = StartParticleFxLoopedAtCoord(name, x, y, z , rotX, rotY, rotZ, scale) + else + particle = StartParticleFxNonLoopedAtCoord(name, x, y, z, rotX, rotY, rotZ, scale, false, false, false) + end + return particle +end \ No newline at end of file diff --git a/lib/shared/la.lua b/lib/shared/la.lua index 20b0987..2539807 100644 --- a/lib/shared/la.lua +++ b/lib/shared/la.lua @@ -402,6 +402,92 @@ LA.MultiplyMatrixByVector = function(m, v) return result end +--Slines +LA.SplineLerp = function(nodes, start, endPos, t) + -- Ensure t is clamped between 0 and 1 + t = LA.Clamp(t, 0, 1) + + -- Find the two closest nodes around t + local prevNode, nextNode = nil, nil + for i = 1, #nodes - 1 do + if nodes[i].time <= t and nodes[i + 1].time >= t then + prevNode, nextNode = nodes[i], nodes[i + 1] + break + end + end + + -- Edge cases: If t is before or after the defined range + if not prevNode then return start end + if not nextNode then return endPos end + + -- Normalize t within the segment + local segmentT = (t - prevNode.time) / (nextNode.time - prevNode.time) + + -- Interpolate the value (y-axis) + local smoothedT = LA.Lerp(prevNode.value, nextNode.value, segmentT) + + -- Perform final Lerp using the interpolated smoothing factor + return LA.Lerp(start, endPos, smoothedT) +end + +LA.SplineSmooth = function(nodes, points, t) + -- Ensure valid input + if #points < 2 then return points end + t = LA.Clamp(t, 0, 1) + + local smoothedPoints = {} + + for i = 1, #points - 1 do + local smoothedPos = LA.SplineLerp(nodes, points[i], points[i + 1], t) + table.insert(smoothedPoints, smoothedPos) + end + + -- Ensure last point remains unchanged + table.insert(smoothedPoints, points[#points]) + + return smoothedPoints +end + +LA.Spline = function(points, resolution) + -- Ensure valid input + if #points < 2 then return points end + + -- Create a list of nodes + local nodes = {} + for i = 1, #points do + table.insert(nodes, { time = i / (#points - 1), value = i }) + end + + -- Smooth the points + local smoothedPoints = {} + for i = 0, 1, resolution do + local smoothedPos = LA.SplineSmooth(nodes, points, i) + table.insert(smoothedPoints, smoothedPos) + end + + return smoothedPoints +end + +LA.SplineCatmullRom = function(points, resolution) + -- Ensure valid input + if #points < 4 then return points end + + -- Create a list of nodes + local nodes = {} + for i = 1, #points do + table.insert(nodes, { time = i / (#points - 1), value = i }) + end + + -- Smooth the points + local smoothedPoints = {} + for i = 0, 1, resolution do + local smoothedPos = LA.SplineSmooth(nodes, points, i) + table.insert(smoothedPoints, smoothedPos) + end + + return smoothedPoints +end + exports('LA', LA) return LA diff --git a/lib/shared/rebound_entities.lua b/lib/shared/rebound_entities.lua index b75ecc6..1f64f7a 100644 --- a/lib/shared/rebound_entities.lua +++ b/lib/shared/rebound_entities.lua @@ -226,7 +226,8 @@ function ReboundEntities.GetAccessibleList(src) return list end -RegisterNetEvent("playerJoining", function(src, _) +RegisterNetEvent("playerJoining", function() + local src = source ReboundEntities.Refresh(src) end)