Data Realms Fan Forums http://45.55.195.193/ |
|
Land Mine script not working *Fixed http://45.55.195.193/viewtopic.php?f=73&t=16207 |
Page 1 of 1 |
Author: | CaveCricket48 [ Thu Aug 13, 2009 10:26 pm ] |
Post subject: | 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 |
Author: | Grif [ Fri Aug 14, 2009 12:23 am ] |
Post subject: | 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) |
Author: | CaveCricket48 [ Fri Aug 14, 2009 12:43 am ] |
Post subject: | 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? |
Author: | Grif [ Fri Aug 14, 2009 1:20 am ] |
Post subject: | 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. |
Author: | CaveCricket48 [ Fri Aug 14, 2009 2:52 am ] |
Post subject: | 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 |
Author: | Mind [ Fri Aug 14, 2009 2:54 am ] |
Post subject: | 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 |
Author: | CaveCricket48 [ Fri Aug 14, 2009 3:05 am ] |
Post subject: | Re: Land Mine script not working |
/facepalm Thanks Mind. |
Author: | Mind [ Fri Aug 14, 2009 3:07 am ] |
Post subject: | Re: Land Mine script not working |
lol np |
Author: | CaveCricket48 [ Fri Aug 14, 2009 3:39 pm ] |
Post subject: | 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 |
Author: | Grif [ Fri Aug 14, 2009 6:30 pm ] |
Post subject: | 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 |
Page 1 of 1 | All times are UTC [ DST ] |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |