Adding an AI

From Off Grid Wiki
Jump to: navigation, search

Adding AI to your level

This page will guide you through the process of getting an AI Agent into your level. You should already have created your level, and have the mission script for it open before you start!

The Characters Table

The first step is to add a table to the characters table in the mission script.

 5 -- Character definitions:
 6 	characters = {
 7 		guard = {
 8 			displayName = "Marcus Fordham",
 9 			internalName = "Marcus_Fordham",
10 			prefab = "hugeGuard",
11 			agent = "Guard.lua",
12 			characterType = "enemy",
13 			profile = "MarcusFordham.lua",
14 			spawnpoint = "guard1spawn",
15 			patrolroute = {
16 				points = {
17 					"PatrolPoint_F0-LobbyStairsA",
18 					"PatrolPoint_F0-LobbyDiningHallA",
19 					"PatrolPoint_F0-DiningHallSnackMachine",
20 				},
21 				cyclic = false,
22 			},
23 		},
24 	},
attribute type description
displayName string The name of the character that will be displayed in-game.
internalName string The name that will be used within the game. This is the name that would be used with the API.
prefab string The prefab to use.
colorTexture string The colourising texture to use.
metalSmoothTexture string TBC
agent string The agent definition to use.
characterType string enemy, virtual, npc or player.
profile string The personality file to use.
spawnpoint string Where the Agent will first appear.
patrolroute string The (optional) set of points that the Agent will patrol along.

Let's look at a few of these in more detail.

prefab

These are currently hard coded. This will be changing in time. The current options are:

prefab name description
player Joe, our protagonist.
hugeGuard A big, burly male.
Secretary Female office worker. Also can be seen as the leader of the shady government forces in the intro.
drone A drone.
M_Lrg_LongJacket-01 A large male.
M_Lrg_Waistcoat-01 A large male.
M_Med_SmartShirt-01 An average sized male.
F_Med-WorkSuit-01 An average sized woman.

These can be colourised using the attributes "colorTexture" & "metalSmoothTexture".

agent

There are currently two basic Agent definitions that can be used - "Guard.lua" & "OfficeWorker.lua". For information on writing custom Agent definitions, see Agent Definitions.

patrolroute

Agents with a PatrolAction need a list of GameObjects within this table.

SetupMission

This is the first function to run. For all the magic to work, the Mission has to have each character added to it. There are two methods of doing this:

All in one go!

105 	for k, character in pairs(mission.characters) do
106 		Mission.AddCharacter(character)
107 	end

Or one by one.

108 	Mission.AddCharacter(mission.characters.guard)

StartMission

This function is called after SetupMission, and you can rely on certain things being done by this point (such as characters being present, among other things)! As a result, we can start to do things to our character. The most important being adding it to a network (or two, or three). Not much of a hacking game otherwise!

306 	Mission.ConnectToNetwork(mission.characters.guard, mission.networks.4G.name, mission.networks.4G.userAccessKey)
307 	Mission.ConnectToNetwork(mission.characters.guard, mission.networks.WiFi.name, mission.networks.WiFi.userAccessKey)

For more information on networks, please refer to XXXX.

So what else? It's quite possible that you want to empower your character with the ability to get through doors. If you've not covered the Door System yet, follow the link.

306 	Doors.AssignKeyToCharacter("Security", mission.characters.guard)

This is probably the bare minimum required to get a new Agent into your level. But there's more that can be done, so keep in mind that the AI API (and others) can be used to create interesting behaviours during your mission. There's nothing to stop you from making all your Agents tired after the player finishes an objective, for instance, and that's just one example.