Skip to content

Commit

Permalink
Try allowing recursive debris spawn attempts
Browse files Browse the repository at this point in the history
  • Loading branch information
thecraftianman committed Sep 6, 2024
1 parent c8a1827 commit f321296
Showing 1 changed file with 25 additions and 19 deletions.
44 changes: 25 additions & 19 deletions lua/acf/damage/debris_cl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,29 @@ end

local EntData = {}

local function SpawnDebris(EntID, Normal, Power, CanGib, Ignite)
timer.Simple(0, function()
local EntInfo = EntData[EntID]
if not EntInfo then return SpawnDebris(EntID, Normal, Power, CanGib, Ignite) end

local NewColor = EntInfo.Color:ToVector() * math.Rand(0.3, 0.6)

ACF.CreateDebris(
EntInfo.Model,
EntInfo.Position,
EntInfo.Angles,
EntInfo.Material,
NewColor:ToColor(),
Normal,
Power,
CanGib,
Ignite
)

EntData[EntID] = nil
end)
end

-- Store data of potentially ACF-killed entities for debris use, then remove from cache soon after
hook.Add("EntityRemoved", "ACF_Debris_TrackEnts", function(Ent)
local EntID = Ent:EntIndex()
Expand All @@ -177,7 +200,7 @@ hook.Add("EntityRemoved", "ACF_Debris_TrackEnts", function(Ent)
Angles = Ent:GetAngles(),
}

timer.Simple(2, function()
timer.Simple(10, function()
if not EntData[EntID] then return end
EntData[EntID] = nil
end)
Expand All @@ -190,24 +213,7 @@ net.Receive("ACF_Debris", function()
local CanGib = net.ReadBool()
local Ignite = net.ReadBool()

timer.Simple(0.01, function()
local EntInfo = EntData[EntID]
local NewColor = EntInfo.Color:ToVector() * math.Rand(0.3, 0.6)

ACF.CreateDebris(
EntInfo.Model,
EntInfo.Position,
EntInfo.Angles,
EntInfo.Material,
NewColor:ToColor(),
Normal,
Power,
CanGib,
Ignite
)

EntData[EntID] = nil
end)
SpawnDebris(EntID, Normal, Power, CanGib, Ignite)
end)

game.AddParticles("particles/fire_01.pcf")
Expand Down

0 comments on commit f321296

Please sign in to comment.