Maxam - Introduction To Encounters

From NWN Lexicon
Jump to: navigation, search

In NWN, there are three ways to place creatures in your module: firstly by selecting them from the creature palette and painting them directly into an area, secondly by setting up an encounter trigger which will "spawn" or create the creatures when a player enters it, thirdly, by writing a script to place the creatures when certain conditions are met.

This tutorial is concerned with the second method.

We will be using two terms frequently, which will be briefly explained here.

Firstly the term "spawn". Spawn is used to refer to any object being created by the NWN engine while a game is running. This could be an object (e.g., a chest or door), but is more likely to be a creature or NPC which is what we will be concerned with in this tutorial. When a creature is "spawned," it will run a script, called an OnSpawn script, and we will be discussing this also.

Secondly, the term "lag". Lag is when, for whatever reason (and there are many), the NWN engine "chokes" or "stutters" and is unable to deliver the optimal silky-smooth gameplay experience we would all like to enjoy. Some lag can be caused by creatures spawning - usually by an encounter and we will be looking at this.

Why Use An Encounter?

At first glance, placing creatures directly from the palette may seem to be the best method for populating a module - after all, creatures are placed and positioned precisely to your liking. Also, building this way closely resembles the way a traditional PnP module would be prepared.

However, there are several key reasons why the use of an encounter is a superior solution to the use of placed creatures:

Encounters can scale to the level of the players

An encounter, for example, may spawn two Goblins for a low level player, or five Bugbears for a higher level player. With placed creatures, those two goblins would remain two goblins, whatever the level of the players going through the area.

Encounters can be used for supernatural appearances or surprise attacks.

Need some wraiths to materialize out of the ether before the players? A small goblin posse to launch a surprise attack from "out of the shadows"? These situations simply cannot be catered for with hand placed creatures.

Encounters lower the processing overhead for NWN

Every creature or NPC in a module saps the resources of NWN by executing a OnHeartbeat script every six seconds - the more creatures, the more heartbeats, the more heartbeats, the slower NWN gets (lag). Admittedly, encounters cause their own form of lag, but it only occurs when they are activated, as opposed to the constant drain of heartbeats. Fortunately there are ways to minimize this, and we will look at this later.

Creating An Encounter

In order to create an encounter, you must first select one from the "Encounter Palette", either from the "Standard" or "Custom" list.

Ideally choose an encounter that is as similar to what you want in terms of creatures and difficulty level as possible. Whilst you can change the encounters properties to achieve the same results, you might as well save yourself a bit of work.

Once you have done this, you create an "Encounter Trigger", by drawing a trigger polygon (multiple sided "area") where you would like the PC to activate the encounter.

This is done by clicking once with the left mouse button for each corner of the polygon, except the last one, which you must double-click. This will tell NWN to close the area (i.e., join the last corner and the first corner).

The encounter trigger can be any size or shape you care to make it - the main thing is to make sure that the players are able to enter it.

If your trigger is not quite the right shape, or you find later that you need to change it, you can do so by right-clicking on it and choosing "Redraw Polygon" from the menu that pops up. Then place the new trigger area in the same way as you placed the old one.

While the trigger is still highlighted, right-click at the location where you would like the trigger to spawn its creatures, and choose "Add Spawn Point".

Right-clicking on the encounter and choosing "Properties" will let you change various settings for the encounter, including the quantity and type of creatures that will appear. We will look at all of the settings you can change under properties in a later section.

Some Important Points

There are some important things to keep in mind when painting encounters in an area:

Trigger Height

You may notice that when you create an encounter trigger that it does not lie flat on the ground (i.e., some of the corners may be higher than the level of the ground). This is because the corner is positioned over something that is higher than the ground, for example a tree or an arch. In most cases this will not be a problem, but it can sometimes cause the toolset to report an error when you try to save and/or exit. If possible, try to make sure that you place all the corners of the trigger area at ground level, and if you accidentally don't, just redraw the trigger area using the "Redraw Polygon" option.

Trigger Placement

Obviously in most cases you will want to place a trigger in such a way that any PCs moving through the area will enter it. In the event that the PCs can approach the trigger from more than one direction (e.g., if you wanted creatures to spawn in the middle of a large room with multiple entrances), just make sure that the trigger area is large enough to cover all the approaches. A common misconception is that an encounter trigger needs to be a fairly small box shape - it can in fact be any size or shape, which is a great aid in situations like this.

Something to consider for modules written with multiple players in mind is that when an encounter trigger fires, it checks the levels of all the members of the party currently in the same area. So, if a trigger is too close to the entrance of an area, it may end up firing based on the first few members of a party who ran ahead and entered the trigger area before the rest of the group arrived.

Encounter Properties

In this chapter, we will examine all of the properties available for an encounter, looking at each tab in sequence.

