NPC Behavior & Ambushes
Table of Contents
Skywind Default Master Package
All Skywind actor base objects should have 00SkywindDefaultMasterPackageList as their Default Package List (or, they should inherit this from their template).
So long as there are no valid packages in the NPC's package stack, the Skywind Default Master Package will govern NPC behavior.
The Skywind DMP lets you apply an array of simple behaviors to NPCs. It is not appropriate for scheduling, for instance, the behavior of a town, but will be good for bandits, mines, tombs, creatures, etc...
To use the Skywind DMP you will need to know how to apply LinkedRefs to NPCs. See the Level Design Coding guide if you don't know how to do this.
This guide will cover all the things you can do with the Skywind DMP. There are examples of all these things in the cell zKMTestDefaultPackages.
I want my NPC to...
Sandbox where I placed them in the Creation Kit.
Nothing. Literally don't do anything, and this is what they will do.
Sandbox near a specific point.
Place an xMarker at that point, and link your NPC to it.
Stand at a specific point.
Place an xMarkerHeading at that point, and link your NPC to it.
Use a specific piece of furniture.
Place the furniture, and link your NPC to it.
Use a specific idle marker.
Place the idle marker, and link your NPC to it.
Follow another NPC.
Link the follower to the leader.
Patrol in a loop.
Place xMarkerHeadings and/or idle markers, and link them into a loop. Then, link your NPC to whichever marker you want them to start their patrol at.
Patrol back and forth.
Instead of making a loop with the xMarkerheadings/idle markers, just have the chain end at some point. Then, link the NPC to where you want them to start.
Aside: What is "Sandboxing"?
"Sandboxing" is a behavior meant to make an NPC appear active by letting them interact with their environment. A sandboxing NPC will variously:
Eat/Drink
Sleep (if an appropriate time)
Sit at a furniture marker (including "working" furniture like anvils, alchemy tables, and so on)
Use an idle marker
Wander around
Start conversations with nearby NPCs (if such conversations exist)
Using a sandbox procedure is an easy way to make an NPC appear "alive" without needing to directly control what they are doing and when they do it.
Because the DMP is meant more for bandits and the like than NPCs with actual schedules, the Skywind DMP by default will not allow NPCs to sleep. However, you can change this for specific NPCs if you want---just read to the next section.
What if I also want...
My NPC to run instead of walk?
Add the script fbmw_DefaultMasterPackageScript to your NPC (the placed NPC, not the base object), open the Properties window, and set the value of the SpeedRunning property to True instead of False (the default value is false).
My NPC to have their weapon drawn?
Add the script fbmw_DefaultMasterPackageScript to your NPC, open the Properties window, and set the value of the WeaponDrawn property to True (the default value is false).
To let my sandboxing NPC be able to sleep?
Add the script fbmw_DefaultMasterPackageScript to your NPC, open the Properties window, and set the value of the AllowSleeping property to True.
To stop my sandboxing NPC from wandering? (I want them to be working, not walking aimlessly!)
Add the script fbmw_DefaultMasterPackageScript to your NPC, open the Properties window, and set the value of the NoWandering property to True.
My NPC to only wander and not sandbox?
Add the script fbmw_DefaultMasterPackageScript to your NPC, open the Properties window, and set the value of the NoSandboxing property to True.
My NPC to stand exactly where I put them in the CK and not sandbox at all?
Add the script fbmw_DefaultMasterPackageScript to your NPC, open the Properties window, and set the value of NoWandering to True AND the value of NoSandboxing to True. That said, you'd really be better off placing an xMarkerHeading and linking your NPC to it.
None of this is exactly right/I want something else entirely.
You probably need a custom package for this, rather than the default ones! Get in touch with the coding department for help.
Extra Notes on Patrols
If you want NPCs to stand at an specific xMarkerHeading or use a specific idle marker for a certain amount of time, double-click on the marker and go to the Patrol Data tab. There, you can set the amount of time the NPC will stay at that marker.
"Patrol" is just the name of the mechanic; it doesn't mean your NPC has to be actually on the lookout for enemies. For instance, you can make a "patrol" out of farming idle markers or sweeping idle markers, as a way to put an NPC to work across a set path.
If you only want an NPC to pass through a point, use an xMarkerHeading. These are more optimized than idle markers. Please do not use a PatrolIdleMarker in your patrol unless you want your NPC to actually stand at the point for an amount of time.
It is possible to include furniture objects in a patrol, but there may be issues of the NPC popping in/out of the furniture if multiple pieces of furniture are linked together. You should make sure there is always at least one xMarkerHeading or idle marker between furniture objects on a patrol route.
Extra Notes on NPCs Following Other NPCs
Follower NPCs will try to match the running/walking behavior and weapon drawn/weapon sheathed behavior of the NPC they are following. However, this can be a little slow to update; it will be more robust to add the WeaponDrawn and SpeedRunning properties to the follower NPCs directly.
Follower NPCs will not inherit the IgnoreCombat behavior from the NPC they are following. That must be added to them directly.
If the leading NPC dies, the follower will sandbox near the corpse, subject to the NoSandboxing, NoWandering, and AllowSleeping flags on the follower NPCs.
If NoSandboxing==True and NoWandering==True, the follower NPC will stand over the corpse.
If NoSandboxing==True and NoWandering==False, the follower NPC will wander around near the corpse.
Etc...
How do I set up an ambush?
What is an ambush?
Ambushes are special combat encounters where an "Ambush NPC" waits outside of combat, typically in special furniture (the Creation Kit object type, not always literally furniture). The level designer can then control when and how the NPC gets up and starts attacking the player.
In Skyrim, think of things like Draugr or Dragon Priests bursting out of sarcophagi, Dwemer spiders and spheres rolling down out of ports, Falmer climbing out of holes in the wall, Spriggans materializing out of trees, and so on. In Skywind, these are used for skeletons and bonewalkers, ancestral ghosts, Dwemer creatures, and so on.
What NPCs can I use for an ambush?
Technically, you can make any type of actor into an ambush NPC, but generally you will want to use the ones that have already been created in the CK. In the object window, filter for 1_Ambush_ for unleveled ambush creatures and 1_Lvl_Ambush_ for leveled ambush creatures. (Remember to read Skywind Creatures for creature naming conventions.) Packages require special NPC AI/Behaviors, so unless you really know what you're doing, try to stick to the premade ones.
What are the types of ambush?
This can mean a few different things, so I'll go over all the different distinctions here.
Standard vs. GroundFX vs. Runner
This is the first prefix after Ambush on the creature ID.
Standard: 99 times out of 100, this is the type you want.
GroundFX: Mechanically, this is the same as the Standard ambush. The exception is that this one will add some effect shaders to the NPC as they climb out of their ambush furniture. This variant was introduced by Skyrim's Dragonborn DLC, for ash spawn climbing out of the ashy ground. That's the intended use case. Only place this type of creature if you really need those effect shaders during the ambush.
Runner: This is a special behavior type made for Squally, and follows its own set of rules for setting it up and using it. See the "Runner Type" NPCs section for details on this. The rest of this section will not apply to them.
OnDetect vs. OnTrigger
All ambush NPCs must must be activated before they will come out of their trigger. Prior to being activated, they will ignore combat and either wait ("sleep") at their ambush furniture, or do whatever else it is their packages tell them to do.
The next question is, what do they do when activated?
OnDetect: If an ambush NPC has an "OnDetect" label, then when activated, the NPC will start "listening" for enemies and will be allowed to enter combat, however they will not get out of their ambush furniture or otherwise change their behavior until they detect an enemy (i.e., the player).
OnTrigger: If an ambush NPC has an "OnTrigger" label, then when activated, they will immediately climb/rise out of their ambush furniture or break whatever other behavior they may have been set on. They will then wander/sandbox in the general area of where they "woke up", and will attack the player as soon as they can.
Furniture Types
Actually, there's no different types here. Skeleton/bonewalker alcove ambushes; wisp ground ambushes; Dwemer centurion ports; mechanically these are all identical. The type of furniture you want to use has no bearing on how the ambush NPC is named or how their packages are set up.
How do I set up an ambush?
Let's go through this in different steps.
Note: You may need to review the Level Design Coding guide if you aren't familiar with Linked Refs, Activate Parents, and placing Trigger Boxes.
Step 1: What does the NPC do while waiting?
Use Ambush Furniture: Link them to the furniture you want them to use. There will need to be navmesh going to the furniture's entry point. No navmesh, no ambush. Waiting in these furnitures is considered a "sleep" behavior, so this won't work if you, say, link an NPC to a random chair.
Patrol: Ambush NPCs don't need to use ambush furniture! You can actually set them up to do other things. The default "other thing" is to patrol. (Different "other things" require some different AI packages that we don't have set up by default.) To use a patrol instead of an ambush furniture, set up the patrol as described earlier on this page ("I want my NPC to... Patrol in a loop/Patrol back and forth" and "Extra Notes on Patrols"), then link your ambush NPC to where you want them to start the patrol using the LinkCustom01 keyword.
Stand in Place: Place an xMarkerHeading or an appropriate idle marker at the spot you want your NPC to stand. Double-click on the marker and navigate to the "Patrol Data" tab. Click the "Patrol Data" checkbox and enter some large number (e.g. 300) in the "Idle Time" field. (Basically, we're tricking the engine into treating this single point as a patrol.) Link your NPC to this marker using the LinkCustom01 keyword.
Step 2: Does anything else need to be activated when the NPC is triggered?
When the NPC is activated, they will pass on this activation to (potentially) four other things.
They will activate their linked ref (i.e., the furniture they are sleeping in). This triggers any "wake up" animations like a dwemer port's door opening.
They will activate their linked ref's linked ref. This handles thing like breaking a sarcophagus lid.
They will activate their linked ref's linked ref's linked ref. There is no common use for this, but you may find it handy in some special encounter might you devise.
They will activate their linked ref with the keyword of your choice. On the placed NPC, you can fill the linkKeyword property with the keyword of your choosing, and then link your NPC to something using that keyword to make them activate it when they come out of their ambush.
If you need any of this behavior, then set up these links now. If not, you can skip this step.
Step 3: How is the NPC triggered?
Two things will always force the NPC out of their trigger: Being attacked/taking damage (from any source), and the player activating them directly. This cannot be changed.
Otherwise, NPCs are triggered by activating them through something other than the player.
There are literally endless ways to handle this. I'm only going to cover the most common one here: The defaultActivateSelfTRIG triggerbox. This is a triggerbox that, when entered by an actor, will activate itself as its name suggests. We can then set our ambush NPCs to inherit this activation, thus triggering them. Here's how to set it up:
Navigate to near where you want the triggerbox to be placed, and click on a large object in that area, preferably a part of the tileset.
Click the "Create Triggerbox" icon on the menu bar (the cube with a T in it), then find and select defaultActivateSelfTRIG. This will create a triggerbox that fills the bounds of the object you had selected.
Move and adjust the size of the triggerbox as desired.
Edit the properties of the defaultActivateSelf script as you see fit. The defaults are: Player Only, Do Once, and No Minimum Level.
Double-click on your ambush NPC and navigate to the Activate Parent tab. Create a new activate parent, and set it to the triggerbox you just placed. Optionally, you can add a delay timer to the activation if you don't want to trigger the NPC immediately.
That's all! Your ambush should now work.
Note: Multiple NPCs can have the same triggerbox as their activate parent.
Note: One NPC can have multiple activate parents, such as different triggerboxes placed at different entryways to a room.
How do I make a custom ambush NPC?
That depends on how custom. The easiest way is to make your new NPC templated off of an existing ambush NPC. Make sure to inherit Scripts, AI Packages, AI Data, and Default Packages. Anything else can be changed. Also, make sure to follow the naming scheme described in Skywind Creatures.
If you need to make a completely new ambush NPC, then these are the things that are required for the ambush to work correctly.
The NPC must have a default aggression of zero.
The NPC must be set to "Helps Nobody".
The NPC must not have any Aggro Radius.
If any of the above are not set this way, it is likely that your NPC will come out of its ambush state early.
The NPC must have the masterAmbushScript attached to them.
The package at the top of the NPC's package stack must be conditioned on Subject.GetActorValue(Variable01) == 1.0000. This is what the NPC will do once they have woken up from their ambush. The default is AmbushSandboxEditorLocation512.
The package below this will be whatever you want the NPC to do before they "wake up". The standard is AmbushPatrolLinkCustom01 followed by AmbushSleepPackage. It is recommended that you only use the existing default ambush packages (filter for "Ambush" in the Packages section of the object window).
How can I keep my NPCs out of combat?
First things first:
The method described here is only meant to fill in gaps where an ambush wouldn't work or otherwise isn't appropriate.
This system should not be used on ambush NPCs at all.
If your NPC is an ambush NPC, then they should stay out of combat until triggered. If they're entering combat early, then there is some mistake in your setup or some other coding issue to resolve. Get in touch with a coder or experienced landscaper for help.
With that said, if your NPC isn't an ambush NPC, then read on...
A common complaint from level designers is that it's hard to keep NPCs from jumping into combat too early. You want separate fights in separate rooms, but the entire dungeon converges on the player at once as soon as the first fight breaks out. The Skywind DMP has a built-in solution for this. You can use it to make NPCs ignore combat until released by script. This section will tell you how to set this up.
Step 1
Add the script fbmw_DefaultMasterPackageScript to your NPC, open the Properties window, and set the value of IgnoreCombat to True. This step tells the NPC to ignore combat.
Step 2
Place a 0_dun_AllowCombatTriggerbox triggerbox into your cell. When the player enters this triggerbox, it will allow NPCs linked to it to enter combat again. So, place it in an appropriate spot for this, e.g. just outside the door to a room where the creatures inside are being held out of combat.
Step 3
Link the triggerbox to all the NPCs you want it to be able to release for combat. The first link does not need a keyword, but after the first, you will need to use LinkCustom## keywords when linking to NPCs. In other words, the 2nd NPC should be linked to with the LinkCustom01 keyword; the 3rd NPC with the LinkCustom02 keyword, and so on.
Note: The keyword is used on the link only. You do not need to edit any of the keywords on the base actors/triggerboxes/etc...
Step 4 (optional)
By default, any NPC entering the triggerbox will release the linked NPCs for combat. If you want to change this so that only the player can release them, set the PlayerOnly property on the triggerbox's script to True.
Step 5 (optional)
If you want, you can delay the release of linked NPCs by filling in the ReleaseDelay array (a property on the triggerbox's script). The first value in the array is the delay between the player entering the triggerbox and the first NPC being released; the second value is the delay between the first and second NPC being released, and so on. For instance, if the array was [1.00, 1.00, 1.00], then: The NPC with no keyword on their link would release 1 second after the player enters the triggerbox; the NPC with the LinkCustom01 keyword would release after 2 total seconds (1 second after the first NPC), and the NPC with the LinkCustom02 (and all other linked NPCs) would release after 3 total seconds (1 second after the second NPC).
Final Notes
When the player enters the trigger box, it will allow the linked NPCs to enter combat again. It does not mean they will jump into combat right away. It gives them permission to enter combat; it doesn't tell them what to do.
Multiple triggerboxes can link to the same NPC. This way, you can handle the player entering a room from different directions/doorways/etc...
NPCs with the IgnoreCombat flag have a failsafe that will let them enter combat if they are hit. Nonetheless, you should really make sure there's no situation where the player can get to an NPC who is blocked out of combat.
By default, one triggerbox can handle up to 11 NPCs (1 link without a keyword, and then links using LinkCustom01 to LinkCustom10). However, you can extend this by adding additional keywords to the triggerbox's LinkCustomList on the placed reference (do not edit the base object).
"Runner Type" NPCs
This was a special request from Squally and isn't technically a part of the Skywind DMP , but it works pretty similarly to it so I'm putting the guide on it here.
A "Runner Type" NPC has the following behavior.
Wait around sandboxing at either near their editor location, or near a reference linked to with the LinkDefSandbox keyword.
When the player enters a triggerbox (0_dun_ReleaseRunnerTriggerBox), the NPC runs with their weapon drawn to a point linked to without a keyword. This point must be the start of a patrol (looping or back-and-forth).
The NPC begins patrolling, keeping their weapon drawn (as if they were searching for the player).
NPC behavior is affected by the fbmw_DefaultMasterPackageScript when applicable:
What the NPC does while sandboxing (i.e. prior to the trigger)
Whether the NPC has their weapon drawn while sandboxing (it is always drawn once triggered)
Whether the NPC runs or walks while sandboxing and after they reach their patrol (they always run to the patrol)
Whether they ignore combat while sandboxing (when 0_dun_ReleaseRunnerTriggerBox is entered, they will stop ignoring combat)
To set this up:
Make a version of NPC's base object that has the 0DefaultPackageRunnerType package at the top of their package stack. This new base object should be templated on the original, and inherit everything except packages.
Note: Make sure such an NPC hasn't already been made.
Place the NPC(s) where you want them to wait, and optionally link them to an xMarker where you want them to wait, using the LinkDefSandbox keyword on the link.
Link the NPC(s) to an xMarkerHeading or idle marker that you want them to run to.
Link the xMarkerHeading or idle marker to other markers to form a patrol.
Place an instance of 0_dun_ReleaseRunnerTriggerBox where you want the player to trigger the running behavior.
Link the 0_dun_ReleaseRunnerTriggerBox instance to the NPC(s), with no keyword for the first NPC and using the LinkCustom## keywords for any additional NPCs.
Optionally, add any delay to when NPCs are released and if the triggerbox is player-only (this works the same as in the Ignore Combat section).
Optionally, add the fbmw_DefaultMasterPackageScript to the NPC(s) and set any desired flags.
Procedure Tree Details
This section describes the exact hierarchy that the package goes through to determine what behavior to use. The first valid behavior on the list is what the NPC will do.
If the NPC has a linked ref, then:
If the linked ref is an NPC, then:
If the linked NPC is alive: Follow the NPC
If the linked NPC is dead, then: Sandbox* near the NPC (see "Sandboxing Stack", where X = the dead NPC)
If the linked ref has a linked ref: Patrol along the linked ref chain
If the linked ref is a furniture object: Use the furniture
If the linked ref is an idle marker: Use the idle marker
If the linked ref is an XMarkerHeading: Travel to the XMarkerHeading
Else: Sandbox* near the linked ref (see "Sandboxing Stack", where X = the linked ref)
Else: Sandbox* near the NPC's editor location (see "Sandboxing Stack", where X = editor location)
Sandboxing Stack: This is reused several times so I'm only going to write it once. NoSandboxing, NoWandering, and AllowSleeping are encoded in the Variable04 actor value, where AllowSleeping uses Bit 1, NoWandering uses Bit 2, and NoSandbox uses Bit 3. Then:
Where X is some location,
If (NoSandbox==True) AND (NoWandering==True): Stand at X
If (NoSandbox==True): Wander around near X
If (NoWandering==True) AND (AllowSleeping==True): Sandbox near X, with sleeping permitted and with wandering disallowed
If (NoWandering==True): Sandbox near X, with sleeping and wandering both disallowed.
If (AllowSleeping==True): Sandbox near X, with sleeping and wandering both permitted
Else: Sandbox near X, with wandering permitted and with sleeping disallowed