Page 1 of 1

Dynamic AI Planning

Posted: Fri May 29, 2009 5:06 pm
by KnightsFan
My problem is that I want my AI to go after different objectives at different times during my campaign map. Somehow, they always manage to go the opposite direction leaving me facing hordes of blood-thirsty droids. Is there a way to either 1. Activate/deactivate barriers, 2. Do the same for planning hubs or connection or 3. Inexorably force the AI to attack a certain region?

Thanks.

Re: Dynamic AI Planning

Posted: Fri May 29, 2009 5:09 pm
by Xavious
Try these:

Code: Select all

BlockPlanningGraphArcs("ConnectionName");
DisableBarriers("BarrierName");
UnblockPlanningGraphArcs("ConnectionName");
EnableBarriers("BarrierName");
They're in the shipped Mustafar map; it's how they make sure the AI don't try to run across the bridge when it's out.

Re: Dynamic AI Planning

Posted: Fri May 29, 2009 5:15 pm
by KnightsFan
Yay! Thanks! But why do you have ";" at the end of each one? Does that actually do anything in LUA?
Edit: The AI are walking straight through the barrier now... and I didn't disable it yet :faint:

Re: Dynamic AI Planning

Posted: Fri May 29, 2009 6:53 pm
by RepSharpshooter
Are they following a path through the barrier? if so, disable that connection with lua as well.

Re: Dynamic AI Planning

Posted: Fri May 29, 2009 8:21 pm
by FragMe!
Here is something from PsychoFred's site (which is a good source of information the link can be found in the FAQ)
Hidden/Spoiler:
gtw 6-17-05

Lua functions for scripting the AI in the mission scripts:

*******************************************************************************
- ClearAIGoals( team )

Removes all previous AI goals for this team. You should call
this before you set the first goals for a team, since teams 1, 2, and 3
start out with a default Conquest goal.

for example:
ClearAIGoals( 1 )


*******************************************************************************
- DeleteAIGoal( goalHandle )

Remove the specified goal. goalHandle is the handle returned by AddAIGoal.

for example:
DeleteAIGoal( handle )


*******************************************************************************
int AddAIGoal( team, goaltype, weight )
int AddAIGoal( team, goaltype, weight, target1 )
int AddAIGoal( team, goaltype, weight, target1, target2 )

Add an AI goal for this team. Returns a handle to the new goal.


goaltype can be one of these:

"Conquest" - plays like BF1 on the command posts
AddAIGoal( team, "Conquest", weight );

"Deathmatch" - just kill everyone
AddAIGoal( team, "Deathmatch", weight );

"Destroy" - destroy the target (a gameobject pointer, or a character index)
AddAIGoal( team, "Destroy", weight, gameObjectPtr );
AddAIGoal( team, "Destroy", weight, integerChrIdx );

"Defend" - defend the target (a gameobject pointer, or a character index)
AddAIGoal( team, "Defend", weight, gameObjectPtr );
AddAIGoal( team, "Defend", weight, integerChrIdx );

"CTFOffense" - try to get the specified flag and bring it back to the specified region
AddAIGoal( team, "CTFOffense", weight, regionName );
AddAIGoal( team, "CTFOffense", weight, regionName, flagPtr );

"CTFDefense" - protect the specified flag, and hunt down and return it when its stolen
AddAIGoal( team, "CTFDefense", weight );
AddAIGoal( team, "CTFDefense", weight, flagPtr );

"Follow" - follow around the target (like defend, but uses a tight follow)
AddAIGoal( team, "Follow", weight, gameObjectPtr);


Weight is a relative weight for this goal. Since you can specify more than one goal
for a team at a time, this specifies how the guys are divided. A goal with weight 2
will get twice as many guys as the goal with weight 1. The size of the numbers doesn't
matter and they don't have to add up to 100 or anything.

The goals for Conquest and Deathmatch don't require a target, since
they figure that out automatically. When you give a Defend, Destroy,
or CTF goal, it has to know what object you want to atttack or protect.

for example:

ClearAIGoals( 1 )
AddAIGoal( 1, "CTFOffense", 50, GetRegionName(team1captureregion) )
AddAIGoal( 1, "CTFDefense", 50 )
ClearAIGoals( 2 )
AddAIGoal( 2, "CTFOffense", 25, GetRegionName(team2captureregion) )
AddAIGoal( 2, "CTFDefense", 50 )
AddAIGoal( 2, "Destroy", 25, sheldBunkerObjPtr )

This will set up a CTF game with half of team 1's guys on offense and half on
defense. Team 2 will have half their guys on defense, a quarter on offense, and
a quarter trying to destroy the shield bunker (a GameObject). Once they kill that it will
automatically rebalance the remaining goals so that 1/3 of the guys are on ctf offense
and 2/3 are on ctf defense.


Or you can specify flags:

ClearAIGoals( 1 )
AddAIGoal( 1, "CTFOffense", 30, GetRegionName(team1captureregion), team2FlagAPtr )
AddAIGoal( 1, "CTFOffense", 30, GetRegionName(team1captureregion), team2FlagBPtr )
AddAIGoal( 1, "CTFDefense", 40, team1FlagCPtr )

This will send some guys to get 'FlagA' and return it to 'team1captureregion', some
other guys to get 'FlagB' and return it there, and the other 40% will defend their
own flagC.


Destroy and Defend can specify GameObjects or Character indices:

ClearAIGoals( 1 )
AddAIGoal( 1, "Defend", 100, 0 )
ClearAIGoals( 2 )
AddAIGoal( 2, "Destroy", 50, 0 )
AddAIGoal( 2, "Destroy", 50, atatPtr )

This sets up all of team 1 to defend Character(0), which is the player. Here you could also
put the index of a special character (ie Leia or anyone) you spawn in somewhere. Team 2 is
set to kill Character(0) (the player again) and also destroy the ATAT specified by atatPtr.

Re: Dynamic AI Planning

Posted: Sat May 30, 2009 6:44 pm
by KnightsFan
I already knew about most of those, FragMe. They don't seem to work very well.

Code: Select all

AddAIGoal(ATT, "Conquest", 100, "cp4")
...And about 4/80 AI head the opposite direction of CP4.

Code: Select all

AddAIGoal(DEF, "Defend", 100, "cp4")
AddAIGoal(ATT, "Conquest", 50, "cp4")
...And I find myself fighting fighting the entire CIS force (ATT) yet my buddies (DEF) only occasionally try to support me.

Re: Dynamic AI Planning

Posted: Sat May 30, 2009 7:16 pm
by Frisbeetarian
Keep in mind that the number you use doesn't matter, as long as the AI only have one objective per team.

Re: Dynamic AI Planning

Posted: Sun Jun 07, 2009 2:14 am
by [RDH]Zerted
KnightsFan wrote:...why do you have ";" at the end of each one? Does that actually do anything in LUA?...
; are optional in Lua. I believe you can use them to put more than one command on the a single line (but I didn't look that up to be sure). Example:

Code: Select all

x=5; why=7; y="no reason"