Data Realms Fan Forums
http://45.55.195.193/

AAI help.....
http://45.55.195.193/viewtopic.php?f=73&t=16850
Page 1 of 1

Author:  NEW Molemian [ Sat Oct 17, 2009 1:29 am ]
Post subject:  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.

Author:  CrazyMLC [ Sat Oct 17, 2009 1:37 am ]
Post subject:  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.

Author:  NEW Molemian [ Sat Oct 17, 2009 1:44 am ]
Post subject:  Re: AAI help.....

So that one should work?

Author:  CrazyMLC [ Sat Oct 17, 2009 1:48 am ]
Post subject:  Re: AAI help.....

In theory, yes.

Author:  NEW Molemian [ Sat Oct 17, 2009 1:52 am ]
Post subject:  Re: AAI help.....

But it didnt..... Somehow nothing i work with end up the way it should be.....

Author:  TorrentHKU [ Sat Oct 17, 2009 2:01 am ]
Post subject:  Re: AAI help.....

Theory sucks, just like physics. WHY CAN'T I BE A FRICTIONLESS SURFACE.

Author:  CrazyMLC [ Sat Oct 17, 2009 2:12 am ]
Post subject:  Re: AAI help.....

press ~ ingame to open a window, it should have an error.
What does it say?

Author:  TheLastBanana [ Sat Oct 17, 2009 5:50 am ]
Post subject:  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.

Author:  Geti [ Sat Oct 17, 2009 7:47 am ]
Post subject:  Re: AAI help.....

cant you use Activity:OtherTeam()?

Author:  TheLastBanana [ Sat Oct 17, 2009 10:35 pm ]
Post subject:  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.

Author:  CrazyMLC [ Sun Oct 18, 2009 4:57 am ]
Post subject:  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.

Page 1 of 1 All times are UTC [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/