Re: Selectively removing things from lists
So here was my blind stab at trying to get lucky implementing that
Code:
function Create(self)
if c4ListS == nil then
c4ListS = { };
end
c4ListS[#c4ListS + 1] = self;
self.thisC4 = #c4ListS
end
function Destroy(self)
c4ListS[self.thisC4] = nil;
end
I am not getting any CtDs, but the first explosion--detonated by the proxy mine--does not always explode all of the c4 within range, and then following detonations usually do not work and give the following error
Code:
proxydetonator.lua:19: attempt to index field '?' (a nil value)
since it will probably help to show it, proxydetonator.lua look like
Code:
function Create(self)
self.explosion = CreateAEmitter("Explosion Sound");
end
function Update(self)
for actor in MovableMan.Actors do
local avgx = actor.Pos.X - self.Pos.X;
local avgy = actor.Pos.Y - self.Pos.Y;
local dist = math.sqrt(avgx ^ 2 + avgy ^ 2);
if dist < 50 then
self:GibThis()
end
end
end
function Destroy(self)
for i=1,#c4ListS do
if MovableMan:IsParticle(c4ListS[i]) then
self.explosion.Pos = c4ListS[1].Pos; --Line 19... hah, I see what the problem is now
for p in MovableMan.Particles do
local avgx2 = p.Pos.X - self.Pos.X;
local avgy2 = p.Pos.Y - self.Pos.Y;
local dist2 = math.sqrt(avgx2 ^ 2 + avgy2 ^ 2);
if dist2 < 150 then
if p.PresetName == "C4 Spray Filler" or p.PresetName == "Active C4 Spray Filler" then
p.Lifetime = 1
elseif (c4ListS[i].Pos - p.Pos).Magnitude < 5 then
p.Vel = Vector(p.Vel.X * 1.25, p.Vel.Y *1.25)
c4ListS[i]:GibThis();
MovableMan:AddParticle(self.explosion);
end
--c4ListS[i]:GibThis();
end
end
end
end
--c4ListS = { };
end
OK... Apparently I need to get the list position for the first non-nil entry for placing the sound effect.