How to add an NPC and set up alliances

Prerequisites:
The Basics

Overview:
This tutorial will describe how to set up characters' alliances.  Often you will want to add characters that immediately act as enemies or be able to control when a type of character is friendly or hostile.

 

1. Place one or more characters of the same type

Under Actor -> Pawn -> ScriptedPawn, there are a number of categories of characters you can add to a map.  Add one.  For example under HumanMilitary, you might add one or more MJ12Troop items.

 

2. Set up alliances to player

To get the character(s) to be an enemy, pull up their properties and expand Alliances -> InitialAlliances -> [0].  Set the AllianceLevel to -1, the AllianceName to Player, and bPermanent to True.  If you had, say, 15 MJ12Troop's you wanted to set as enemies, you could right-click one of them and hit "Select all MJ12Troop actors".  Then you could pull up and set the properties for all 15 at once.  If you think you might need to set other characters' alliances to this one, you can also fill in the Alliance value with something, if there isn't a default value there.  Try "mj12" for this exampe.

As stated in the SDK docs, the valid values for AllianceLevel are:

-1 = Hostile toward
0 = Neutral toward
1 = Friendly toward

The Alliance name of the player is, well, "Player".

The bPermanent value will force an alliance to stay friendly, neutral, or hostile.  For example, if bPermanent was set to False and you shot at a friendly, their alliance will change to hostile and may very well start shooting back.

 

3. Set up alliances to other NPC's

If you want to have characters be friendly, neutral, or hostile to each other, you can define up to 8 alliance relationships per NPC.

Let's say we want to add some Greasels that don't like MJ12, but are friendly with Karkians and Grays.  Add one or more Greasels to your map and pull up their properties.   Expand Alliances -> InitialAlliances -> [0].  As it turns out, the Greasel class has a default Alliance name of "Greasel" and is already set up to be friendly to Karkians.  As you might guess, the default Alliance name of a Karkian is "Karkian", and the default for a Gray is "Gray".

Expand the [1] item and set AllianceLevel to 1, AllianceName to Gray, and bPermanent to True.

Expand the [2] item and set AllianceLevel to -1, AllianceName to mj12 (the alliance name from Step 2), and bPermanent to True.

 

4. Change alliances via triggers

If you have bPermanent set to False, there are a number of events that can cause an NPC's alliances to change.  However, you can also trigger an alliance change explicitly using an alliance trigger.

Expand Actor -> Triggers -> Trigger, select AllianceTrigger, and add one to your map.  For an example, let's use the Greasels from the above example and have them turn against the player when the trigger is fired.  Pull up the AllianceTrigger's properties and expand AllianceTrigger -> Alliances -> [3].  The reason we're using #3 is so that we don't step on the other alliances we set up in Step 3.  Set AllianceLevel to -1, AllianceName to Player, and bPermanent to True.  Also, set the Alliance value under AllianceTrigger to Greasel.

We're not done yet, though.  We'll also need to fill in the Events -> Event value to the Tag value of the NPC's we're changing.  In this case, the default Tag value for a Greasel is (you guessed it), "Greasel".  So expand Events and set Event to Greasel.

You should now see red lines extending from the AllianceTrigger to the Greasels in your map.  Here's a top view of an AllianceTrigger attached to 2 greasels.

Here, the greasels will turn to enemies as soon as the player steps into the range of the trigger.  (the radius is set by changing the Collision -> CollisionRadius value)  You could also set the CollisionRadius to zero and/or put the trigger where the player couldn't run into it and fire the AllianceTrigger another way.  For instance, you could set up a conversation to trigger it in ConEdit.


Back to main page