Character AI in GTA 2 Mission Scripts
You have a lot more control over mission characters in GTA 2 than in GTA 1.
Occupations
This details what they do, from criminal to police officers. Below is a list of valid occupations for your peds. See also character occupation memory addresses by Sektor.
ANY_ELVIS
| Primarily used for bonus checks. |
---|---|
ANY_EMERGENCY_SERVICE_MAN
| |
ANY_GANG_MEMBER
| |
ANY_LAW_ENFORCEMENT
| |
ARMY
| Army Soldier. |
BANK_ROBBER
| Bank Robber. |
CARTHIEF
| Dude who goes and steals cars. |
CRIMINAL
| Normal Criminal. |
CRIMINAL_TYPE1
| Attacks CRIMINAL_TYPE2 characters.
|
CRIMINAL_TYPE2
| Attacks CRIMINAL_TYPE1 characters.
|
DRIVER
| Driver of a car. |
DRONE
| Probably follow exactly what you do. |
DUMMY
| Normal ped. |
ELVIS
| Part of an Elvis group. |
ELVIS_LEADER
| The leader of an Elvis group. |
FBI
| FBI bloke. |
FIREMAN
| Fireman. |
GUARD
| Guards an object or area. |
GUARD_AGAINST_PLAYER
| Guards against the player. |
MUGGER
| Steals peoples cash and runs away. |
NO_OCCUPATION
| Used for START_BONUS checks.
|
POLICE
| Police Officer. |
PSYCHO
| Goes around city killing people. |
REFUGEES
| Probably have no weapons, weak etc. |
ROAD_BLOCK_TANK_MAN
| Dude at Tank road block. |
SPECIAL_GROUP_MEMBER
| Probably someone who can fight independantly of the player. |
STAND_STILL_BLOKE
| Someone who stands very still. |
SWAT
| SWAT member. |
TANK_DRIVER
| Driver of a tank. |
Threat Search
If you want to make your peds to act as a guard, you’ll need to make them know who to look out for. By default, if a gun is fired when he is on screen, he will simply run away and then return. You need to use the THREAT_SEARCH
as well as THREAT_REACTION
(next topic) in order for him to effectively act as a guard:
SET_CHAR_THREAT_SEARCH (name, SEARCH_TYPE)
NO_THREATS | Doesn’t look for threats. |
---|---|
LINE_OF_SIGHT | 90° search area. Blocked by buildings but not cars and objects. |
LINE_OF_SIGHT_PLAYER_ONLY | Same as LINE_OF_SIGHT except only the player is looked for.
|
AREA | About 3 cells in every direction. Moves with the character. |
AREA_PLAYER_ONLY | Same as above, but only looks for the player. |
Example code:
SET_CHAR_THREAT_SEARCH (guard01, LINE_OF_SIGHT_PLAYER_ONLY)
Now that your character has found the player, what does he do? Stand and fight or run away? This where reactions come into it. The next topic details this.
Threat Reaction
The THREAT_REACTION
makes you choose what the ped does when he finds a threat, he can either react as normal (such as shoot) or run away.
SET_CHAR_THREAT_REACTION (name, REACTION_TYPE)
NO_REACTION | Ignores the threat. |
---|---|
REACT_AS_NORMAL | Do the default for that occupation. A guard will attack the threat. |
RUN_AWAY | Once the character is far away from the threat, it will to normal action. |
Example code:
SET_CHAR_THREAT_REACTION (guard01, REACT_AS_NORMAL)
Objectives
You can also give objectives to the ped to make him do a number of things, from shoot a person, get in a vehicle, walk to location and many more. If the character is told to walk to a location, he will do that objective until he gets there and then he stops waiting for another command, so this is where IF commands come into it, but for now we’ll just detail the one-off objectives.
SET_CHAR_OBJECTIVE (name, OBJECTIVE_TYPE)
This is a basic function which tells him to do this:
SET_CHAR_OBJECTIVE (name, OBJECTIVE_TYPE, second_item)
This is generally used for "kill this" actions or entering/exiting cars. The second item is a previously created car, character or something else. The game will crash if the object doesn’t already exist when you use this command!
Can also be used for "go to" commands if you put an (X,Y,Z)
coordinate in:
SET_CHAR_OBJECTIVE (name, OBJECTIVE_TYPE, X,Y,Z)
NO_OBJ | Make him walk around like a normal ped. Useful if you don’t need the character anymore. |
---|---|
WAIT_ON_FOOT | Wait on foot until something happens. Simple. |
FLEE_ON_FOOT_TILL_SAFE | Character runs away until he thinks he’s safe, about 6 blocks. |
GUARD_SPOT | Guard his standing position. Best give him a weapon. |
GUARD_AREA | Guard this area, usually 3–6 blocks. |
WAIT_IN_CAR | Sits inside a car doing nothing. |
KILL_CHAR_ON_FOOT | Character runs after person on foot. Give him a weapon otherwise he’ll start punching him. |
---|---|
KILL_CHAR_ANY_MEANS | If he is off screen, he will use a car to chase victim. Will also warp so don’t put an arrow on him. |
FLEE_CHAR_ON_FOOT_TILL_SAFE | Run away until he feels safe. Give him another command or he’ll start walking around normally. |
FLEE_CHAR_ON_FOOT_ALWAYS | Always run away from this character. |
GOTO_CHAR_ON_FOOT | Locate a second character. Once done, it is classed as “passed objective” and will do nothing else. |
LEAVE_CAR | Exits a created car, must be inside car! |
ENTER_CAR_AS_PASSENGER | Enter a created car as a passenger. |
ENTER_CAR_AS_DRIVER | Enter a created car as a driver. |
FOLLOW_CAR_IN_CAR | Character must be in a car to follow. Set the second item to be a previously created car. |
FIRE_AT_OBJECT_FROM_VEHICLE | Character must be inside to work, useful for tanks. |
DESTROY_OBJECT | Set the second item to what is going to be destroyed. |
DESTROY_CAR | Destroy a previously created car. |
GOTO_AREA_ON_FOOT | Run to a spot on the map. |
---|---|
GOTO_AREA_IN_CAR | Drive to a location on the map. Must be inside car when you use this command! |
FOLLOW_CAR_ON_FOOT_WITH_OFFSET
This requires a second_item
, an integer rotation
, and a floating point distance
. Remember to limit the driver’s maximum speed so the characters can stay with it! Also remember you might need bigger distances for bigger cars when they turn, such as the Limosine.
SET_CHARACTER_OBJECTIVE (name, FOLLOW_CAR_ON_FOOT_WITH_OFFSET, second_item, rotation,distance)
Example, following about 1 block away to the left:
SET_CHARACTER_OBJECTIVE (bodyguard, FOLLOW_CAR_ON_FOOT_WITH_OFFSET, presidential_limo, 270,1.5)
Example, leading the car by a few blocks (might fall behind when the car turns):
SET_CHARACTER_OBJECTIVE (bodyguard, FOLLOW_CAR_ON_FOOT_WITH_OFFSET, presidential_limo, 000,4.0)
FOLLOW_CAR_ON_FOOT_WITH_OFFSET
| Orders the character to follow the movements of a particular car 'on foot'. distance is measured from the centre of the car. rotation sets which side of the car. second_item is the name of the car to follow.
|
---|
Examples
SET_CHAR_OBJECTIVE (guard01, GUARD_SPOT)
SET_CHAR_OBJECTIVE (guard02, GOTO_AREA_ON_FOOT, 12.5,27.5,2.0)
Patrol Points
You can simply leave guards and others just stand on the spot, but you can also add patrol points for them and add as many as you like!
ADD_PATROL_POINT (name, X,Y,Z)
The guy will walk to it, and back to his original place, and then back again for infinity until you tell him to do something else. An example could be:
ADD_PATROL_POINT (guard02, 12.5,13.5,2.0)
You don’t have to tell him to return to his start position as he’ll do it automatically. If you’re just making him go back and forth, you just need to add one patrol point set to the location to walk to.
(Originally written by Chris “Pyro” Hockley and formatted by Ben “Cerbera” Millard with full permission.)