Data Realms Fan Forums
http://45.55.195.193/

Particle check issue
http://45.55.195.193/viewtopic.php?f=73&t=17351
Page 1 of 1

Author:  MaximDude [ Sat Dec 12, 2009 12:20 am ]
Post subject:  Particle check issue

Ok, so, I made a brain crab and I wanted to add a nice touch to it - Instead of being just a crab with a brain sprite, I made an attachable brain that can be destroyed without the crab itself being destroyed (Realism and such, you know).

Anyway, the issue is rather stupid I think, but I can't seem to solve it... >________>'

So, the way the thing works is that there is an emitter attached to the attached brain, that emitter emits a MOPixel. A lua script attached to the crab checks whether the particle exists within a certain range and if it doesn't find it, the activity ends.

The issue is that... Well... The activity ends, regardless whether the particle exists or not, or alternatively, the script does nothing at all.

This is the code:
Code:
function Update(self)
   local curdist = 200;
   for particle in MovableMan.Particles do
      local avgx = particle.Pos.X - self.Pos.X;
      local avgy = particle.Pos.Y - self.Pos.Y;
      local dist = math.sqrt(avgx ^ 2 + avgy ^ 2);
      if particle.PresetName == "Brain Check" and dist < curdist then
         self.Existing = 1
      else
         self.Existing = 0
      end
      if self.Existing == 0 then
         ActivityMan:EndActivity();
      else
         self.Existing = nil;
      end
   end
end


Please point out the idiotic mistake here, I really want to get this thing done. >________>'

Author:  411570N3 [ Sat Dec 12, 2009 4:31 am ]
Post subject:  Re: Particle check issue

I thought you were able to just directly have the brain attached and have it work. Try not bothering with Lua and attaching a brain actor to the crab.

Author:  PhantomAGN [ Sat Dec 12, 2009 8:50 am ]
Post subject:  Re: Particle check issue

Check running before emitter starts emitting, maybe?
Your implementation feels odd to me.
How about using lua to look at itself and see if there's a brain attached instead?
Via if there is a brain actor within a close distance, with no emitters needed.

Author:  MaximDude [ Sat Dec 12, 2009 3:09 pm ]
Post subject:  Re: Particle check issue

PhantomAGN wrote:
How about using lua to look at itself and see if there's a brain attached instead?
Via if there is a brain actor within a close distance, with no emitters needed.


I'm not very fluent with lua, so I really didn't think of that. >_________>'
I hope I can get it to work.

Edit:

Wait... On second though... How the hell am I supposed to do that?
It just doesn't seem right. >_________>'

Author:  CaveCricket48 [ Sun Dec 13, 2009 2:13 am ]
Post subject:  Re: Particle check issue

Code:
function Create(self)
   self.brainname = "name"; -- Name of brain attachable goes here
   self.brainclass = "Attachable"; -- Class of brain attachable goes here

   self.brain = nil;

      for i = 1,MovableMan:GetMOIDCount()-1 do
         target = MovableMan:GetMOFromID(i);
    if target.PresetName == self.brainname and target.Class == self.brainclass and target.RootID == self.ID then
   self.brain = target;
   end
end
end

function Update(self)
   if self.brain.ClassName ~= self.brainclass then
   ActivityMan:EndActivity();
   end
end


Attach that to the crab.

Author:  PhantomAGN [ Sun Dec 13, 2009 2:14 am ]
Post subject:  Re: Particle check issue

You can make the brain an actor attached to the crab just in ini code, and then use lua on the crab to check and see if there is a brain actor with the right Presetname within some distance from itself. Given that the brain is always near, and the mission is probably only going to have one of these guys, it should work. The activity would end if the brain ever fell off and was not broken though.
You could also script the mission itself to look for the actor brain, if it's only going to be used in one place.

Ah, ninja'ed by a better solution.

Author:  MaximDude [ Sun Dec 13, 2009 3:41 pm ]
Post subject:  Re: Particle check issue

PhantomAGN wrote:
You can make the brain an actor attached to the crab just in ini code, and then use lua on the crab to check and see if there is a brain actor with the right Presetname within some distance from itself.


If I understanding you correctly, then that won't work.
Attaching actors to other actors via .ini results in crashes during loading.

@ CaveCricket

Attempt to index field 'brain' (a nil value) @ line 14.
:???:

Author:  PhantomAGN [ Sun Dec 13, 2009 8:44 pm ]
Post subject:  Re: Particle check issue

Well shoot. Whoops.
That's a foot in my mouth. I get lua scripting, not ini code.

In that case, disregard whatever I've said.
I'll just follow the solution here and not inject fails.

Author:  CaveCricket48 [ Sun Dec 13, 2009 9:24 pm ]
Post subject:  Re: Particle check issue

Try this:

Code:
function Create(self)
   self.brainname = "name"; -- Name of brain attachable goes here
   self.brainclass = "Attachable"; -- Class of brain attachable goes here
   self.gotbrain = false;

   self.brain = nil;

      for i = 1,MovableMan:GetMOIDCount()-1 do
         target = MovableMan:GetMOFromID(i);
    if target.PresetName == self.brainname and target.Class == self.brainclass and target.RootID == self.ID then
   self.brain = target;
   self.gotbrain = true;
   end
end
end

function Update(self)
   if self.gotbrain == true then
    if self.brain.ClassName ~= self.brainclass then
    ActivityMan:EndActivity();
    end
   end
end

Author:  MaximDude [ Sun Dec 13, 2009 9:54 pm ]
Post subject:  Re: Particle check issue

Well, there don't seem to be any errors and such, there just isn't any effect.
Nothing happens when the attached brain is destroyed. >__________>'

Author:  CaveCricket48 [ Sun Dec 13, 2009 11:05 pm ]
Post subject:  Re: Particle check issue

Whoops, it's "ClassName" not "Class". Silly me.

Code:
function Create(self)
   self.brainname = "name"; -- Name of brain attachable goes here
   self.brainclass = "Attachable"; -- Class of brain attachable goes here
   self.gotbrain = false;

   self.brain = nil;

      for i = 1,MovableMan:GetMOIDCount()-1 do
         target = MovableMan:GetMOFromID(i);
    if target.PresetName == self.brainname and target.ClassName == self.brainclass and target.RootID == self.ID then
   self.brain = target;
   self.gotbrain = true;
   end
end
end

function Update(self)
   if self.gotbrain == true then
    if self.brain.ClassName ~= self.brainclass then
    ActivityMan:EndActivity();
    end
   end
end

Author:  MaximDude [ Sun Dec 13, 2009 11:24 pm ]
Post subject:  Re: Particle check issue

♥♥♥♥ YES IT WORKS!
Massive thanks for getting it to work, you are awesome. :D

Page 1 of 1 All times are UTC [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/