Data Realms Fan Forums http://45.55.195.193/ |
|
Checking distance from an actor via Lua http://45.55.195.193/viewtopic.php?f=73&t=19285 |
Page 1 of 1 |
Author: | carnaxcce [ Mon Jul 19, 2010 12:40 am ] |
Post subject: | Checking distance from an actor via Lua |
How can I check the distance from an enemy actor using lua? |
Author: | mail2345 [ Mon Jul 19, 2010 12:48 am ] |
Post subject: | Re: Checking distance from an actor via Lua |
SceneMan:shortestDistance(self.Pos,actor.Pos,true).Magnitude It will return the distance, assuming that actor is defined. |
Author: | carnaxcce [ Mon Jul 19, 2010 1:21 am ] |
Post subject: | Re: Checking distance from an actor via Lua |
But how do I tell if it's an enemy actor? |
Author: | mail2345 [ Mon Jul 19, 2010 1:46 am ] |
Post subject: | Re: Checking distance from an actor via Lua |
Code: if actor.Team ~= self.Team then <stuff> end Replace stuff with code, tabbing is optional but preferred. |
Author: | carnaxcce [ Mon Jul 19, 2010 2:03 am ] |
Post subject: | Re: Checking distance from an actor via Lua |
So, what I'm trying to do is crate a gun whose rounds explode after a certain time after they come within range of a target; the purpose being that the explode inside said target (they'll probably be dead already, but it could be used for busting bunkers). I also don't want it to explode on allies, so it only explodes on enemy actors. This is what I have: Quote: function Update(self) if SceneMan:shortestDistance(self.Pos,actor.Pos,true).Magnitude <= 30 and actor.Team ~= self.Team and dist.timer:IsPastSimMS(1000) == true then self.timer = Timer(); break end if self.timer:IsPastSimMS(1000) == true then self.GibThis() end It seems as if the round just explodes on impact. Help! |
Author: | mail2345 [ Mon Jul 19, 2010 2:12 am ] |
Post subject: | Re: Checking distance from an actor via Lua |
Actor is undefined, along with the timers. The timer check doesn't check if it's defined. Code: function Create(self) self.acttimer = Timer() self.timer = Timer() self.active = false end function Update(self) if self.acttimer:IsPastSimMS(1000) and not self.active then for actor in MovableMan.Actors do if SceneMan:shortestDistance(self.Pos,actor.Pos,true).Magnitude <= 30 and actor.Team ~= self.Team then self.active = true self.timer:reset() end end end if self.active and self.timer:IsPastSimMS(1000) == true then self.GibThis() end That should work. |
Author: | carnaxcce [ Mon Jul 19, 2010 2:21 am ] |
Post subject: | Re: Checking distance from an actor via Lua |
Just from looking at that, it seems like the second timer starts at the beginning. What I'm trying to do is have the timer start when it gets in range of an enemy. Everything else looks good though. Thanks! |
Author: | mail2345 [ Mon Jul 19, 2010 2:52 am ] |
Post subject: | Re: Checking distance from an actor via Lua |
The timer gets restarted when an enemy is found, and the timer is ignored untill an enemy is found. Captialize the R in reset though, I made a mistake. |
Page 1 of 1 | All times are UTC [ DST ] |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |