View unanswered posts | View active topics It is currently Thu Dec 26, 2024 6:14 pm



Reply to topic  [ 7 posts ] 
 Problem with Proximity mine 
Author Message

Joined: Mon Apr 05, 2010 2:29 am
Posts: 4
Reply with quote
Post Problem with Proximity mine
Hi guys.

Im trying to create a script to make a proximity bomb, able to explode when an enemy aproaches.

The script seems to load fine, but it doesn´t work like i want, because the mine explodes right after i throw it away.

Here is the script.

Code:
function Update(self)
   for actor in MovableMan.Actors do
      if actor.Team ~= self.Team then
      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 < 100 then
            self:GibThis();
         end
      end
   end
end


Wed Sep 29, 2010 1:27 am
Profile
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 13144
Location: Here
Reply with quote
Post Re: Problem with Proximity mine
That's because it's detecting the thrower. It's working perfectly.

You should create a timer in the Create() function, and check if it's after a certain time before doing your proximity check.


Wed Sep 29, 2010 1:44 am
Profile

Joined: Mon Apr 05, 2010 2:29 am
Posts: 4
Reply with quote
Post Re: Problem with Proximity mine
Ok i made a timer but im getting an error in the console:

http://img529.imageshack.us/img529/7055/screendump000.jpg

Here is the new script:

Code:
function Create(self)
    self.LTimer = Timer();
end

function Update(self)
   if Timer:IsPastSimMS(3000) == true then
   for actor in MovableMan.Actors do
      if actor.Team ~= self.Team then
      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 < 100 then
         self:GibThis();
      end
      end
   end
end


Thanks for your help.


Wed Sep 29, 2010 3:05 am
Profile
User avatar

Joined: Sat Oct 17, 2009 2:07 pm
Posts: 127
Reply with quote
Post Re: Problem with Proximity mine
Add one more "end".
And it must be
Code:
   if self.LTimer:IsPastSimMS(3000) == true then

instead of
Code:
   if Timer:IsPastSimMS(3000) == true then


Wed Sep 29, 2010 1:50 pm
Profile ICQ

Joined: Mon Apr 05, 2010 2:29 am
Posts: 4
Reply with quote
Post Re: Problem with Proximity mine
It works!

Thanks Alex!

Here is the code with somebody wants it:

Code:
function Create(self)
    self.LTimer = Timer();
end

function Update(self)
   if self.LTimer:IsPastSimMS(3000) == true then
   for actor in MovableMan.Actors do
      if actor.Team ~= self.Team then
      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 < 50 then
         self:GibThis();
      end
      end
   end
end
end


Wed Sep 29, 2010 6:33 pm
Profile
User avatar

Joined: Sun May 31, 2009 1:04 am
Posts: 308
Reply with quote
Post Re: Problem with Proximity mine
Code:
if actor.Team ~= self.Team then

You can take this if statement out. If I remember correctly from the old IRC MOTD, thrown items such as grenades and stuff don't have a defined team.

If you want to use this line of code, you'll have to define the team yourself by adding some code to the Create function that searches for the nearest actor, since the nearest one is most likely the one who initially threw the bomb. Define that actor as the owner, and then use his team number for comparison instead of the bomb's.

Hope this helps your optimize the code a little.


Fri Oct 01, 2010 12:02 am
Profile

Joined: Mon Apr 05, 2010 2:29 am
Posts: 4
Reply with quote
Post Re: Problem with Proximity mine
Thanks for the idea.

I just started with lua, it seems a little complicated, but i will try.


Fri Oct 01, 2010 1:12 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 7 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:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.197s | 13 Queries | GZIP : Off ]