Thursday, February 23, 2012

Tutorial: Readable Spell Tomes

Object: To make spell tomes readable, instead of losing them when the spell is learned.

Difficulty: Easy-Moderate (involves script editing)
[edit] It appears that modifying the spell tomes causes conflicts with the vendors lists with Crash To Desktop whenever the spell tomes are hovered in the lists. Hence another solution will have to be figured out but the tutorial is still interesting to approach the functions of spell tomes and scripting.

Time Needed: Less than 5 minutes

Things you will need:

  • Creation Kit. The Creation Kit is the modding tool for Skyrim and can be downloaded for free on Steam.
  • Some previous experience with item-editing, and (preferably) script editing
Note: The scripting part of this tutorial is a one-time ordeal. After the script has been made, you will simply need to add it to each book that you want to apply it to, rather than creating a new script for each item. For users of the Readable Spell Tomes mod on the Nexus and the Workshop, you can skip to step 8.

Download: To download the Readable Spell Tomes mod, visit the:
Steam Workshop at:  http://steamcommunity.com/sharedfiles/filedetails/?id=13474
Nexus at: http://skyrim.nexusmods.com/downloads/file.php?id=10954

1. Open the Creation Kit and load the appropriate Data Files.
2. Open the 'Gameplay' Menu and click 'Papyrus Script Manager.'

3. Right-click in the Script Manager, and click 'New.' This allows you to create a new script.
4. Name your new script "SpellTomeReadScript". This is not a required name, but it is simple and easy to find when you search for it later. Also, type "ObjectReference" into the Extends text box. It MUST be "ObjectReference" and NOTHING else.

5. Click OK, and type/copy the following into the editor that pops up:


Scriptname SpellTomeReadScript extends ObjectReference  
{Adds spell to player on equip}

Event OnEquipped(Actor reader)
if (Game.GetPlayer().HasSpell(SpellLearned))
Debug.Notification("You already know this spell.")
endIf
Game.GetPlayer().AddSpell(SpellLearned)
EndEvent

Note that the first time you open a script you may need to tell Windows which program it should use to open the script file. If so, choose a program like Notepad (or Notepad++ if you have it) in the list Windows proposes.

6. Don't worry about the last line that you see in the image above. That is added in automatically by the CK when you add the script to an item later in the tutorial. (nox.fox: personnaly I had to add this last line to compile the script successfully)
7. Save the script. Right click on the script in the Script Manager, and click 'Compile'. Click on your script in the box that pops up. If the box disappears, then the script was compiled successfully and no errors were found. If it says that there was an error, then something in the script was typed incorrectly.
8. In the Object Window, navigate to the Items > Books category, and find the Spell Tome that you want to modify.
9. Double-click on the book to edit it. The first thing you must do is to deactivate the standard option of teaching a spell. On the left side of the Book window, there should be a 'Teaches' section, and then two options. For a spell-tome, the 'Spell' option should be filled, and the appropriate spell should already be selected in the drop-down menu. Open the drop-done menu, scroll to the top, and click NONE. This deactivates the spell-teaching, so that we can use the SpellTomeReadScript instead.
10. Now click 'Add' in the Scripts section of the Book window. A window should pop up that lists all of the scripts. Find the 'SpellTomeReadScript' and click OK.

11. In the Scripts section of the Book Window, select the 'SpellTomeReadScript' and click 'Properties.'
12. Click Add Property in the window that pops up.
13. Select SPELL from the drop-down menu in the new window, and type "SpellLearned" in the 'Name' text box.
14. Click OK. Select your new property, and click 'Edit Value'.
15. Select the spell that you want to add to the player from the drop-down menu, and click 'OK.
16. The script should be added correctly to the item. Save the mod, and test the spell tome ingame.
17. To make other spell tomes readable, repeat steps 9-15 for the spell tome or book that you want to modify.

Notes/Possible Bugs:

1. Note: This process can be used on any book to have it teach a spell without being destroyed.
2. If you have tested your book out, and it is not working, then go back over the tutorial carefully and make sure that everything was typed in correctly and that you disabled the standard method of making books teach a spell.


Feedback:

If you have any comments/questions, or would like to request a tutorial, then please feel free to leave a comment. I will answer your question as quick as I can. If you request a tutorial, I'll let you know when/if you should expect your request to be fulfilled.

