Author |
Message |
CaveCricket48
Joined: Tue Jun 12, 2007 11:52 pm Posts: 13144 Location: Here
|
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
|
Sat Sep 05, 2009 8:16 pm |
|
|
Geti
Joined: Sun Jul 13, 2008 9:57 am Posts: 4886 Location: some compy
|
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
|
Sun Sep 06, 2009 1:11 am |
|
|
CaveCricket48
Joined: Tue Jun 12, 2007 11:52 pm Posts: 13144 Location: Here
|
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.
|
Sun Sep 06, 2009 1:28 am |
|
|
Geti
Joined: Sun Jul 13, 2008 9:57 am Posts: 4886 Location: some compy
|
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.
|
Sun Sep 06, 2009 2:14 am |
|
|
CaveCricket48
Joined: Tue Jun 12, 2007 11:52 pm Posts: 13144 Location: Here
|
Re: Trip Mine script not working
How do you trace along a vector with Lua? Sorry if that sounds kinda dumb.
|
Sun Sep 06, 2009 2:23 am |
|
|
Geti
Joined: Sun Jul 13, 2008 9:57 am Posts: 4886 Location: some compy
|
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.
|
Sun Sep 06, 2009 2:33 am |
|
|
CaveCricket48
Joined: Tue Jun 12, 2007 11:52 pm Posts: 13144 Location: Here
|
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.)
|
Sun Sep 06, 2009 2:56 am |
|
|
Geti
Joined: Sun Jul 13, 2008 9:57 am Posts: 4886 Location: some compy
|
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.
|
Sun Sep 06, 2009 4:51 am |
|
|
hellboy999
Joined: Mon Dec 07, 2009 4:59 am Posts: 1
|
Re: Trip Mine script not working
try
if dist < "what you want" = explode if else dist > "what you want" = deactivate
|
Mon Dec 07, 2009 5:13 am |
|
|
Foa
Data Realms Elite
Joined: Wed Sep 05, 2007 4:14 am Posts: 3966 Location: Canadida
|
Re: Trip Mine script not working
I think he wants a directional trigger, not a radial trigger.
And hellboy, he already did that.
|
Tue Dec 08, 2009 12:34 am |
|
|
Grif
REAL AMERICAN HERO
Joined: Sat Jan 27, 2007 10:25 pm Posts: 5655
|
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
|
Tue Dec 08, 2009 1:11 am |
|
|
CaveCricket48
Joined: Tue Jun 12, 2007 11:52 pm Posts: 13144 Location: Here
|
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.
|
Tue Dec 08, 2009 1:17 am |
|
|
|