Read book, get key

Post » Sat May 28, 2011 9:23 pm

Ok... so what I want to do is... when the player reads a book, a key is placed in their inventory at that moment. I can make the key be given, but then the book becomes unreadable.

This is the script in its current form:
scriptname ****Keybegin OnActivateif ( getIsReference ****JournalRef >= )  endifendShort controlvarBegin OnActivateIf ( controlvar == 0 )Ref MyItemShort countset MyItem to ****Keyset count to 1player.additem MyItem CountSet controlvar to 1  EndIfend

User avatar
Daniel Holgate
 
Posts: 3538
Joined: Tue May 29, 2007 1:02 am

Post » Sat May 28, 2011 10:12 pm

Ok... so what I want to do is... when the player reads a book, a key is placed in their inventory at that moment. I can make the key be given, but then the book becomes unreadable.

This is the script in its current form:
scriptname ****Keybegin OnActivateif ( getIsReference ****JournalRef >= )  endifendShort controlvarBegin OnActivateIf ( controlvar == 0 )Ref MyItemShort countset MyItem to ****Keyset count to 1player.additem MyItem CountSet controlvar to 1  EndIfend



It should be fairly simple, if I recall correctly.
All you have to do is call "activate" somewhere in your OnActivate block, so it does not break the actual activation sequence and your book will open.
I only hope the code above is pseudo-code, because in a real script 2 OnActivate blocks at the same time likely won't work.
User avatar
Claire Mclaughlin
 
Posts: 3361
Joined: Mon Jul 31, 2006 6:55 am

Post » Sat May 28, 2011 9:34 am

Hmm, I got it to work by shedding it down to:
scriptname ****KeyBegin OnActivategetIsReference ****JournalRefactivateRef MyItemShort countset MyItem to ****Keyset count to 1player.additem MyItem Countend

It spouts out the key each time you read it though. I had to remove the code that only gave the key once because it made it so that you could only read the book once. :yawn:
User avatar
Dean Ashcroft
 
Posts: 3566
Joined: Wed Jul 25, 2007 1:20 am

Post » Sat May 28, 2011 10:04 am

ScriptName xxxScript ; attach this script to the book - preferably xxx is the name of the bookShort countBegin onactivate    Activate    If (count == 0 ) ; did I already do this?        Set count to 1        Player.AddItem  yyyKey 1 : yyyKey is the formid of the key   EndifEnd

No need for any ref variables and the count is how many times you gave the player the key - which you want to stop at 1! - not the number to give this time. Note that the "Activate" is outside the if, because you always want to do this. Giving the key is inside a test to see if you already gave it.

The position of the Activate before or after the if is not important here, but if you added a SetStage to update the Journal when the player gets the key, then the order of the commands becomes more important, as you may want one thing to display on top of the other.
User avatar
Adam
 
Posts: 3446
Joined: Sat Jun 02, 2007 2:56 pm

Post » Sat May 28, 2011 8:35 am

Thanks, I just implemented that, I'll test it in a bit.
By the way, it doesn't need a journal update because it's just an easter egg.
User avatar
Chica Cheve
 
Posts: 3411
Joined: Sun Aug 27, 2006 10:42 pm

Post » Sat May 28, 2011 3:00 pm

Err... ok, that script doesn't work at all.

Edit: I have made fire!
scriptname ****KeyShort countBegin onactivate    Activate    If (count == 0 ) ;        Set count to 1getIsReference ****JournalRefRef MyItemShort countset MyItem to ****Keyset count to 1player.additem MyItem Count   EndifEnd

This script does exactly what I'm looking for. Read the book for the first time, a key falls out. Read it again, no key. Yay.
User avatar
BlackaneseB
 
Posts: 3431
Joined: Sat Sep 23, 2006 1:21 am


Return to IV - Oblivion