View unanswered posts | View active topics It is currently Fri Dec 27, 2024 8:22 am



Reply to topic  [ 8 posts ] 
 Checking distance from an actor via Lua 
Author Message
User avatar

Joined: Sun Jul 04, 2010 8:09 pm
Posts: 12
Reply with quote
Post Checking distance from an actor via Lua
How can I check the distance from an enemy actor using lua?


Mon Jul 19, 2010 12:40 am
Profile
User avatar

Joined: Tue Nov 06, 2007 6:58 am
Posts: 2054
Reply with quote
Post 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.


Mon Jul 19, 2010 12:48 am
Profile
User avatar

Joined: Sun Jul 04, 2010 8:09 pm
Posts: 12
Reply with quote
Post Re: Checking distance from an actor via Lua
But how do I tell if it's an enemy actor?


Mon Jul 19, 2010 1:21 am
Profile
User avatar

Joined: Tue Nov 06, 2007 6:58 am
Posts: 2054
Reply with quote
Post 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.


Mon Jul 19, 2010 1:46 am
Profile
User avatar

Joined: Sun Jul 04, 2010 8:09 pm
Posts: 12
Reply with quote
Post 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!


Mon Jul 19, 2010 2:03 am
Profile
User avatar

Joined: Tue Nov 06, 2007 6:58 am
Posts: 2054
Reply with quote
Post 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.


Mon Jul 19, 2010 2:12 am
Profile
User avatar

Joined: Sun Jul 04, 2010 8:09 pm
Posts: 12
Reply with quote
Post 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!


Mon Jul 19, 2010 2:21 am
Profile
User avatar

Joined: Tue Nov 06, 2007 6:58 am
Posts: 2054
Reply with quote
Post 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.


Mon Jul 19, 2010 2:52 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 8 posts ] 

Who is online

Users browsing this forum: No registered users


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.042s | 13 Queries | GZIP : Off ]