Basic Tab

Name and Tag

Like everything in NWN, encounters have a "Name" and a "Tag". The "Name" is used to describe this encounter in the "Encounter Palette", the '"Tag" is used to describe the encounter in the "Module Contents" panel. The "Tag" is also how you would refer to the encounter in a script.

Difficulty

This determines how difficult the encounter will be, constrained only by the creatures you have put in the "Creature List". For example, when an encounter is triggered, NWN will weigh up the challenge rating of the creatures in its "Creature List" and the combined level of the PCs, then spawn in an appropriate amount of creatures in an attempt to match the difficulty level you have set. Obviously it will not always be able to do this - if you have only entered creatures with a challenge rating of 6 to 9 in the creature list, setting the encounter to "Very Easy" will never make it possible for level 1 characters, nor will setting it to "Impossible" make it challenging for characters of level 30.

If the level of players in your module is likely to cover a wide range (definitely the case if it is a PW), you will need to make sure that the creatures the encounter spawns cover a broad spectrum of difficulty ("Challenge Rating") - see the Creature List section below for an in depth explanation.

Maximum and Minimum Creatures

This is where you set the limits for the "Maximum Creatures" and "Minimum Creatures" generated by the encounter. The greater the range set here, the easier it is for NWN to scale the difficulty of the encounter.

Spawn Option

There are two settings here - "Single Shot" and "Continuous". "Single Shot" means the encounter will trigger once and once only. "Continuous" means that it can be triggered more than once, although you will need to set additional options in the "Advanced" tab to make it work properly; see below.

Category (For Custom Encounters Only)

"Category" is only available for "Custom Encounters" or when you add a "Standard Encounter" to the "Custom Encounter Palette". It simply indicates where the encounter will be found in the palette (i.e., in the "Hard" section, "Impossible" section, or whatever). Note that this is for your reference only - it has no effect on the actual difficulty of the encounter.

Creature List Tab

The "Creature List" is where you select what monsters or NPCs the encounter will spawn. As mentioned in the Difficulty section above, if the level of players in your module is likely to vary greatly, you need to take care when populating the "Creature List", otherwise NWN will not be able to provide a challenge for the players appropriate to the difficulty level you have set.

For example - let's say you have an encounter which you would like to spawn a scaled mob of ordinary Humanoids (i.e., no Chieftains, Shamans, or Champions). At the most basic level, you could place a Goblin, an Orc, a Bugbear, and an Ogre in the creature list - for a low level party or PC the encounter would probably spawn just Goblins, adding Orcs, Bugbears, and Ogres to the mix for higher level parties, until eventually just spawning all Ogres.

Another, more advanced, method involves making several new creature blueprints with varying difficulty settings of the same creature. For example in the encounter above you could have a normal Goblin (CR .25), a tough Goblin (CR .5), a normal Orc, a tough Orc, etc.

The bottom line is that the greater the variety you give the encounter in terms of Challenge Ratings of the monsters, the easier it will be for NWN to scale the encounter properly.

The "Unique" check box in the list forces NWN to make only one instance of this creature appear (if the difficulty of the encounter warrants its appearance that is!) - this is useful for spawning boss creatures leading groups, or making sure that only one spell caster is spawned in a group of warriors.

However, mixing unique and non-unique creatures in the same encounter can limit the scalability of that encounter. Why? Simply put, placing three "leaders" of varying difficulty all set to unique, will not guarantee that only one them will appear. Depending on the level of the players, the encounter may well spawn all of the "unique" leaders. For example, in the case of the Humanoid mob discussed above, if you wanted a unique leader to appear for the group, you would either have to have a single unique leader that couldn't scale, or you would have to handle the leader with a separate encounter. Refer to the section on Case Studies below.

Finally, it might be a good idea to think about how "realistic" your encounter is (a loosely defined term in a fantasy RPG) when populating your "Creature List". Although you could have an encounter spawn a wide range of creatures from Kobolds to Balors (with Giants, Trolls, Umber Hulks, and more in between), bear in mind that NWN will not spawn a group entirely made of creatures of one type - it will invariably mix it up as best it can. This being the case, it may not be logical in the context of your area or module for such a varied selection of creatures to appear.

Scripts Tab

An encounter has five event handlers that will fire a script - four of which are standard (OnEnter, OnExit, OnHeartbeat, and OnUserDefined), and one which is unique to encounters (OnExhausted). An OnExhausted event is fired when the last creature spawned by the encounter is slain. This can be used to trigger an event such as the opening of a gate, or a cut scene once the encounter group has been defeated.

Advanced Tab

Faction

Like creatures, encounters have a faction. It is important to note that the faction of the encounter in no way determines or changes the faction of the creatures spawned. It only controls whether or not the encounter will spawn when a PC or other creature walks over it.

