Fools Rush In - Part Seven

The next thing to look at are the triggered events that will mark the passage of time during the hour of play time. First off, let's look at the creature we mentioned briefly in the plan. Getting some wildlife moving around our map and discovering the ways we can get our prototype NPCs to react to such wildlife sounds like a decent learning exercise.

The Unreal 2 actorlist contains a giant arachnid, which I found to be one of the creepiest enemies in the game, mainly because I'm a committed arachnophobe. Giant insects and spiders have been a staple of science-fiction since the beginning and are cliche as a consequence, but I have an idea that amuses me.

Girls are scared of spiders, right? It's a well-known fact. Spiders in the bath, absolutely terrifying to /girls/. Except that's just a tiny little bit of stereotypical bunkum, one of hundreds that add up to tip the scales in favour of creating the same boring characters over and over again. So let's have a bit of fun with it. Somewhere near the start of our story the characters called Sarah and Beth will be out surveying the surrounding area, watching for signs that the Ghost Warriors have caught up with them. The first time the player sees them they will appear over the rise that lies directly in front of the bunker, running full pelt and screaming their heads off. Yeah, girls are scared of spiders alright, 'cos this one is about six-foot at the shoulder and will be seen running over the hill in pursuit of the girls. Just as Beth and Sarah reach the safety of the bunker, Anna will also spot the advancing creature and then all three will open fire, hopefully turning the errant arachnid into mush. Or they'll get eaten. Which could seriously shorten their character development. We'll see.

The spiders in Unreal 2 are dayglo orange, which isn't that scary. A little light re-skinning turns our luminescent, slightly comical creature into a hairy black menace, as is only proper.

Marvellous.

Now then, how to get the ugly sucker to do our bidding. There is very little in the way of unreal 2 specific editing available on the internet. There is plenty of information that relates to the Unreal engine in general but several of the more important aspects of Unreal 2 are particular to Legend Entertainment's implemetation, including AI Scripting, and that stuff is incredibly hard to come by.

Enter one Matthias Worch Who worked on the game with Legend. Out of the goodness of his heart he has written several primers specifically about Unreal 2 AI scripting and dialog implementation:

http://www.langsuyar.com/articles/u2_tutorialsmain.html

...and this information is going to be our primary 'how to'. Additionally, there is a basic set of reference materials available as a bunch of text files which I found here:

http://www.fileplanet.com/download.aspx?f=120885

You'll need a Fileplanet ID, sorry. I might host it here, but I'm a bit unsure about the copyright so that'll have to do for now.

This is essentially a dictionary of commands and their definitions. There's little in the way of guidance on implementing those commands, but it's certainly going to be invaluable as we trial-and-error our way towards getting what we want.

Let's kick off by putting our arachnid in the map:

There are two ways we can achieve this. The first way is to place the original 'araknid' pawn and then manually overide it's 'skins' settings with the new textures we've previously loaded. A better method is to create a custom pawn class for it, that way we can butcher the settings as much as we like at source without having to overide the one beast we placed in the map all the time. Also it means that every time we place our custom pawn it'll have our custom settings.

It's not that hard once you've figured out how to compile custom classes. Just find the the original class text file, duplicate it in your custom package folder, edit and rebuild. Actually, it's probably a lot harder than that if you have no idea what I'm talking about, but I don't want to write pages and pages of tutorial on stuff that has already been covered far more eloquently on sites like UnrealWiki (we'll be going back there quite often).

The most important property we have to change is called CommandFileName which is simply the name of the file we're going to write all of our instructions in, as per Matthias' tutorial linked above. At runtime the engine will search for this file and read it for the instructions.

Let's try something simple to test it out:

gotoactor Pathnode34

...which just tells the spider to find its own way to a specific object in the map with the object-name 'Pathnode34'. Incidentally, pathnodes are vertex objects you place in the map to define a series of paths that NPCs can follow. It's how they 'see' the geometry of the map. I've already placed a few basic ones in the map and built the path network. Pathnode34 lies right at the top of the ramp at the entrance to the bunker, which means our spider should attempt to run right up the ramp.

A quick test run proves the theory:

Arachnid comes over the rise...

...makes his way down the hill...

...walks spiderly up the ramp.

Huzzah! The spider does as it's told. That's more than that bitch Emily ever did.

The next step is to bring on Beth and Sarah as potential lunch.

