Author |
Message |
CaveCricket48
Joined: Tue Jun 12, 2007 11:52 pm Posts: 13144 Location: Here
|
Land Mine script not working *Fixed
Edit: New Land mine script, not working. Help please. Code: function Create(self) end local curdist = 40; 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 < curdist then self:GibThis(); end end
Last edited by CaveCricket48 on Fri Aug 14, 2009 3:50 pm, edited 1 time in total.
|
Thu Aug 13, 2009 10:26 pm |
|
|
Grif
REAL AMERICAN HERO
Joined: Sat Jan 27, 2007 10:25 pm Posts: 5655
|
Re: Land Mine script not working
Anything in the create function will only be executed the same update as the object is created.
Put the distance check inside function Update(self)
|
Fri Aug 14, 2009 12:23 am |
|
|
CaveCricket48
Joined: Tue Jun 12, 2007 11:52 pm Posts: 13144 Location: Here
|
Re: Land Mine script not working
So it will look like: Code: function Update(self) end local curdist = 40; 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 < curdist then self:GibThis(); end end Right?
|
Fri Aug 14, 2009 12:43 am |
|
|
Grif
REAL AMERICAN HERO
Joined: Sat Jan 27, 2007 10:25 pm Posts: 5655
|
Re: Land Mine script not working
No. Because that code would immediately end the function loop. function create self, then for, if, then three ends at the end of the script.
|
Fri Aug 14, 2009 1:20 am |
|
|
CaveCricket48
Joined: Tue Jun 12, 2007 11:52 pm Posts: 13144 Location: Here
|
Re: Land Mine script not working
I'm not getting any errors, but this isn't working either. Code: function Create(self) local curdist = 50; 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 < curdist then self:GibThis(); end end end
|
Fri Aug 14, 2009 2:52 am |
|
|
Mind
Joined: Thu Mar 06, 2008 10:54 pm Posts: 1360 Location: USA
|
Re: Land Mine script not working
Code: function Update(self) local curdist = 50; 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 < curdist then self:GibThis(); end end end
|
Fri Aug 14, 2009 2:54 am |
|
|
CaveCricket48
Joined: Tue Jun 12, 2007 11:52 pm Posts: 13144 Location: Here
|
Re: Land Mine script not working
/facepalm
Thanks Mind.
|
Fri Aug 14, 2009 3:05 am |
|
|
Mind
Joined: Thu Mar 06, 2008 10:54 pm Posts: 1360 Location: USA
|
Re: Land Mine script not working
lol np
|
Fri Aug 14, 2009 3:07 am |
|
|
CaveCricket48
Joined: Tue Jun 12, 2007 11:52 pm Posts: 13144 Location: Here
|
Re: Land Mine script not working
Another script not working. I think I need a "for" statement, but I'm not sure how I'm suppose to put it in. Edit: got the "for" statement, but getting errors abou a nil box value. Edit2: Found an easier way to do box and it works. Problem solved. Small, easy box script: Code: function Update(self)
--Using Lua to do box detection
for actor in MovableMan.Actors do --If an actor gets within the defined area if (actor.Pos.X >= self.Pos.X - 20) and (actor.Pos.X <= self.Pos.X + 20) and (actor.Pos.Y >= self.Pos.Y - 20) and (actor.Pos.Y <= self.Pos.Y + 20) then self:GibThis(); --Gib the Mine end end end
|
Fri Aug 14, 2009 3:39 pm |
|
|
Grif
REAL AMERICAN HERO
Joined: Sat Jan 27, 2007 10:25 pm Posts: 5655
|
Re: Land Mine script not working *Fixed
Longform box detection is marginally slower than engine boxes. This script will check every half-second for an actor (rather than every sim update) and uses engine functions for that tiny bit of not-lagginess.
function Create(self) self.checktimer = Timer(); self.checkbox = Box(Vector(self.Pos.X - 20,self.Pos.Y - 20),Vector(self.Pos.X + 20,self.Pos.Y + 20)); end
function Update(self) if self.checktimer:IsPastSimMS(500) == true then self.checktimer:Reset(); for actor in MovableMan.Actors do if self.checkbox:WithinBox(actor.Pos) == true then self:GibThis(); end end end end
|
Fri Aug 14, 2009 6:30 pm |
|
|
|