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



Reply to topic  [ 11 posts ] 
 AAI help..... 
Author Message

Joined: Wed May 27, 2009 1:19 pm
Posts: 15
Reply with quote
Post AAI help.....
Hello, I am currently working on trying to make an Lua-file to work the way it is supposed to but have struck a hard end as the script doesnt work..... Now i am turning here to ask for help to make it work.....


AAI, Advanced Artificial Intelligence, was supposed to make units search for the closest enemy unit and then give a GO-TO command to it.....
Code:
function Create(self)
   self.Target = nil;
   self.Target1 = nil;
   AIMode = 3;
   Dist = 100;

   if self.Team == 0 then
      self.EnemyTeam = 1;
   else
      self.EnemyTeam = 0;
   end
end

function Update(self)
   self.Target = MovableMan:GetClosestActor(self.EnemyTeam, self.Pos, 500, Dist, self);
   if MovableMan:IsActor(self.Target) and MovableMan:IsActor(self.Target1) then
      if self.Target.ID ~= self.Target1.ID then
         self.Target1 = self.Target;
         self:ClearAIWaypoints();
         self:AddAIMOWaypoint(self.Target1);
      end
   end
end


So please, if anybody could help me i would be really grateful.


Sat Oct 17, 2009 1:29 am
Profile
User avatar

Joined: Fri Dec 22, 2006 4:20 am
Posts: 4772
Location: Good news everyone!
Reply with quote
Post Re: AAI help.....
NEW Molemian wrote:
Code:
function Create(self)
   self.Target = nil;
   self.Target1 = nil;
   AIMode = 3;
   Dist = 100;

   -- Heh, I used this a while ago, It only works with team 1 and team 2.
   -- The better way to do it...
--   if self.Team == 0 then
--      self.EnemyTeam = 1;
--   else
--      self.EnemyTeam = 0;
--   end
   for actor in MoveableMan.Actors do
      if self.Team ~= actor.Team then
         EnemyTeam = actor.Team;
      end
   end
end

function Update(self)
   self.Target = MovableMan:GetClosestActor(self.EnemyTeam, self.Pos, 500, Dist, self);
   if MovableMan:IsActor(self.Target) and MovableMan:IsActor(self.Target1) then
      if self.Target.ID ~= self.Target1.ID then
         self.Target1 = self.Target;
         self:ClearAIWaypoints();
         self:AddAIMOWaypoint(self.Target1);
      end
   end
end

The rest looks like perfectly good code to me.


Sat Oct 17, 2009 1:37 am
Profile WWW

Joined: Wed May 27, 2009 1:19 pm
Posts: 15
Reply with quote
Post Re: AAI help.....
So that one should work?


Sat Oct 17, 2009 1:44 am
Profile
User avatar

Joined: Fri Dec 22, 2006 4:20 am
Posts: 4772
Location: Good news everyone!
Reply with quote
Post Re: AAI help.....
In theory, yes.


Sat Oct 17, 2009 1:48 am
Profile WWW

Joined: Wed May 27, 2009 1:19 pm
Posts: 15
Reply with quote
Post Re: AAI help.....
But it didnt..... Somehow nothing i work with end up the way it should be.....


Sat Oct 17, 2009 1:52 am
Profile
Loose Canon
User avatar

Joined: Sun Mar 29, 2009 11:07 pm
Posts: 2992
Location: --------------->
Reply with quote
Post Re: AAI help.....
Theory sucks, just like physics. WHY CAN'T I BE A FRICTIONLESS SURFACE.


Sat Oct 17, 2009 2:01 am
Profile WWW
User avatar

Joined: Fri Dec 22, 2006 4:20 am
Posts: 4772
Location: Good news everyone!
Reply with quote
Post Re: AAI help.....
press ~ ingame to open a window, it should have an error.
What does it say?


Sat Oct 17, 2009 2:12 am
Profile WWW
DRL Developer
DRL Developer
User avatar

Joined: Wed Dec 13, 2006 5:27 am
Posts: 3138
Location: A little south and a lot west of Moscow
Reply with quote
Post Re: AAI help.....
Actually, his original way of determining enemy team was far better. It's more efficient. There's no reason to run through every actor in the game just to determine the team. What if there are no other actors? Then the method won't work. Your method isn't going to allow it to work on team -1, either. Remember, this is being run in the Create function, so it only happens once. It's only going to return one number.
However, this would be a better way of working the code:
Code:
function Create(self)
   self.Target = nil;
   self.Target1 = nil;
   AIMode = Actor.AIMODE_GOTO;
   Dist = 100;

   if self.Team == Activity.TEAM_1 then
      self.EnemyTeam = Activity.TEAM_2;
   else
      self.EnemyTeam = Activity.TEAM_1;
   end
   for actor in MoveableMan.Actors do
      if self.Team ~= actor.Team then
         EnemyTeam = actor.Team;
      end
   end
end

function Update(self)
   self.Target = MovableMan:GetClosestActor(self.EnemyTeam, self.Pos, 500, Dist, self);
   if MovableMan:IsActor(self.Target) and MovableMan:IsActor(self.Target1) then
      if self.Target.ID ~= self.Target1.ID then
         self.Target1 = self.Target;
         self:ClearAIWaypoints();
         self:AddAIMOWaypoint(self.Target1);
      end
   end
end

It's always best to use constants instead of "magic numbers".
Now, as for the problem... I did some testing with MovableMan:GetClosestActor and I can't for the life of me get ClosestActor working. Try ClosestTeamActor again, but I'm pretty sure this is another case of function implementation that is incompatible with Lua (it's looking for pointers, but Lua doesn't have explicit pointers). I think your best bet would be to use the code from the homing missile to find the nearest actor. It's not as efficient as using a built-in function, but I don't think this function is even working.


Sat Oct 17, 2009 5:50 am
Profile WWW
User avatar

Joined: Sun Jul 13, 2008 9:57 am
Posts: 4886
Location: some compy
Reply with quote
Post Re: AAI help.....
cant you use Activity:OtherTeam()?


Sat Oct 17, 2009 7:47 am
Profile WWW
DRL Developer
DRL Developer
User avatar

Joined: Wed Dec 13, 2006 5:27 am
Posts: 3138
Location: A little south and a lot west of Moscow
Reply with quote
Post Re: AAI help.....
Actually, as far as I can tell, that function doesn't exist as of B23. Correct me if I'm wrong, but I'm unable to call it up.


Sat Oct 17, 2009 10:35 pm
Profile WWW
User avatar

Joined: Fri Dec 22, 2006 4:20 am
Posts: 4772
Location: Good news everyone!
Reply with quote
Post Re: AAI help.....
I never knew function Create only ran once, good to know, good to know.
I meant to put it in Update...
But I guess that would be a little slower than doing what he did before, seemed to work fine in my code though.


Sun Oct 18, 2009 4:57 am
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 11 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.127s | 13 Queries | GZIP : Off ]