Formations?

In this forum you will find and post information regarding the modding of Star Wars Battlefront 2. DO NOT POST MOD IDEAS/REQUESTS.

Moderator: Moderators

Post Reply
MileHighGuy
Jedi
Jedi
Posts: 1194
Joined: Fri Dec 19, 2008 7:58 pm

Formations?

Post by MileHighGuy »

Is it possible to make the ai go into formations via lua? Or at least travel in groups? For example, can I have clones follow the first clone commander they see? How complex can we go with this?
Marth8880
Resistance Leader
Posts: 5042
Joined: Tue Feb 09, 2010 8:43 pm
Projects :: DI2 + Psychosis
Games I'm Playing :: Silent Hill 2
xbox live or psn: Marth8880
Location: Edinburgh, UK
Contact:

Re: Formations?

Post by Marth8880 »

You could possibly create a table with a for...while loop that compiles all of the currently-spawned Commander units and then create an AI goal that's set to defend or follow (defend is a loose follow, follow is a tight follow) the entity ptrs stored in that table. Or something like that. I'm not very familiar with tables, so I can't help you very much with it. However, I think the AI goal bit would probably be something along the lines of this:

Code: Select all

AddAIGoal(REP, "Defend", 80, [commandertable])
MileHighGuy
Jedi
Jedi
Posts: 1194
Joined: Fri Dec 19, 2008 7:58 pm

Re: Formations?

Post by MileHighGuy »

Are there any examples of this being used in the stock files? I will have to look up how to use tables in lua.
razac920
2nd Lieutenant
2nd Lieutenant
Posts: 365
Joined: Sun Jan 16, 2011 12:42 am

Re: Formations?

Post by razac920 »

AIGoals seems like a good idea. I don't know of any examples like this in the stock files, but here's how I would do it:
Hidden/Spoiler:
[code]
players = {}
goals = {}
count = 0
addgoal = OnCharacterSpawn(function(player)
if GetCharacterClass(player) == 4 and GetCharacterTeam(player) == REP then // replace 4 with the index of your commander, starting with 0
local seen = false
for i = 1,count do
if players == player then
seen = true
goals = AddAIGoal(REP,"Defend",80,GetCharacterUnit(player)) // or "Follow" if you want them to follow very closely, and change the weight too
end
end
if not seen then
count = count + 1
players[count] = player
goals[count] = AddAIGoal(REP,"Defend",80,GetCharacterUnit(player)) // or "Follow" if you want them to follow very closely, and change the weight
end
end
end)

removegoal = OnCharacterDeath(function(player,killer)
for j = 1,count do
if players == player and not goals == nil then
DeleteAIGoal(goals)
goals = nil
end
end
end)
[/code]


Since there is a maximum of 20 AI Goals, make sure you don't have too many commanders on the map at the same time.
Last edited by razac920 on Sat May 31, 2014 9:52 am, edited 1 time in total.
Marth8880
Resistance Leader
Posts: 5042
Joined: Tue Feb 09, 2010 8:43 pm
Projects :: DI2 + Psychosis
Games I'm Playing :: Silent Hill 2
xbox live or psn: Marth8880
Location: Edinburgh, UK
Contact:

Re: Formations?

Post by Marth8880 »

Looks great! The syntax for the defend/follow goal is AddAIGoal( team, "Defend", weight, gameObjectPtr ), though. ;)
razac920
2nd Lieutenant
2nd Lieutenant
Posts: 365
Joined: Sun Jan 16, 2011 12:42 am

Re: Formations?

Post by razac920 »

Fixed, good catch!
Post Reply