For our two Angels we're going to pull exactly the same stunt, setup a command file for both pawns and just order them to run like hell towards a specified actor. We'll place two navigation points (in this case Cover Points, but we're not entirely sure those work as actual cover indicators, playing with someone else's code you often find the remnants of systems that we're either abandoned or not fully implemented before time ran out). The cover points are children of the actor superclass and as such have object-names, so they should work fine just as AI landmarks.

We'll place Beth and Sarah out of sight behind the rise and give them a headstart on the spider because we don't want them to get eaten before we've seen them, likewise we don't want them to kill the spider before we've seen it.

A test run:

Sarah and Beth run over rise...

...here comes the spider in hot pursuit...

...Sarah and Beth facing the wall doing nothing. Hmm.

Erk. Once Sarah and Beth reach the cover points they just wander off and it looks odd. NPCs have two modes of operation, 'Scripted', in which they follow the commands in the command file and 'Autonomous' in which they wander around and obey the unseen commands the AI programming automatically assigns to them based on what is going on in the game environment.

Lets modify Sarah and Beth's command files. After they reach the cover points we want them to turn around to face the spider. After all, they have reached the relative safety of the bunker and with their mates behind them they can turn the tables on the arachnid. so let's add the command 'turntoactor' and target the same central pathnode the spider is making for, Pathnode34. After that, we want them to wait until they see the spider before they start firing. Luckily, one of the commands used by the 'Autonomous' mode is 'seeEnemy', when the NPCs see an enemy pawn they will attack it. To have Sarah and Beth stay where they are until that happens we ask them to 'sleep'. This doesn't mean they will doze off, just that the AI routines will do nothing until it gets new stimulous, in this case sighting the spider. The command file for the girls now looks like this:

gotoactor Coverpoint1
turntoactor Pathnode34
sleep

Another test run:

Sarah and Beth run over rise...

...cue the spider...

...Sarah and Beth turn to face the oncoming spider...

...and open fire.

Success!

The final issue we have to address is an administrative one. Although we have the beginnings of a reasonable set piece, seasoned with some autonomous behaviour on the part of the bots (i.e. actual 'play'), we want to be able to fire this event according to what time it is. We need the spider, Beth and Sarah to wait patiently behind the rise until they get their curtain call. As it stands, if we just leave them stationary the autonomous behaviour will take over and they'll fight each other to the death. We need a command that will disconnect the AI until it's called into action and a quick run through the reference text shows us that command is called 'dormant'.

We'll set dormant 1 for spider, Beth and Sarah. Now when we run the map they don't do anything at all. We need some way to trigger the execution of our commands.

Events and triggers are staple Unreal editing. An 'Event' is simply a named message that is broadcast to the game environment. You can use these broadcasts to activate all kinds of things. You can set a door to open when the Event 'door' is sent by a button, for example.

Triggers are devices you can use to send and Event message dependent on a variety of circumstances. For testing purposes, we'll create a Trigger that sends the Event 'StartRun' when the player runs over it. If we get the NPCs to stop being dormant when this Trigger is activated we should be able to start Beth, Sarah and the arachnid running when we're ready to observe the effects.

The CommandFile syntax allows us to label blocks of code with a specific name. For the girls let's call the commands that send them to the entrance of the bunker ':RunToBunkerEntrance' and for the spider we'll call his commands ':EatGirls'. The command that tells an NPC to expect an Event name is 'onevent', so for the Angels we can say 'onevent StartRun (the Event name broadcast by the trigger) gotolabel :RunToBunkerEntrance (the set of commands that get them to the bunker)'.

So the sequence written in plain english now goes:

...and the code looks like this:

ontrigger StartRun gotolabel RunToBunkerEntrance
dormant 1
sleep

:RunToBunkerEntrance
dormant 0
gotoactor Coverpoint1
turntoactor Pathnode34
sleep

So it's really quite simple. Test run:

Here's the trigger...

When we run over it the sequence plays out just as before.

Huzzah.

We'll leave it there for now, aside from updating The Plan. We have successfully built a set piece that we can execute when we send a specific Event to the system, which is a bunch of experience that is going to prove invaluable as much of what we have planned depends on things happening at an appointed time.

Next time, we'll look at building an artillery barrage in a similar way.

Sarah: "I fricking hate this godforsaken rockball. And I FRICKIN' HATE spiders. Giant frickin' spiders...
Anna: "Technically it's a type of wasp."
Sarah: "Shut up."

Comments: on the _blackbored

Next: Part Eight