Tips on Building Encounters

Forum for builders of NWN material.
Post Reply
Mistcaller
Groundling
Posts: 137
Joined: Tue Nov 25, 2003 7:29 am
Location: Avlis Team - Tairis'nadur Team

Tips on Building Encounters

Post by Mistcaller » Thu May 20, 2004 8:47 am

OnExhausted event
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.


Encounter's Faction
Its worth noting that encounters set to the standard npc factions, (commoner, merchant and defender,) don't seem to trigger for npc's that are hostile to these factions, they only trigger for PC's 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.

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 PC's, 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.

Source: NWN Lexicon (http://www.nwnlexicon.com)

Mistcaller
Groundling
Posts: 137
Joined: Tue Nov 25, 2003 7:29 am
Location: Avlis Team - Tairis'nadur Team

Post by Mistcaller » Thu May 20, 2004 8:56 am

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 (ie 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.

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.

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.


Source: NWN Lexicon (http://www.nwnlexicon.com)

Chassagne
Planar Sage
Posts: 73
Joined: Tue Dec 02, 2003 2:38 pm

Post by Chassagne » Thu May 20, 2004 11:15 am

About the OnExhausted event : from what I saw in Hala, it's not always fired when the encounter is exhausted : about 10% - 20% of the time (edit : it is not fired), independant of server load (I also noticed that while I was alone on my test server).

Post Reply