In order for the encounter to trigger properly, the player must be hostile to the faction of the trigger - the creatures spawned could be hostile, neutral, or even friendly. For this reason most triggers will be set to the "Hostile" faction.

Its worth noting that encounters set to the standard NPC factions (commoner, merchant, and defender) don't seem to trigger for NPCs that are hostile to these factions — they only trigger for PCs and members of their party. However, using a custom faction on the encounter, set up with similar likes and dislikes, should work as expected.

So, for example, you could set a number of encounters with a faction of "Commoner" around a village. When triggered, these encounters would spawn groups of guards to deal with the attackers. These encounters will not be triggered when players wander around the village unless the players have been attacking villagers, thus becoming hostile to the villagers ("Commoner") faction.

Active

Simply put, this needs to be checked for the encounter to work. Possible reasons for setting this to unchecked would be for encounters you wanted to remain dormant until a certain time, and then make active with a script - for example, graveyard encounters that only become active when night falls.

Encounter Respawns

If you have set the "Spawn Option" on the Basic Tab to "Continuous", the "Encounter Respawns" options will be available. Here you will be able to set how frequently the encounter respawns and how often (a limited or infinite number of times).

Note that the "Respawn Time" represents (in seconds) the amount of time NWN takes to make the encounter active again from when the last creature spawned by the encounter is killed.

