Page 1 of 1
Making AI automatically follow. [Solved]
Posted: Tue Jul 22, 2014 6:25 pm
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.
Re: Making AI automatically follow.
Posted: Tue Jul 22, 2014 6:45 pm
by AQT
Re: Making AI automatically follow.
Posted: Tue Jul 22, 2014 9:57 pm
by commanderawesome
Is there any way to make it universal across all scripts?
Re: Making AI automatically follow.
Posted: Tue Jul 22, 2014 10:02 pm
by Noobasaurus
Just put it in all your scripts. It doesn't take that long.
Re: Making AI automatically follow.
Posted: Wed Jul 23, 2014 2:18 pm
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?
Re: Making AI automatically follow.
Posted: Wed Jul 23, 2014 3:04 pm
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().)
Re: Making AI automatically follow.
Posted: Thu Jul 24, 2014 8:58 pm
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)
Re: Making AI automatically follow.
Posted: Thu Jul 24, 2014 9:22 pm
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?
Re: Making AI automatically follow.
Posted: Fri Jul 25, 2014 7:25 pm
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.
Re: Making AI automatically follow.
Posted: Fri Jul 25, 2014 7:31 pm
by commanderawesome
That's exactly what i'm looking for. Thanks!