Difference between revisions of "AI Modding"

From FA Forever Wiki
Jump to navigation Jump to search
m (Reverted edits by Softles (talk) to last revision by JJs AI)
Line 70: Line 70:
== Super Up-To-Date ==
This page is legit really up to date.
Like, for real.

Revision as of 08:03, 25 May 2016

Before you start

It is always good to have some knowledge of how you want your AI to play out. So before you create an AI, it is recommended that you have a good idea of how the features of Forged Alliance works, e.g. The Economy.

You will need a text editor of some kind:

- Sublime Text or Notepad ++ will do.

Setup info

To add an AI to the game we need to load our code in the FA init file, it can't be done through the usual modding means.

Some root folders we'll use when modding:

1) lua/ - this houses the main body of the lua code. Files and functions here overwrite previous code, but we can still call functions from the original versions of the file.

2) schook/ - this houses code that gets appended to the rest of the moddable files on startup, so schook/lua/ will get added to the end of stuff in lua/

Adding an AI to the lobby

To do that we need to get a little info about our AI into the aitypes table in lua/ui/lobby/aitypes.lua

Fortunately for us this is really easy, we just need to add our AI table somewhere in the lua/AI/CustomAIs_v2/ folder (all files in this folder with a .lua get loaded).

For example, we could create a file lua/AI/CustomAIs_v2/EpicAi.lua, containing:

 AI = {
   Name = "Epic",
   Version = "1.0.0",
   AIList = {
       key = 'epic1',
       name = "AI: Epic AI 1",
       key = 'epic2',
       name = "AI: Epic AI 2",
   CheatAIList = {
       key = 'epiccheat',
       name = "AIx: Epic",

This is the table that the lobby will load in to give your AI as an option, and has subcategories for normal and cheating AIs. We can stick as many AIs as we like in here.

Next we need to create some lobby tooltips for our new AIs, these are the help texts that come up when someone hovers over our AI. To do this we will be adding to the Tooltips object in lua/ui/help/tooltips.lua.

Since this is already full of stuff, what we really want to do is append to it (rather than have to maintain an up to date tooltips.lua every time a new FAF patch comes out).

For this we create our shadow file in schook: /schook/lua/ui/help/tooltips.lua, and our file contents should look something like:

 Tooltips.aitype_epic1 = { title = "This is the title for AI Epic 1", description = "This AI really is epic!!", }
 Tooltips.aitype_epic2 = { title = "AI: Epic 2", description = "This AI is really epic as well!!", }
 Tooltips.aitype_epiccheat = { title = "AIx: Epic", description = "This AI cheats so is marginally less epic :(", }

This is all we need to add our AIs to the lobby.

Defining AI behaviour

AI behaviour gets keyed by files in the lua/AI/AIBaseTemplates/ folder