How do I get a reference for a book the player has opened?

Post » Sat Nov 17, 2012 9:14 am

Greetings

What I am trying to do is the following: When the player opens any book in the game to start reading it, I want to get a reference for either that book or it's base object.

The only way I currently know of doing this is to attach a script to a book then place my script inside an OnRead event. The problem is that, as far as I know, the OnRead event only works in scripts that are attached to a book, and only when that particular book is read. I would rather not go this route though because I want my script to fire whenever the player reads any book. To accomplish this would require attaching a script to every book in the game, causing massive conflicts for any mod that modifies books.

If anyone can help me with this, I would greatly appreciate it.
User avatar
Charlotte Buckley
 
Posts: 3532
Joined: Fri Oct 27, 2006 11:29 am

Post » Sat Nov 17, 2012 3:39 am

I believe the OnObjectEquipped() event is sent to the player reference when he reads a book. You could use an alias filled by the player that has a script attached that has Event OnObjectEquipped(), check to see if akBaseObject as Book, and then do what you want with the returned Base Object or Object Reference.
User avatar
Alisia Lisha
 
Posts: 3480
Joined: Tue Dec 05, 2006 8:52 pm

Post » Sat Nov 17, 2012 1:58 am

Thank you for the help Chesko

My apologies though but I am still new to scripting with Papyrus. What exactly do you mean by "an alias filled by the player"?

Edit: Would this have anything to do with it: http://www.creationkit.com/Quest_Alias_Tab
User avatar
hannaH
 
Posts: 3513
Joined: Tue Aug 15, 2006 4:50 am

Post » Sat Nov 17, 2012 10:10 am

Yep that's the right place.

1. Make a new quest, give it a name and tick "start game enabled" (or something along those lines). Then click ok, exiting the window, so that the ck generates the rest of the quest window
2. Go back into your quest, navigate to the quest alias tab. Right-click and create a new reference alias.
3. Give it a name. Fill it with the player reference (Cell= (any), Actor= Player). This is where you'll be placing your script. If you cannot see the "ok" button, just click on the name box with your mouse, hold shift and press tab twice, then hit enter

http://www.creationkit.com/Alias some info on what an alias is

- Hypno
User avatar
Anna Watts
 
Posts: 3476
Joined: Sat Jun 17, 2006 8:31 pm

Post » Sat Nov 17, 2012 10:54 am

Thank you Hypno88. That is quite an amazing addition Bethesda made to the modders' arsenal.

As for my problem, the player alias works exactly as advertised. ATM, I've just created a script that pops up message boxes while I test things out. I've discovered a small problem though: the OnObjectEquipped event only fires when I click on a book in my inventory. Reading a book by activating one present in the game world doesn't activate this event (for obvious reasons, I suppose).

The OnObjectEquipped event limitation is workable but I would prefer being able to detect the player "activating" books as well as equipping them. I'm trying to find a solution to this problem but if someone beats me to it, that would be great. One thing I've tried is to create an alias which attaches a script with an OnRead event to all books. Either it doesn't work or I did something wrong though because I couldn't find any books with a script attached via the alias.
User avatar
Dean Ashcroft
 
Posts: 3566
Joined: Wed Jul 25, 2007 1:20 am

Post » Sat Nov 17, 2012 12:57 am

The OnObjectEquipped event limitation is workable but I would prefer being able to detect the player "activating" books as well as equipping them.


These are the same thing. Equip in this case just means "used by the player". This event is also sent by objects of type Potion when consumed, for instance.
User avatar
Thomas LEON
 
Posts: 3420
Joined: Mon Nov 26, 2007 8:01 am

Post » Sat Nov 17, 2012 3:35 am

These are the same thing. Equip in this case just means "used by the player". This event is also sent by objects of type Potion when consumed, for instance.
The OnObjectEquipped event will fire whenever anything in the inventory of the actor with the script attached is equipped. Weapons, armour, potions, books, even miscellaneous items.

In scripting for Bethesda games, Activate and Equip means different things. Activate is when the player points the crosshair at an item in the world and presses the activate command (E by default) or when an NPC does the equivalent action. Equip is when the player opens their inventory and clicks on an item present or when an NPC does the equivalent action. So if you see some armour lying on a table that you want, you would "activate" it to bring it into your inventory then "equip" it to start wearing it.

