Adding an AI

From Off Grid Wiki
Revision as of 11:13, 5 December 2018 by Steve (talk | contribs)
Jump to navigation Jump to 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.

-- Character definitions:
	characters = {
		guard = {
			displayName = "Marcus Fordham",
			internalName = "Marcus_Fordham",
			prefab = "hugeGuard",
			agent = "Guard.lua",
			characterType = "enemy",
			profile = "MarcusFordham.lua",
			spawnpoint = "guard1spawn",
			patrolroute = {
				points = {
					"PatrolPoint_F0-LobbyStairsA",
					"PatrolPoint_F0-LobbyDiningHallA",
					"PatrolPoint_F0-DiningHallSnackMachine",
				},
				cyclic = false,
			},
		},
	},
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!

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

Or one by one.

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!

Mission.ConnectToNetwork(mission.characters.guard, mission.networks.4G.name, mission.networks.4G.userAccessKey)
	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.

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.