View unanswered posts | View active topics It is currently Fri Dec 27, 2024 7:31 am



Reply to topic  [ 9 posts ] 
 Selectively removing things from lists 
Author Message
User avatar

Joined: Thu May 28, 2009 3:59 pm
Posts: 209
Reply with quote
Post Selectively removing things from lists
Yet another C4 lua related question.
The normal vanilla C4, and the recent mods based on it, use the creation of a list so the detonator can tell all the C4 bombs on that list to explode. I have run into a problem mucking with that code where I have a Proximity sensor that detects any actor within a small radius, then detonates the C4 spray in a larger radius. I have that part working, but there is a bug in there that sometimes causes CC to crash to desktop. My best guess is that since the Proxy Detonator is exploding only some of the C4 spray in the list and not clearing the list--like the normal detonator does--that when another call to detonate the spray that is already detonated crashes the game.

So, to check to see if this is what is causing the problem, and to solve it if it is, the script needs to remove the detonated c4 spray from the list when it is detonated. I have not had any luck figuring out how to go about doing that, anyone have an idea?


Fri Jun 26, 2009 1:31 am
Profile
User avatar

Joined: Tue Nov 06, 2007 6:58 am
Posts: 2054
Reply with quote
Post Re: Selectively removing things from lists
When it's created, track it's own list location.
THen set lisst[lisstlocation] to nil.


Fri Jun 26, 2009 1:49 am
Profile
User avatar

Joined: Sun Jul 13, 2008 9:57 am
Posts: 4886
Location: some compy
Reply with quote
Post Re: Selectively removing things from lists
in other words, when you add it to the list in create(self), add this
Code:
self.thisC4 = #<listname>
and this to destroy(self),
Code:
table.remove(<listname>, self.thisC4)

edit:typos <_<


Fri Jun 26, 2009 4:47 am
Profile WWW
User avatar

Joined: Tue Nov 06, 2007 6:58 am
Posts: 2054
Reply with quote
Post Re: Selectively removing things from lists
table.remove shifts things down the list, invalidating the thisc4 variables.


Fri Jun 26, 2009 4:48 am
Profile
User avatar

Joined: Thu May 28, 2009 3:59 pm
Posts: 209
Reply with quote
Post 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.


Fri Jun 26, 2009 5:37 am
Profile
User avatar

Joined: Sun Jul 13, 2008 9:57 am
Posts: 4886
Location: some compy
Reply with quote
Post Re: Selectively removing things from lists
mail2345 wrote:
table.remove shifts things down the list, invalidating the thisc4 variables.

really? good to know, thanks mail.


Fri Jun 26, 2009 7:25 am
Profile WWW
User avatar

Joined: Tue Nov 06, 2007 6:58 am
Posts: 2054
Reply with quote
Post Re: Selectively removing things from lists
Figured that out after an hour's worth of muttering "What the ♥♥♥♥!" at my laptop.

Anyway try:
Code:
if not(soundexpposset) and c4ListS[i] ~= nil then
self.explosion.Pos = c4ListS[i].Pos;
soundexpposset = true
end

And in create:
Code:
soundexpposset = false


Fri Jun 26, 2009 7:31 am
Profile
User avatar

Joined: Thu May 28, 2009 3:59 pm
Posts: 209
Reply with quote
Post Re: Selectively removing things from lists
Is it safe to assume that the true/false status on that will be specific to individual proxy sensors and not for all proxy sensors?


Fri Jun 26, 2009 7:41 pm
Profile
User avatar

Joined: Tue Nov 06, 2007 6:58 am
Posts: 2054
Reply with quote
Post Re: Selectively removing things from lists
Whoops!
Forgot about that.
Just add self. infront of soundexpposset


Fri Jun 26, 2009 7:43 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 9 posts ] 

Who is online

Users browsing this forum: No registered users


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.037s | 15 Queries | GZIP : Off ]