Making AI automatically follow. [Solved]

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
User avatar
commanderawesome
Field Commander
Field Commander
Posts: 971
Joined: Tue Aug 13, 2013 11:58 pm
Projects :: Skin Changer - Warfront - Other stuff
Games I'm Playing :: SWBF SWTOR KotOR EaW
xbox live or psn: AaTc_CmdrAwesome
Location: The Universe

Making AI automatically follow. [Solved]

Post by commanderawesome »

You know the fake console command that makes the AI automatically follow you? What I wan't to know is, is this an ODF thing or an LUA thing? Because I wan't to make a class that will make people follow him on the start.
Last edited by commanderawesome on Fri Jul 25, 2014 7:31 pm, edited 1 time in total.
AQT
Gametoast Staff
Gametoast Staff
Posts: 4910
Joined: Sat Nov 03, 2007 4:55 pm
Location: SoCal, USA

Re: Making AI automatically follow.

Post by AQT »

User avatar
commanderawesome
Field Commander
Field Commander
Posts: 971
Joined: Tue Aug 13, 2013 11:58 pm
Projects :: Skin Changer - Warfront - Other stuff
Games I'm Playing :: SWBF SWTOR KotOR EaW
xbox live or psn: AaTc_CmdrAwesome
Location: The Universe

Re: Making AI automatically follow.

Post by commanderawesome »

Is there any way to make it universal across all scripts?
Noobasaurus
Droid Pilot Assassin
Droid Pilot Assassin
Posts: 2006
Joined: Tue Aug 17, 2010 5:56 pm

Re: Making AI automatically follow.

Post by Noobasaurus »

Just put it in all your scripts. It doesn't take that long.
User avatar
commanderawesome
Field Commander
Field Commander
Posts: 971
Joined: Tue Aug 13, 2013 11:58 pm
Projects :: Skin Changer - Warfront - Other stuff
Games I'm Playing :: SWBF SWTOR KotOR EaW
xbox live or psn: AaTc_CmdrAwesome
Location: The Universe

Re: Making AI automatically follow.

Post by commanderawesome »

The mod I'm making is quite big, it'll be three eras with multiple modes per map. I'd prefer another way around. Would it work if I added it to setup_teams.lua?
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: Making AI automatically follow.

Post by Marth8880 »

Create a new LUA file, insert the code in a new function in the new script, load the new script in mission.req, and call the function in the ScriptPostLoad() section of all of your maps' mission scripts. (Don't forget to call the LUA file in all of your maps' scripts using ScriptCB_DoFile().)
User avatar
[RDH]Zerted
Gametoast Staff
Gametoast Staff
Posts: 2982
Joined: Sun Feb 26, 2006 7:36 am
Projects :: Bos Wars AI - a RTS game
Games I'm Playing :: SWBF2 and Bos Wars
xbox live or psn: No gamertag set
Location: USA
Contact:

Re: Making AI automatically follow.

Post by [RDH]Zerted »

commanderawesome wrote:Would it work if I added it to setup_teams.lua?
It should since setup_teams.lua is normally part of each map's mission.lvl. You'll have to put it in the right place.

AddAIGoal(team, "follow", 100, GetCharacterUnit(character))

The 100 doesn't mean 100% of the AI bots on team team. It means whatever percent 100 is out of the total AI goals values. If you have three AddAIGoals all with 100, then each would assign a third of the bots. If you have three AddAIGoals all with 5, then they still each assign a third of the bots.

Read the AI Goals documentation if you want to learn more about them. You'll probably have to read it a few times before you understand it.

You can't make the AI follow a specific class, but you can make them follow any unit that spawns as the class. Just be sure to remove the corresponding goal when the unit dies. SWBF2 has a max AIGoal limit (see the limits topic)
User avatar
commanderawesome
Field Commander
Field Commander
Posts: 971
Joined: Tue Aug 13, 2013 11:58 pm
Projects :: Skin Changer - Warfront - Other stuff
Games I'm Playing :: SWBF SWTOR KotOR EaW
xbox live or psn: AaTc_CmdrAwesome
Location: The Universe

Re: Making AI automatically follow.

Post by commanderawesome »

[RDH]Zerted wrote:
commanderawesome wrote:Would it work if I added it to setup_teams.lua?
It should since setup_teams.lua is normally part of each map's mission.lvl. You'll have to put it in the right place.
What part would that be?
[RDH]Zerted wrote:Just be sure to remove the corresponding goal when the unit dies. SWBF2 has a max AIGoal limit (see the limits topic)
Ok, then, is it possible to add death as a variable in the if-then-else logic?
User avatar
[RDH]Zerted
Gametoast Staff
Gametoast Staff
Posts: 2982
Joined: Sun Feb 26, 2006 7:36 am
Projects :: Bos Wars AI - a RTS game
Games I'm Playing :: SWBF2 and Bos Wars
xbox live or psn: No gamertag set
Location: USA
Contact:

Re: Making AI automatically follow.

Post by [RDH]Zerted »

I can't tell you where in setup_teams.lua, because I no longer have the mod tools installed. It needs to be somewhere that's called from when your map is starting up. You can't simple place it at the top of the file because then it'll run as soon as the DoFile() function is called for setup_teams. You could put the code in a function and put that function at the top of the file. Then call that function from ScriptPostLoad. That should work. Try it and find out. Instead of using AddAIGoal use a print statement and see if it outputs in the debug log. If it does, then you know it's being loaded probably and you can fill it in with the correct code.

(The 'proper' way would be to follow Marth8880's advice.)

I'm not sue what you mean by add death as a variable. You'll need an OnCharacterDeath(). When a character dies that has an AI goal associated with it, remove the goal. Example pseudo (fake) code:

Code: Select all

myAIGoals = {}

OnCharacterSpawn(function(character)
    charClassIndex = character's class
    if (charClassIndex == the index of the class to attack) and (table.getn(myAIGoals) < MaxAmountOfAIGoals including the game mode's AI goals) then
        myAIGoals[character] = AddAIGoal( ... )
end))

OnCharacterDeath(function(character)
    if myAIGoals[character] ~= nil then
        ReleaseAIGoal(myAIGoals[character])
        myAIGoals[character] = nil
    end
end))
The above code stores things in a table using the character's id as the 'name' to access what was stored. It's normally easier to use tables and loops than huge if else statements or having lots of personA, personB, personC, etc... variables. Many people here on GT should use tables more often... The whole FakeConsole list was built with tables. Instead of having to think up and remember names for every function behind each command, they're all stored as unnamed functions directly in the table displaying all of the commands.

At least one of the OnCharacter, OnObjectCreate, or something else has a class filter, so it'll only get triggered on the specific class. You should use that OnXXXXX trigger.
User avatar
commanderawesome
Field Commander
Field Commander
Posts: 971
Joined: Tue Aug 13, 2013 11:58 pm
Projects :: Skin Changer - Warfront - Other stuff
Games I'm Playing :: SWBF SWTOR KotOR EaW
xbox live or psn: AaTc_CmdrAwesome
Location: The Universe

Re: Making AI automatically follow.

Post by commanderawesome »

That's exactly what i'm looking for. Thanks!
Post Reply