Call of Duty: World at War

Call of Duty: World at War

Not enough ratings
[Scripting Tutorial] A.I. Basics
By SparkyMcSparks
Basic technical overview of working with AI in Call of Duty.
The Call of Duty engine is heavily data-driven, and while the AI foundation is in the source code compiled into the game EXE, much of the gameplay behavior for AI is controlled through script from combat states to animations and one-off vignettes.

This tutorial will take a very basic but technical look at how the AI works in Call of Duty.
Configuration Files for AI Characters
AI are setup through the ...\aitype\aitypes_characteraliases.GDT which can be opened in Asset Manager. This ASCII file contains the character model permutations, weapon loadouts, and engagement distances for all of the AI in the game.

The Converter parses the GDT and autogenerates a GSC script and CSV file for each AI type. When you drop the AI actor in a level and compile it, Linker will automatically grab the autogenerated files associated with the AI type.

The autogenerated GSC is also referenced by Radiant, the level editor, so it can let you drop a spawner for the AI type.

.png]Note: If you want to make a new AI type, it's HIGHLY advisable to create a new GDT. Editing the aitypes_characteraliases.GDT will flag the Converter cache to attempt a reconvert of all AI types in that specific GDT, and since it's included simply for reference (and will error out) it'll erase all the stock autogenerated AI types supplied in the mod tools.

// THIS FILE IS AUTOGENERATED, DO NOT MODIFY /*QUAKED actor_ally_us_usmc_roebuck (0.0 0.25 1.0) (-16 -16 0) (16 16 72) SPAWNER FORCESPAWN UNDELETABLE ENEMYINFO defaultmdl="char_usa_marine_fullbody1" "count" -- max AI to ever spawn from this spawner SPAWNER -- makes this a spawner instead of a guy FORCESPAWN -- will try to delete an AI if spawning fails from too many AI UNDELETABLE -- this AI (or AI spawned from here) cannot be deleted to make room for FORCESPAWN guys ENEMYINFO -- this AI when spawned will get a snapshot of perfect info about all enemies */ main() { self.animTree = ""; = "allies"; self.type = "human"; self.accuracy = 0.2; = 100; self.weapon = "thompson"; self.secondaryweapon = ""; self.sidearm = "colt"; self.grenadeWeapon = "fraggrenade"; self.grenadeAmmo = 3; self setEngagementMinDist( 256.000000, 0.000000 ); self setEngagementMaxDist( 768.000000, 1024.000000 ); character\char_usa_marine_h_miller::main(); } spawner() { self setspawnerteam("allies"); } precache() { character\char_usa_marine_h_miller::precache(); precacheItem("thompson"); precacheItem("colt"); precacheItem("fraggrenade"); }

rawfile,aitype/ally_us_usmc_roebuck.gsc character,char_usa_marine_h_miller weapon,sp/thompson weapon,sp/colt weapon,sp/fraggrenade
Debugging A.I.
To bring up a rudimentary debugging tool for AI, make sure you are first running Developer mode (+set developer 2) and devmap into a level.

From there, toggle the dvar g_entInfo <0-5>. For most cases, you'll either use 1 or 2.
All ents / draw lines / draw info
Selected ent / draw lines / draw info
Selected ent / draw info
All ents / draw goal lines and raii
Selected ent / draw goal lines and radii

You'll notice some 3D text above AI and some lines drawing around them, here's a breakdown of what they mean. We'll start with the lines first:

AI Bounding Box
Pink rectangle around AI.
This is the bounding box that should always surround an AI. For the most part, it'll represent the AI having bullet and player collision.
AI Goal Radius
Green circle on the ground the AI is running to.
The center of the circle represents the origin the AI is trying to run to, and the circle radius represents the distance at which the AI will be notified it's reached it's goal.
Target Visibility Trace
Line drawing from AI head to another AI's head.
This represents whether the AI can see it's target.

Green = Can clearly see.
Red = Cannot see.
Yellow / Orange = Slightly obstructed.

We'll go over the more common of the 3D text above the AI using the image above as reference:

126 : starting_allies
<entity #> : <targetname>
The entity number is a unique id, and the targetname is for that AI.
health: 1000000000
health: <health #>
The current health for that AI.
384 : <noname target>
<enemy entity #> : <enemy targetname>
The current enemy's unique entity id, and the enemy's targetname (if it has one).
range: 774.88 ac: 0.04 MISS 8
range: <distance to current enemy> accuracy: <chance of hitting current enemy> MISS ???
The engagement distance and accuracy for the current AI.
IGNOREALL FLAG: <true/false>
Whether the current AI is ignoring enemy AI.
< >
Gal4xy Oct 19, 2016 @ 11:38am 
is there a way to spawn them while in game? or is there a command to do so? ive modded the Xbox 360 and on campaign in my mod menu. there was a option to spawn ai and it worked. so do you perhaps know the command for it on pc?
Rinkydink Snorkeldick Jul 4, 2016 @ 7:00pm 
Very, very interesting!
Ghost0fSparta96 Jan 2, 2015 @ 12:29pm 
Fantastic tutorial man, Im at the very beginning of trying to understand how all of this works