@Rogue-Novice-1-1 Due to what is needed not being absolutely clear, I have assumed that you want code for a door that will only open if one or another book (or both) is in the PC’s possession. I have also assumed that you are more interested in having something that works (but see later) than in understanding how it actually works. What follows is the simplest (maybe over-simplified) script just in case I am wrong about that. In fact there are actually 2 scripts. Any questions about this don’t be afraid to ask. So you can see it in action I have created a small simple module (in NwN EE) to demonstrate it -
Rogue-Novice-1-1.7z (6.4 KB)
There are 8 jail cells and wide hall (where the PC starts). Each cell has a custom door with the scripts already in place. The 4 Northern cells each have a copy of “All About Cats” which is a custom book placed on the floor. The 4 Southern cells each have a copy of “All About Dogs” which is another custom book placed on the floor. All the books can be picked up by the PC.
The first script goes in the OnOpened event slot under scripts. What it does is first automatically close the door 7 seconds after it has been opened. Half a second later the door locks. This code is taken from the Newbie Scripting FAQ almost as is (I just shortened the time taken).
/////////////////////////////////////////////////////////
// Auto-Close Door / Lock Door
/////////////////////////////////////////////////////////
void main()
{
DelayCommand(7.0f, ActionCloseDoor(OBJECT_SELF));
DelayCommand(7.5f, SetLocked(OBJECT_SELF, TRUE));
}
The other script is the one that unlocks the door only if the PC has at least one of the books in their inventory. Unfortunately, there is a minor problem in that it is not seamless. Because there is no OnClicked event for doors I had to choose the next best event - OnFailToOpen. This means that this code only fires after the PC unsuccessfully tries to open the door. In other words, the PC needs to try a second time in order to open it. There may well be other ways around this but they will be much more complex. To cover this I make the PC speak a short “lock needs oiling” phrase.
/////////////////////////////////////////////////////////
// Auto-Unlock Door Only if they possess one (or both) of 2 books
/////////////////////////////////////////////////////////
void main()
{
object oPC = GetClickingObject(); //who opened the door?
object BookCat;
object BookDog;
int bValidBook;
if(GetIsPC(oPC))
{
BookCat = GetItemPossessedBy(oPC, "Cat"); // has the PC got this book?
BookDog = GetItemPossessedBy(oPC, "Dog"); // has the PC got this book?
bGotValidBook = ((BookCat != OBJECT_INVALID) || (BookDog != OBJECT_INVALID)); // has the PC got either book?
if(bGotValidBook) // see if the PC has gotten either in their possession
{
SetLocked(OBJECT_SELF, FALSE); // if so, unlock the door
AssignCommand(oPC, SpeakString("Oh, I heard the door unlock! The lock must be old and need oiling"); // as this simple code doesn't fire until PC fails to open door first
}
}
}
I repeat, if you have any questions just ask.
BTW, there is a tool that you may well find useful -
LS-TK Script Generator (Lilac Soul’s Script Generator, updated for NWN 1.69)
TR