Delaying Script

Post » Tue Oct 15, 2013 10:35 pm

I have a script that auto-teaches some Alchemy recipes OnRead via an array. It is available to buy but can also be stolen from an Apothecary's bedroom.

I have tested it thoroughly and it works perfectly. It will be flagged as stolen if taken from it's placed location, but because when you pick up non-Spell books you open them first instead of them going into inventory, a thief could put the book back and has learned all the ingredient effects and does not risk getting caught. So he gets something for nothing.

Is there a way to delay the script from triggering until after it's first reading? EG, requiring it to go to inventory first and THEN the OnRead function fires when it is read for a second time AFTER being stolen?

Cheers!

~.~

User avatar
Kelly Tomlinson
 
Posts: 3503
Joined: Sat Jul 08, 2006 11:57 pm

Post » Tue Oct 15, 2013 6:47 pm

So basically set a variable when the book is added to the player's inventory, and then in your OnRead script test that variable and only teach the recipes if it is set?
User avatar
Catharine Krupinski
 
Posts: 3377
Joined: Sun Aug 12, 2007 3:39 pm

Post » Tue Oct 15, 2013 7:28 pm

Does a book that's been picked up for reading count as being in the player's inventory? If not, you could put a PlayerREF.GetItemCount(Book) check in the OnRead event.
User avatar
sally R
 
Posts: 3503
Joined: Mon Sep 25, 2006 10:34 pm

Post » Wed Oct 16, 2013 12:58 am

Cheers. Could you show me an example code for that?

~

User avatar
lucile
 
Posts: 3371
Joined: Thu Mar 22, 2007 4:37 pm

Post » Tue Oct 15, 2013 9:25 am

I really don't know.

~

User avatar
Natalie Taylor
 
Posts: 3301
Joined: Mon Sep 11, 2006 7:54 pm

Post » Tue Oct 15, 2013 4:33 pm

I'll start you off. Maybe it'll spark something and you'll be able to code things like this.

Set up a variable:

Int BookCheckVariable

Find the event for adding an item to the players inventory and then create an event that looks something like this:

On ThatEvent()

BookCheckVariable =1

EndEvent

You'll now need to check if that variable is equal to 1 before you can get the effects of the book. An if statement seems logical. DreamKing suggested the OnRead event. You should look into that in the wiki.

User avatar
Chelsea Head
 
Posts: 3433
Joined: Thu Mar 08, 2007 6:38 am

Post » Tue Oct 15, 2013 11:37 am

So for ThatEvent(), would OnContainerChanged work?

Then in the OnRead section, check with

If BookCheckVariable=1 ?

Thing is, when I have tried to mix scripts with Functions and Events, I get compiler errors. I've never been able to make an Event OnSomething work with a Function OnSomethingElse. I usually get "Too many arguments", but I'll give it a go.

~.~

User avatar
Jacob Phillips
 
Posts: 3430
Joined: Tue Aug 14, 2007 9:46 am

Post » Tue Oct 15, 2013 8:05 pm

Non-Automatic Skill Books adds a dialog box to skill books that allows you to take a book without reading it. You might try to look at its code and remove the messagebox and just have it go to the player's inventory directly. It also puts it directly in your inventory when sneaking.

http://skyrim.nexusmods.com/mods/16463/?

User avatar
Jerry Cox
 
Posts: 3409
Joined: Wed Oct 10, 2007 1:21 pm

Post » Wed Oct 16, 2013 1:01 am

That part works, but when I use If BookCheckVariable = 1 in the Function OnRead section, I get:

"No viable alternative at input 'BookCheckVariable'"

User avatar
Jose ordaz
 
Posts: 3552
Joined: Mon Aug 27, 2007 10:14 pm

Post » Tue Oct 15, 2013 6:15 pm

That is a brilliant idea! I can do message boxes. I'll see if I can make it so the only choice is Pick Up or Leave It.

Like,

"You are about to steal a very expensive book!"

Take It

Leave It

As long as that part only runs once, so if I put it on my Hideout bookcase I don't get that message again next time I pick it up.

Do you know how to make message boxes run only once? Although it would have to be run only once IF it has been picked up.

Cheers!

~.~

User avatar
Dawn Porter
 
Posts: 3449
Joined: Sun Jun 18, 2006 11:17 am

Post » Tue Oct 15, 2013 6:50 pm

I just realized the mod doesn't include its script source file, so here it is

globalvariable property BSBConfig automessage property SkillBookMenu autoactor property PlayerRef autofunction OnActivate(ObjectReference akActionRef)	if BSBConfig.GetValueInt() == 0		self.Activate(PlayerRef as ObjectReference, true)	elseIf BSBConfig.GetValueInt() == 1 && PlayerRef.IsSneaking()		PlayerRef.AddItem(self as form, 1, false)	else		self.SpellBookMenuFunction(true, 0)	endIfendFunctionfunction SpellBookMenuFunction(Bool ShowMenu, Int MenuButton)	while ShowMenu		game.DisablePlayerControls(true, false, true, true, true, false, true, false, 0)		if MenuButton != -1			MenuButton = SkillBookMenu.Show(0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000)			if MenuButton == 0				self.Activate(PlayerRef as ObjectReference, true)				ShowMenu = false			elseIf MenuButton == 1				PlayerRef.AddItem(self as form, 1, false)				ShowMenu = false			elseIf MenuButton == 2				ShowMenu = false			endIf		endIf	endWhile	game.EnablePlayerControls(true, true, true, true, true, true, true, true, 0)endFunctionfunction OnLoad()	self.BlockActivation(true)endFunction

SkillBooksMenu is a messagebox with Read, Take without reading, and Leave book, and BSBConfig is set to 1 by default.

User avatar
Alan Whiston
 
Posts: 3358
Joined: Sun May 06, 2007 4:07 pm


Return to V - Skyrim