The problem with books is that the player can read one by equipping one in their inventory as well as by activating it in the game world. In my tests, the OnObjectEquipped event only fires when I click on the book in my inventory. If I activate a book in the game world, nothing happens.
User avatar
kyle pinchen
 
Posts: 3475
Joined: Thu May 17, 2007 9:01 pm

Post » Sat Nov 17, 2012 6:42 am

Ah, that's unfortunate. I haven't tried world object books with this function yet.

Without SKSE I'm not sure of a way. There is no event to arbitrarily detect anything (everything) that the player activates.
User avatar
Sharra Llenos
 
Posts: 3399
Joined: Wed Jan 17, 2007 1:09 pm

Post » Sat Nov 17, 2012 3:22 pm

The problem with books is that the player can read one by equipping one in their inventory as well as by activating it in the game world. In my tests, the OnObjectEquipped event only fires when I click on the book in my inventory. If I activate a book in the game world, nothing happens.

True. It's why reading a book is NOT stealing.

You can use the http://www.creationkit.com/OnRead_-_ObjectReference OnRead Event (in a script attached to the book, or the book alias) which does work (if I remember right) from inventory or just from reading-in-world
User avatar
Lisa
 
Posts: 3473
Joined: Thu Jul 13, 2006 3:57 am

Post » Sat Nov 17, 2012 1:36 pm

You can use the http://www.creationkit.com/OnRead_-_ObjectReference OnRead Event (in a script attached to the book, or the book alias) which does work (if I remember right) from inventory or just from reading-in-world
The OnRead event would be the ideal one for me. As I stated earlier though, I would prefer not attaching scripts directly to the game's books. There are three reasons for this:
My mod would conflict with every other mod that modifies books.
There are a lot of books which means a lot of work to attach a script to all of them
The script won't be able to work on mod-added books

If I could figure out how to create an alias that attaches my script to every book in the game, that would be great. I haven't been successful so far though.
User avatar
lillian luna
 
Posts: 3432
Joined: Thu Aug 31, 2006 9:43 pm

Post » Sat Nov 17, 2012 2:39 pm

The OnRead event would be the ideal one for me. As I stated earlier though, I would prefer not attaching scripts directly to the game's books. There are three reasons for this:
My mod would conflict with every other mod that modifies books.
There are a lot of books which means a lot of work to attach a script to all of them
The script won't be able to work on mod-added books

If I could figure out how to create an alias that attaches my script to every book in the game, that would be great. I haven't been successful so far though.
You can use SPELLS to attach "scripts" dynamically, to npcs or to objects.

There's a tutorial right here: http://www.creationkit.com/Dynamically_Attaching_Scripts

Will then work with any book in the game-world (yours, vanilla, other-modder) ... NOTE: Works better with NPCs than objects, but does work for both ... if you can figure out how to implement for your situation ;)
User avatar
MISS KEEP UR
 
Posts: 3384
Joined: Sat Aug 26, 2006 6:26 am

Post » Sat Nov 17, 2012 4:22 am

@H4vent
Your suggestion is exactly what I needed. I did previously try using an alias to attach a script to nearby books but the tutorial you linked to showed me what I did wrong.

Well, my mod is pretty much finished. I just need to do some testing then I will release it. A big thank you to the three people who helped me get the code written. Also, I think I've now more or less figured out what makes Papyrus tick compared to the old engine's scripting.
User avatar
e.Double
 
Posts: 3318
Joined: Tue Jul 24, 2007 11:17 pm

Post » Sat Nov 17, 2012 7:31 am

I've just uploaded the mod I was working on related to the questions I asked here. The mod is called "Mark Books as Read" and can be downloaded from either http://skyrim.nexusmods.com/mods/20910 or the http://steamcommunity.com/sharedfiles/filedetails/?id=84244648.

Again, a big thank you to the three people who helped to make this mod possible.
User avatar
Sarah MacLeod
 
Posts: 3422
Joined: Tue Nov 07, 2006 1:39 am

Post » Sat Nov 17, 2012 7:57 am

Looks interesting...congrats on the release

- Hypno
User avatar
Beast Attire
 
Posts: 3456
Joined: Tue Oct 09, 2007 5:33 am


Return to V - Skyrim