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



Reply to topic  [ 12 posts ] 
 Particle check issue 
Author Message
User avatar

Joined: Wed Nov 22, 2006 3:19 pm
Posts: 2073
Reply with quote
Post 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. >________>'


Sat Dec 12, 2009 12:20 am
Profile
User avatar

Joined: Wed Jan 07, 2009 10:26 am
Posts: 4074
Location: That quaint little British colony down south
Reply with quote
Post 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.


Sat Dec 12, 2009 4:31 am
Profile WWW
User avatar

Joined: Mon Jun 29, 2009 2:40 am
Posts: 610
Location: Deep below The Map of Mars
Reply with quote
Post 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.


Sat Dec 12, 2009 8:50 am
Profile
User avatar

Joined: Wed Nov 22, 2006 3:19 pm
Posts: 2073
Reply with quote
Post 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. >_________>'


Sat Dec 12, 2009 3:09 pm
Profile
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 13144
Location: Here
Reply with quote
Post 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.


Sun Dec 13, 2009 2:13 am
Profile
User avatar

Joined: Mon Jun 29, 2009 2:40 am
Posts: 610
Location: Deep below The Map of Mars
Reply with quote
Post 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.


Sun Dec 13, 2009 2:14 am
Profile
User avatar

Joined: Wed Nov 22, 2006 3:19 pm
Posts: 2073
Reply with quote
Post 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.
:???:


Sun Dec 13, 2009 3:41 pm
Profile
User avatar

Joined: Mon Jun 29, 2009 2:40 am
Posts: 610
Location: Deep below The Map of Mars
Reply with quote
Post 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.


Sun Dec 13, 2009 8:44 pm
Profile
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 13144
Location: Here
Reply with quote
Post 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


Sun Dec 13, 2009 9:24 pm
Profile
User avatar

Joined: Wed Nov 22, 2006 3:19 pm
Posts: 2073
Reply with quote
Post 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. >__________>'


Sun Dec 13, 2009 9:54 pm
Profile
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 13144
Location: Here
Reply with quote
Post 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


Sun Dec 13, 2009 11:05 pm
Profile
User avatar

Joined: Wed Nov 22, 2006 3:19 pm
Posts: 2073
Reply with quote
Post Re: Particle check issue
♥♥♥♥ YES IT WORKS!
Massive thanks for getting it to work, you are awesome. :D


Sun Dec 13, 2009 11:24 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 12 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.050s | 13 Queries | GZIP : Off ]