Grimlar - Guide To Directional Encounters
Prerequisites
It is assumed that you have a basic understanding of the NWN scripting language and are familiar with the Aurora Toolset, i.e. you know how to place and set up simple encounters, traps doors etc. If this isn't the case, please go and have a look at Celowins scripting tutorials and Bioware's module construction tutorial first.
What's The Problem?
You've probably come across the problem before. Your players have gone round the module / dungeon in a way you didn't plan for and every encounter has spawned its creatures behind the party in an area they know was empty five seconds ago. Once or twice could be explained, having it happen all the time is simply embarrassing...
What you need is an encounter that changes its spawn point depending on which direction the players entered it from.
How Does It Work?
The principle is fairly simple, and the code is straightforward and relatively easy to extend for more than two directions.
For a two-direction single fire encounter, you simply place two ordinary encounters next to each other, separated by a small gap, so that depending on the direction you approach from, you must go through the first encounter to reach the second.
In the small gap between the two encounters place an ordinary trigger. This trigger will be set to delete both encounters when its entered by a PC. As such only one encounter will ever fire.
For a two direction repeat fire encounter you would set things up in the same way as the single fire encounter, the only difference is that instead of deleting the encounters they are deactivated for a certain amount of time.
Examples
The following examples assume that you are working on an area something along the lines of an 4 by 4 Castle Interior with three long corridors joined at both ends. (I.e. a test corridor for each type of encounter and one corridor for moving to and fro without setting anything off.)
Two Direction Single Fire Encounter
1) Place a standard encounter in one of the corridors, say 'Goblinoid Group' found in the 'Very Easy' category of the palette.
2) Change the tag of the encounter to something unique like 'My_Goblinoid1' and make a note of it.
3) Place a second encounter in the same corridor a short distance away from the first encounter. The gap should be about the same width as two characters standing next to each other. Use another encounter from the 'Very Easy' category such as 'Orc, Low Group'.
4) Change the tag of the second encounter to something unique like 'My_OrcLow1' and make a note of it.
5) Place the spawn point for the Goblinoid encounter at the end of the corridor on the other side of the Orc encounter. Likewise for the Orc encounter, place its spawn point at the end of the corridor on the other side of the Goblinoid encounter.
6) Place a 'New Generic' trigger (standard trigger palette, 'Generic Trigger' category,) in the gap between the two encounters, change its tag to 'My_SEnc1' and change its name to 'Single Fire Encounter'.
7) On the 'Scripts' tab, type 'my_senc_oe' in the 'OnEnter' script box and then click on the edit button, click on 'Ok' when it tells you that it will create a new script. In the script editor window that opens type the following code:
void main() { //Only execute when a PC enters the trigger if (GetIsPC(GetEnteringObject())) { //Retrieve the local variables and encounter objects string sEnc1 = GetLocalString(OBJECT_SELF,"Enc1"); string sEnc2 = GetLocalString(OBJECT_SELF,"Enc2"); object oEnc1 = GetObjectByTag(sEnc1); object oEnc2 = GetObjectByTag(sEnc2); //Deactivate the encounters SetEncounterActive(FALSE,oEnc1); SetEncounterActive(FALSE,oEnc2); //Destroy the encounters and the trigger DestroyObject(oEnc1); DestroyObject(oEnc2); DestroyObject(OBJECT_SELF); } }
Once that is done, save and compile the script.
8) On the 'Advanced' tab, click on the '...' button where it says 'Variables', then add two local variables, the first will be a string variable with the Name 'Enc1' and a value of 'My_Goblinoid1'. The second variable will also be a string variable with the name 'Enc2 and a value of 'My_OrcLow1'.
9) Right click on the trigger and select 'Add To Palette' from the pop up menu, on the 'Advanced' properties tab change the blueprint text to read 'singlefireenc' and ok the changes. This will give you a trigger template that can be used to build more single fire encounters simply by changing the tag and the names of the two encounters entered in the variable list.
Two Direction Repeat Fire Encounter
This is a little more complex than the single fire encounter. But is set up in a largely similar manner.
1) Start by creating a new single fire encounter in a different corridor following the steps above. You may wish to use the 'Orc, Low Group' and 'Undead, Low Group' encounters for now, changing their tags to 'My_OrcLow2' and 'My_UndeadLow1' respectively.
2) Change the name of the trigger to 'Repeat Fire Encounter', and the tag to 'My_REnc1'.
3) On the 'Scripts' page enter 'my_renc_oe' in the 'OnEnter' script box and then click on the edit button. In the script editor window that opens type the following code:
void main() { if (GetIsPC(GetEnteringObject())) { //Retrieve the local variables and the encounter objects string sEnc1 = GetLocalString(OBJECT_SELF,"Enc1"); string sEnc2 = GetLocalString(OBJECT_SELF,"Enc2"); object oEnc1 = GetObjectByTag(sEnc1); object oEnc2 = GetObjectByTag(sEnc2); if (GetEncounterActive(oEnc1) && GetEncounterActive(oEnc2)) { object oTrig = OBJECT_SELF; //Set the delay for the number of seconds to wait before //turning the encounters back on. Minimum of 30 seconds. float fSecDelay = GetLocalFloat(OBJECT_SELF,"fSecDelay"); if (fSecDelay<30.0f) { fSecDelay = 30.0f; } DelayCommand(fSecDelay,ExecuteScript("my_resettrig",oTrig)); //Turn both encounters off. SetEncounterActive(FALSE,oEnc1); SetEncounterActive(FALSE,oEnc2); } } }
Once that is done, save and compile the script.
4)Next, open the script editor again, and enter the following code:
void main() { //Retrieve the local variables and the encounter objects string sEnc1 = GetLocalString(OBJECT_SELF,"Enc1"); string sEnc2 = GetLocalString(OBJECT_SELF,"Enc2"); object oEnc1 = GetObjectByTag(sEnc1); object oEnc2 = GetObjectByTag(sEnc2); //Turn the encounters back on SetEncounterActive(TRUE,oEnc1); SetEncounterActive(TRUE,oEnc2); }
Save the script as 'my_resettrig' and compile.
5) On the 'Advanced' tab, click on the '...' button where it says 'Variables', then add three local variables, the first will be a string variable with the Name 'Enc1' and a value of 'My_UndeadLow1'. The second variable will also be a string variable with the name 'Enc2 and a value of 'My_OrcLow2'. The third variable will be a float variable with the name 'fSecDelay' and a value of 60.
9) Right click on the trigger and select 'Add To Palette' from the pop up menu, on the 'Advanced' properties tab change the blueprint text to read 'repeatfireenc' and ok the changes.. This will give you a trigger template that can be used to build more repeat fire encounters simply by changing the tag and the names of the two encounters entered in the variable list.
Notes
Leave the encounters as single fire encounters, even for the repeat fire encounter. The continuous fire encounter is supposed to generate a different kind of encounter, wave after wave of baddies, but it can be difficult to deactivate unless all the creatures have been killed.
'fSecDelay' controls how long it takes for the encounters to get turned back on, and should always be some reasonable length of time such as 60 seconds. The reason for the minimum delay time of 30 seconds is that very small delays such as 0 can hang your computer.
Don't be surprised if, when you enter your value of 60 for the fSecDelay variable, it turns it into something like 59.9999 etc. Floating point variables are notoriously prone to rounding errors, and this one can be safely ignored.
If you find you get both groups of encounter creatures spawned in when you try this you have probably made either the central trigger or the encounter area's too small. Always try to err on the side of caution and go for larger areas if you can.
A demonstration module is available from here.
author: Grimlar, editor: Charles Feduke