Alien vs. Predator 2 combines elements, creatures, and settings from the hit movies Aliens and Predator in three unique, interlocking stories. They unfold from the perspective of a young Marine Corporal, a newly-emerged Alien, and a Predator on the hunt. Highly detailed environments, phenomenal effects, and an advanced game engine intensify the gameplay of this first-person shooter adventure.

Post tutorial Report RSS AI Escorts in AvP2

AI Escort units for AvP2. They display a similar behavior like the NPC's in Half Life.

Posted by on - Intermediate Client Side Coding

The following prefab is a simplification to the original AI Escort prefab;  it has less triggers, without affecting too much it's performance.
I don't know whether I've stated this before or not, but this page
CANNOT REPLACE modmaker's tutorial and the docs that came with the tools
(I'm talking about the avp2_AI_notes.doc file). Read them if you plan on
expanding this prefab; you'll need some info about AI Volumes and AI commands
that can be found in those docs. If you're only after a copy-paste prefab,
or you're experienced enough with AvP2's AI, you can skip them.

a. Describing the problem
The problem itself is the same: what does an escort actually do? It follows
the player anywhere he/she goes and, when spotting an enemy, opens fire. The
AI that escorts the player must be able to receive orders like 'Follow me'
and 'Hold ground'. Either way, the AI must attack any enemy within his range.

So all we have to do is to give our AI an iddlescript and tell him to run
towards the player by sending it the message:
killscripts; iscr(run; mt player; end;)
We can continuously send this command using some sort of loop.
The fact that it's an iddlescript will allow the AI to break the script to
engage enemies. Although it's something that we want, it does have one bad
effect: the AI, having the script terminated by engaging the enemy. However,
the next message will tell it to move on.

How do we 'persuade' this pesky marine to stop following us? Well, that's
easy: kill it's scripts (the 'killscripts' command) and terminate the loop.
To make it follow the player again, give it a script and restart the loop

b. Looped triggers
Place two triggers, both of them with a 'SendDelay' of one second and make
them trigger each other: triggerA should have as target triggerB and
vice versa. Trigger any of them and you'll get a 2 seconds period loop. Each
two seconds triggerA gets triggered. To break the loop, send the 'lock'
message to one of the triggers. To restart the loop, send the 'unlock' message
to the locked trigger and then trigger any of them. That easy.

In our case, we'll need just one loop.

c. The scripts
The following images contain explicit scenes and should not be viewed by
any audience. This images are for mappers' eyes only :-)
First, the structure of one AI escort unit:

unit structure

The EAIMarine0 is the A.I. unit that gets to follow your ass. LoopA0 and loopB0 make up the 'short-fused' loop. FollowMe0 unlocks the loop and restarts them after starting a new
script. HoldGround0 does the opposite: kills all scripts and locks the loop.

Here are the settings and commands for the AI unit:
ai settings
I know this is a little bit unusual, but I've set the AI unit to be indestructible. That was achieved by setting the 'NeverDestroy' flag to TRUE (see 'DamageProperties' for the AI unit).

However, the interesting part takes place in the 'Commands' section and the goals selected in 'Goals':

AI Unit goals

As you can see, I choose only the 'Attack' and 'Iddlescript' goals. The third goal makes the AI look more natural while standing still. The other stuff I was talking about is the 'Commands' section. Placing messages in here will allow you to use the AI unit much like a switch:

AI Unit ON/OFF messages

So, if we press 'USE' while facing EAIMarine0, we'll trigger either
FollowMe0 or HoldGround0.

As stated earlier, these two triggers unlock and start the loop or do
the opposite. The settings and targets for the FollowMe0 trigger:

Follow player trigger

What does it do? Unlocks and starts the 'short-fused' loop that sends the
iscr messages. It also starts the iddlescript for the AI unit, makes
it say something and allows it to move anywhere (leash length is set to 0).

The loop has the loopA0 trigger and loopB0 trigger. Those two are almost
identical, except the last target. The settings and targets for the loopA0
trigger:

loop closer

The loopB0 trigger has it's second target set to loopA0. Except that, they're twins.

From 'HoldGround0' we'll expect to kill all scripts and lock one trigger in our loop:

Hold Ground trigger
And you were right; it also makes the AI say one phrase and gives him a
384 units leash around the point it was ordered to guard.

If you plan to add more units like these, the only thing you should be
aware of is to change the 'Commands' section so that EAIMarineXX sends
his messages to FollowMeXX and HoldGroundXX. The triggers themselves
are excellent connected, so you won't need to change anything there when
copy-paste -ing folders containing units like these; your only concern will
be the 'Commands' section. So, copy-paste whole folders and change the
'Commands' section for each AI unit.
It may rarely happen that even after you've told the marine to hold ground,
it may still follow you; that's because the other trigger already got ...
triggered and it was only a matter of time (those 3 seconds) until it managed
to send it's messages. You can shorten this amount of time; however, you'll be
starting and ending too many scripts per second, so it may cost you extra CPU.
It's a nasty choice: better AI performance vs. better overall map behavior.
Three seconds were a good compromise. However, feel free to toy with this;
remember, the power of the computers grows every year.

Expand the escort by means of Copy-Alt_Paste and editing the ActivateOn and ActivateOff fields in the Commands section.

Hopefully, this will spell the end for those SP missions that left you
alone to deal with your enemies.

Post a comment

Your comment will be anonymous unless you join the community. Or sign in with your social account: