|
Page 1 of 1
|
[ 11 posts ] |
|
Author |
Message |
NEW Molemian
Joined: Wed May 27, 2009 1:19 pm Posts: 15
|
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 |
|
|
CrazyMLC
Joined: Fri Dec 22, 2006 4:20 am Posts: 4772 Location: Good news everyone!
|
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 |
|
|
NEW Molemian
Joined: Wed May 27, 2009 1:19 pm Posts: 15
|
Re: AAI help.....
So that one should work?
|
Sat Oct 17, 2009 1:44 am |
|
|
CrazyMLC
Joined: Fri Dec 22, 2006 4:20 am Posts: 4772 Location: Good news everyone!
|
Re: AAI help.....
In theory, yes.
|
Sat Oct 17, 2009 1:48 am |
|
|
NEW Molemian
Joined: Wed May 27, 2009 1:19 pm Posts: 15
|
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 |
|
|
TorrentHKU
Loose Canon
Joined: Sun Mar 29, 2009 11:07 pm Posts: 2992 Location: --------------->
|
Re: AAI help.....
Theory sucks, just like physics. WHY CAN'T I BE A FRICTIONLESS SURFACE.
|
Sat Oct 17, 2009 2:01 am |
|
|
CrazyMLC
Joined: Fri Dec 22, 2006 4:20 am Posts: 4772 Location: Good news everyone!
|
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 |
|
|
TheLastBanana
DRL Developer
Joined: Wed Dec 13, 2006 5:27 am Posts: 3138 Location: A little south and a lot west of Moscow
|
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 |
|
|
Geti
Joined: Sun Jul 13, 2008 9:57 am Posts: 4886 Location: some compy
|
Re: AAI help.....
cant you use Activity:OtherTeam()?
|
Sat Oct 17, 2009 7:47 am |
|
|
TheLastBanana
DRL Developer
Joined: Wed Dec 13, 2006 5:27 am Posts: 3138 Location: A little south and a lot west of Moscow
|
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 |
|
|
CrazyMLC
Joined: Fri Dec 22, 2006 4:20 am Posts: 4772 Location: Good news everyone!
|
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 |
|
|
|
|
Page 1 of 1
|
[ 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
|
|