It is also important to note that, if you set the respawn time to 0 seconds and the triggering PC remains standing within the trigger, it will retrigger immediately once only, after which it needs to be "re-entered" to trigger again. Refer to the {{#Study 2: Continuously Spawning Encounters|Continuously Spawning Encounters]] case study below.

Player Triggered Only

When set, only players can trigger the encounter - otherwise henchmen, familiars, and, occasionally, NPCs can also trigger it. Obviously the latter for the most part is preferable and more realistic although there will be times when it will be more convenient or necessary to set it otherwise.

Comments Tab

This tab usually contains a short description of the encounter's purpose or usage. It has no effect on the operation of the encounter.

Encounter Lag Issues

Even those with the most powerful PCs will notice the tell-tale judder or "lag" that signifies the activation of an encounter trigger. The severity of this can range from a slight hiccup to a lengthy spate of shuddering - apart from the obvious irritation of the delay, it's even more annoying because it gives the player an indication that they are about to be set upon by foes.

While it can never be removed completely, there are certainly ways to lessen it, or even in some cases hide it from players. However, in order to address this issue we must understand what causes it.

There are two main things that cause encounter lag - placing creatures (i.e., when NWN determines where to place them in an area) and spawning creatures (that is, running their OnSpawn script as they are placed in the area).

Placing Creatures

There are some key points to bear in mind if you wish to lessen the lag caused by an encounter triggering:

Spawn points lessen lag

One of the most processor-intensive things you can give an encounter to do is ask it to place creatures when you have not specified one or more spawn points. With no spawn points given, NWN will agonize over the best place to put the creatures, trying as hard as it can to place the creatures "behind" the players (i.e., out of sight), yet close enough so that they are put in combat. This delay is considerably worsened if the players are moving quickly through an area.

Multiple spawn points are better than one

Unless a spawn point is located a long way away from the trigger, it is better to place more than one spawn point. Why? Because if a PC is too close to the spawn point, NWN will ignore it and try to ensure that the creatures appear at least a certain distance from the player. Or to put it another way, if the only spawn point is too close, then NWN will try to place the creatures in the same manner as if there were no spawn points specified at all, leading to the same problem discussed in the point above.

There is no limit to the amount of spawn points you can create, however, as with all things in NWN, the less you give the engine to think about the better.

Spawn points should be in open areas

When spawning creatures, it is important that the spawn point is not too close to walls or other objects as NWN will get bogged down trying to position the creatures legally - this is extremely important if there is more than one creature being placed by the encounter./<p>

Spawning Creatures

When each creature is placed in NWN, whether by an encounter or a script or when the module first loads (for manually placed creatures), they execute an OnSpawn script. The execution of spawn scripts causes lag, although for manually placed creatures this happens when the module first loads and is rarely noticed by the player.

There are ways to minimize the lag caused by spawn scripts:

Streamline spawn scripts
Spawn scripts set up all manner of things for the creature, from various behavior patterns to how much treasure it is carrying. All of this takes time to execute, so reducing the size of the spawn script in any way can help considerably.<p>The best thing to do is have custom on spawn scripts, stripping them down to their bare essentials by commenting out any checks or unwanted behavior, for example, commenting out WalkWayPoints() if the creature is not going to be following a patrol route.

One of the most lag-inducing elements of the spawn script is the section which generates random treasure for a creature. If you can, try to live without this - comment it out and have the creature not carry any treasure, storing it in handy nearby chests or crates, for example. Obviously you will not always want to do this, but you will notice the difference in lag between creatures that generate treasure, and those that don't.

Custom creatures can have a higher processing overhead

If the creatures being placed are from the custom palette, they will, in most cases, add to the lag. This can range from fairly minor to fairly serious.

There are two major customizations you can make to a creature that will incur lag - firstly, customized appearances (i.e., a generic human with different limbs/torso/head selected) and secondly customized equipment (i.e., equipping creatures with weapons, clothing, and accessories which themselves are from the custom items palette).

For example a group of custom orcs that have had their primary stats changed will not add significantly to the lag, but a group of human mercenaries with customized armor, shields, swords, and different heads will definitely add to the lag.

Cache all Spawn Scripts

Next to heartbeat scripts, the most commonly executed scripts in any module are the spawn scripts - fortunately NWN provides the ability to "cache", or store, scripts in memory for faster execution. Cache as many of the spawn scripts as you can - if possible, all of them, but at least the most commonly used ones.

Case Studies

Here we will look at some examples of specific things that you may want to do in a module, and explain how they may be done with encounters.

Study 1: Scaling Unique Leaders

You want to spawning a group of creatures with a unique leader and have the abilities of the leader scale to the level of the PCs. The solution is to have two separate encounters: one for the main group and one for the leader. Ideally you would make the two trigger areas overlap and place the spawn points for both encounters together.

For the group encounter you would need a range of creatures of varying difficulty (e.g., Goblin, Hobgoblin, and Bugbear) and varying quantities (e.g., 4 - 8).

For the boss encounter, create two or more creature blueprints of the leader with increasing levels of toughness (e.g., a Hobgoblin Champion of CR 3, 6, and 9) and place them in the creature list with each one set to unique. Then make sure that the maximum and minimum creatures are both set to one.

Then when the triggers are crossed you will get both a scaled group and a scaled leader spawned in.

Study 2: Continuously Spawning Encounters

An example of a continuously spawning encounter would be to have the guardian of a portal respawn after a certain amount of time, say 10 minutes after it is slain. On the surface, it would appear that the solution to this problem would be to have an encounter trigger covering the whole area, set to continuous and infinite, with a respawn time of 600 seconds. You would expect that as the PCs are present within the trigger (they must be unless they leave the level), the trigger will fire as soon as the respawn time is met. There is however a problem with this, as mentioned earlier (Encounter Respawns, above), an encounter will only respawn once if the PCs remain within the trigger area. After that, the PCs must exit and re-enter the trigger area for it to fire again.

The solution is to stick with an area-wide trigger, but shaped in such a way that the PCs cannot avoid constantly moving in and out of it as they wander around. By necessity, the shape of the trigger will vary depending on the design of your area, but one of the more common ways to do it (particularly in open areas) would be to "stripe" the level with the trigger (i.e., shape the trigger like a comb - the teeth stretching across the area).

Study 3: Permanent Wandering Monsters

To create wandering monsters that are always present in an area, begin by creating one or more creature blueprints for the wandering monster(s) that either have mobile animations set in their OnSpawn script or have a set of waypoints to follow.

Next create the encounter and paint an area-wide trigger in a similar fashion to the trigger discussed in Continuously Spawning Encounters above. Then set up at least two spawn points that are a reasonable distance apart (near a waypoint path if you are using them) and set the encounter to continuous and infinite with a respawn time of 0 seconds.

Take care when drawing the trigger that it does not stray too close to any entrances to the area to avoid scaling issues as discussed in the Creating An Encounter section (under Trigger Placement) above.

Troubleshooting

Here we will look at some common problems people come across when using encounters and address them.

An encounter does nothing when PCs enter it

This is a common problem, and usually indicates that the player is not hostile to the faction of the encounter. Setting the encounter faction to "Hostile" should solve this problem.

Creatures spawned by an encounter do not face the direction of the spawn point arrow

With older versions of NWN, there was a problem of creature spawns always facing east. This has been fixed in more recent versions. Note also that if a creature spawns close enough to a PC, it will appear facing the PC regardless of the direction of its spawn point.

An encounter does not spawn an appropriate amount or type of creature for the party's level

The encounter trigger may be too close to the entrance of the area. When an encounter trigger fires, it checks the levels of all the members of the party which the triggering PC belongs to. However, it only looks at party members currently in the same area.

So, if a trigger is too close to the entrance of an area, chances are it will only end up firing based on the one or two members of a party who ran ahead and entered an area before the rest of their team mates.

Alternatively, you may need to specify a bigger range of creatures in the "Creature List" (different "Challenge Ratings" etc.) to enable the encounter to better match the strength of the party.


 author: Maxam, editor: Grimlar