AI basics    
 the problem  
   solutions?  
   AI scripts   
  the triggers 
  extra hints   
  the .zip file  
prefabs 'office' [email protected]


  The folowing prefab is a simplification to the original AI Escort prefab;
 it has less triggers, without afecting too much it's performance.
  I don't know wether 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 alow 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
 viceversa. 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:

 
  The EAIMarine0 is the A.I. unit that
 gets to follow your ass.

  loopA0 and loopB0
  make up the
 'short-fused' loop.

  loopC0 and loopD0 make up the second
  loop; it keeps killing the AI's script
  and starts a fresh one.
 
FollowMe0 unlocks the loops and restarts them after starting a new script. HoldGround0 does the oposite: kills all scripts and locks the loops. Here are the settings and commands for the AI unit:
 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'.

  As you can see, I choosed 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 alow you to use the AI unit much like a switch: 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 loops or do the oposite. The settings and targets for the FollowMe0 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 lenght 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: 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 each loop: 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 anthing 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 folow yoy; 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 ammount of time; however, you'll be starting and ending too much 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. The .zip file will have both the .ed and this .html page. The .ed file is a small map, that has one EscortUnit and a multispawner, triggered by 4 wall switches. Toy with your escort, make him guard you or their last position with or without enemies. See how they behave. Expand it 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.
index