Data Realms Fan Forums
http://45.55.195.193/

Trip Mine script not working
http://45.55.195.193/viewtopic.php?f=73&t=16447
Page 1 of 1

Author:  CaveCricket48 [ Sat Sep 05, 2009 8:16 pm ]
Post subject:  Trip Mine script not working

I have a script that is attached to an MOSRotating. The script is suppose to find other MOSRs of its type and then shoot an MORay at them for the "laser." If an actor touches one of the lasers, then the 2 forming that laser gib. The problem is that it doesn't make the laser or the MORay. The script is below.

Code:
function Create(self)
   self.haspartner = false;
   self.destroyself = false;
end

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 dist < curdist and particle.PresetName == "Particle C Trip Mine Layer Active" and particle.ID ~= self.ID then
   self.partner = particle;
   self.haspartner = true;
   end
    end

   if self.haspartner == true then
   local partnerdir = math.atan2(-(self.partner.Pos.Y-self.Pos.Y),(self.partner.Pos.X-self.Pos.X));
   local triplaser = CreateMOSRotating("Particle C Trip Mine Layer Laser");
   triplaser.Pos = self.Pos;
   triplaser.RotAngle = partnerdir;
   MovableMan:AddParticle(triplaser);
--   triplaser.Frame = local dist / 5;
   end

   if self.haspartner == true then
   local raystartvector = self.Pos;
   local rayendvector = self.partner.Pos;
   local moid = SceneMan:CastMORay(raystartvector , rayendvector , 0 , 0 , true , 3);
   local mo = MovableMan:GetMOFromID(moid);
   end

   if mo ~= nil and mo.RootID == actor.ID and mo.ID ~= self.ID then
   self.destroyself = true;
   end

   if self.destroyself == true then
   self:GibThis();
   self.partner:GibThis();
   end
end

Author:  Geti [ Sun Sep 06, 2009 1:11 am ]
Post subject:  Re: Trip Mine script not working

oh my god you are using for movableman.particles in update you crazy person.
and shitty distance finding.
and check the console for errors

Author:  CaveCricket48 [ Sun Sep 06, 2009 1:28 am ]
Post subject:  Re: Trip Mine script not working

I don't see what's wrong with "for particle in MovableMan.Particles" Well, I fixed up the script a bit.

Code:
function Create(self)
   self.haspartner = false;
   self.destroyself = false;
   self.LifeTimer = Timer();
   self.lengtha = 0;
   self.lengthb = 0;
end

function Update(self)
   if self.LifeTimer:IsPastSimMS(199) and self.haspartner == false then
   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 dist < curdist and dist > 4 and particle.PresetName == "Particle C Trip Mine Layer Active" then
   self.partner = particle;
   self.haspartner = true;
   end
    end
end

   if self.LifeTimer:IsPastSimMS(200) then
   self.LifeTimer:Reset();
   end

   if self.haspartner == true then
   local partnerdir = math.atan2(-(self.partner.Pos.Y-self.Pos.Y),(self.partner.Pos.X-self.Pos.X));
   local triplaser = CreateMOSRotating("Particle C Trip Mine Layer Laser");
   triplaser.Pos = self.Pos;
   triplaser.RotAngle = partnerdir;
   MovableMan:AddParticle(triplaser);
   self.lengtha = (self.Pos.X - self.partner.Pos.X);
   self.lengthb = (self.Pos.Y - self.partner.Pos.Y);
   triplaser.Frame = (math.sqrt(self.lengtha ^ 2 + self.lengthb ^ 2)) /5;
   end

   if self.haspartner == true then
   local raystartvector = self.Pos;
   local rayendvector = self.partner.Pos;
   local moid = SceneMan:CastMORay(raystartvector, rayendvector, 0, 0, true , 3);
   local mo = MovableMan:GetMOFromID(moid);
   end

   if mo ~= nil and mo.RootID == actor.ID then
   self.destroyself = true;
   print("Got target");
   end

   if self.destroyself == true then
   self:GibThis();
   self.partner:GibThis();
   print("Self destructing");
   end
end


I don't have any errors now, but it still doesn't self-destruct.

Author:  Geti [ Sun Sep 06, 2009 2:14 am ]
Post subject:  Re: Trip Mine script not working

well, lets see, it loops whatever you've got in that code block for however many particles are on the screen, which is some cases is over 2000. if you have more than one of these, you can multiply that by however many of them there are. very soon youre going to get a lot of lag.
the way you've fixed it up makes it a lot nicer, but i still dont see why it cant be in create.
your problem is actor.ID. i think you mean mo:IsActor(), but i cant be sure. also, your endvector is flawed, because its the vector to trace along, not the vector to trace to.

Author:  CaveCricket48 [ Sun Sep 06, 2009 2:23 am ]
Post subject:  Re: Trip Mine script not working

How do you trace along a vector with Lua? Sorry if that sounds kinda dumb.

Author:  Geti [ Sun Sep 06, 2009 2:33 am ]
Post subject:  Re: Trip Mine script not working

it means you need to create a vector that describes the difference in position from one mine to the next. basically, the vector should be the difference of both vectors, or self.Pos - self.whatevertheotheroneiscalled.Pos.

Author:  CaveCricket48 [ Sun Sep 06, 2009 2:56 am ]
Post subject:  Re: Trip Mine script not working

Well, I have this:

Code:
   if self.haspartner == true then
   local raystartvector = self.Pos;
   local rayendvector = (self.Pos - self.partner.Pos)
   local moid = SceneMan:CastMORay(raystartvector, rayendvector, 0, 0, true , 3);
   local mo = MovableMan:GetMOFromID(moid);
   end


but I'm not sure this is working. (Another part of the script might be causing problems.)

Author:  Geti [ Sun Sep 06, 2009 4:51 am ]
Post subject:  Re: Trip Mine script not working

you're going to need to ignore self.ID

you need to do if GetMOFromID(mo.RootID):IsActor() or however the syntax should go rather than mo.RootID == actor.ID. the second one doesnt even make any sense.

Author:  hellboy999 [ Mon Dec 07, 2009 5:13 am ]
Post subject:  Re: Trip Mine script not working

try

if dist < "what you want" = explode
if else dist > "what you want" = deactivate

Author:  Foa [ Tue Dec 08, 2009 12:34 am ]
Post subject:  Re: Trip Mine script not working

I think he wants a directional trigger, not a radial trigger.

And hellboy, he already did that.

Author:  Grif [ Tue Dec 08, 2009 1:11 am ]
Post subject:  Re: Trip Mine script not working

hellboy999 wrote:
try

if dist < "what you want" = explode
if else dist > "what you want" = deactivate


oh god what

if else

FFFF

HEREBY MOTIONING THAT WE BAN HELLBOY FROM LUA SCRIPTING FORUM

also foa just on principle

Author:  CaveCricket48 [ Tue Dec 08, 2009 1:17 am ]
Post subject:  Re: Trip Mine script not working

Oh hey, this old topic... Yeah, with my current Lua knowledge, I can do this now with no problem. Thanks for the help, though, people.

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