19 comments:

  1. Did you ever find a solution to the vendor list crash?

    ReplyDelete
    Replies
    1. I didn't investigate it further, but I think it might possible to work around the issue through scripting with the Event OnRead() command to add the spell to the player instead of Event OnEquipped(Actor reader).
      I haven't tested this out, and it might take to alter the script shown in this tutorial some more, but I think it's possible to figure out what commands to use on creationkit.com =)

      Delete
    2. Right.. This doesn't work, what you told us to type is different from the picture example.. It won't compile

      Delete
    3. Scriptname SpellTomeReadScript extends ObjectReference
      {Adds spell to player on equip}

      Event OnEquipped(Actor reader)
      ;adds spell to player
      if (Game.GetPlayer().AddSpell(SpellLearned))
      endIf
      EndEvent



      What did I do wrong??

      Delete
    4. The Nexus link is an .esp? Why upload it as an .esp? (Also didn't work)

      Delete
    5. This tutorial is pretty old and the CK has been updated a lot since. The bug you encounter may or may not be related to one of the most recent updates that puts all the source scripts in an archive. I can't guarantee that it is the cause but just in case I'd suggest checking this:
      https://steamcommunity.com/app/72850/discussions/0/611702631221612646/

      Fucking CK updates driving everybody crazy.
      When a tutorial says "this works" and it turns out it doesn't, you can bet it's because of an update.
      Take good note though, that it says in this tutorial's beginning that the method presented in it was known to cause CTD when the spell tomes were hovered in the vendor lists.

      Delete
  2. Thanks for the reply buddy. I'm sure we will figure it out xD

    ReplyDelete
    Replies
    1. You're welcome! Don't hesitate to keep us updated on your progress :D

      Delete
  3. This comment has been removed by the author.

    ReplyDelete
  4. he spell tome in question is a custom book.. Necronomicon, it has nice illustrations, that's why i wanted to keep the book after learning "advanced dead thrall" :) so no chance of the book being in a vendor list xD

    ReplyDelete
    Replies
    1. Haha, sure then! Though, careful not to hover it if you have it in your inventory while trying to sell books! Another solution to that would be to have the script remove the spell tome and replace it by a simple book version (it would make a "Necronomicon added" notification tho)

      Delete
  5. I have no idea how to even try that xD Could you help me good sir, to whip up a tasty script? :D

    ReplyDelete
  6. I'm not sure what you mean by "hover"? The Necronomicon did alot of that in the films o:

    ReplyDelete
  7. I have a script that adds a dummy key to a misc item, so a vendor can have it in his inv, then you buy the key, and it turns into a real key? sounds a bit like

    ReplyDelete
  8. Scriptname PM_Script_BuyKey extends ObjectReference
    {Allows you to add a misc object version of a key into a merchant's container and then purchase it.

    This script then swaps the misc item for the actual key.}

    ;PLEASE KEEP THIS CREDIT LNE IN YOUR SCRIPT IF USED
    ;Original universal script created by Darkfox127
    ;Any potential problems which may arise from this script being changed from the original are the sole responsibility of the mod author making the changes.



    Key Property NewKey Auto
    {The key you want to be added to the player upon purchase of this misc item version.}

    MiscObject Property DeadKey Auto
    {This needs to state itself as a reference as removing self does not work.}

    ObjectReference Property PlayerREF Auto
    {The reference for the player.

    Property is auto-filed.}



    Event OnContainerChanged(ObjectReference akNewContainer, ObjectReference akOldContainer)

    If akNewContainer == PlayerREF
    PlayerREF.RemoveItem(DeadKey, 1, True)
    PlayerREF.AddItem(NewKey, 1, True)
    EndIf

    EndEvent

    ReplyDelete
  9. Any help would be much appreciated :)

    ReplyDelete
    Replies
    1. Darkfox127 is an excellent reference for scripts, and this does sound like a good walkaround! I wouldn't have been capable to script anything if not for his tutorials. I'm afraid I wouldn't be able to help a lot more though, as I haven't scripted much anything for about 2 years, due to being kept very busy by comics to draw and a house to renovate ; u ; Doesn't help that each time I try to get back to modding I first have to figure out what new bugs are caused by the CK updates and how to solve them!

      Delete
    2. Stoopid CK :|

      Well I have finally found a way to add a spell to a readable book! (without the book being destroyed ofc) xD



      Scriptname MyBook_AddSpellScript extends ObjectReference

      SPELL Property mySpell Auto

      Event OnRead()
      Actor PlayerREF = Game.GetPlayer()

      If (PlayerREF.HasSpell(mySpell)!=true)
      PlayerREF.AddSpell(mySpell, true)
      EndIf
      EndEvent

      Delete
    3. Great! Congrats on this and thank you for sharing! If I have some time for this later on, would you mind if I add your script in the tutorial with credits to you? :)

      Delete