Jump to content

[LE] Hardback book keyword


Recommended Posts

Ahh, I see. Well, there are always workarounds, it just depends on how important including books are to your mod. If you're using ShowGiftMenu on a specific npc, you can set up a quest alias and use OnItemAdded to add books to your list. Something like:

 

Formlist Property MyGiftList auto 


Event OnItemAdded(Form akBaseItem, Int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)
    If akBaseItem as Book 
        If akBaseItem.GetWeight() >= 1
            MyGiftList.AddForm(akBaseItem) 
        Endif 
    Endif 
EndEvent 

If you need to do it on multiple NPC's you can use a function that searches their inventory and adds books to the list, like so:

Event SomeEvent() 
    AddBooksToGiftList(SomeActor, MyGiftList)
EndEvent

Function AddBooksToGiftList(Actor akActor, Formlist GiftList) 
    Int M = akActor.GetNumItems() 
    While M > 0
        M -= 1
        Form CurrentForm = akActor.GetNthForm(M) 
        If CurrentForm as Book
            If CurrentForm.GetWeight() >= 1
                GiftList.AddForm(CurrentForm)
            Endif 
        Endif 
    Endwhile 
EndFunction

Again it's just a matter of how important it is, and whether or not you're willing to use skse.

Edited by dylbill
Link to comment
Share on other sites

The mod already uses SKSE, that's not a problem at all. It'd be cool to make it work :smile:

Apparently my knowledge is lacking quite a bit here (that's why I gave up so easily in my previous post, I didn't know this was possible.). So allow me a quick recap:

 

The player can give the gifts to any NPC. The actual objects eligible as gifts depend on the NPC's class. I'm not happy with the vanilla Gift* formlists, so I made my own, and would like to include books for classes that would be happy if a book was gifted to them (let's stick to Priest for the example).

 

The book is the player's inventory, intended to be gifted to the NPC.

So what you're saying is that something like this could work?

 
Class Property Priest Auto
Formlist Property CustomPriestGiftList Auto  ; In the CK, containing the basic things.
Keyword Property Book  Auto
 
Function GiftingFunctionCalledByMod(Actor akTarget)
 
    ; conditions for checking if actor is a priest and other necessary stuff
 
    ; add books to formlist:
    Int M = Game.GetPlayer().GetNumItems()
    while M > 0
        M -= 1
        Form CurrentForm = Game.GetPlayer().GetNthForm(M) 
        If CurrentForm as Book
            If CurrentForm.GetWeight() >= 1
                CustomPriestGiftList.AddForm(CurrentForm)
            Endif 
        Endif 
    Endwhile 
 
    int points = akTarget.ShowGiftMenu(true, CustomPriestGiftList)
EndFunction

This would be supercool. However, does the Formlist then stay modified forever? Because the player can just decide to give a gift to this NPC again. Based on SKSE's documentation, if a form is already a member of the formlist, calling AddForm on it won't do anything, so I guess it's safe to rely on this functionality, and there's no need to bother with checking if it's been already added or not?

 

 

EDIT:

So Book is not a Keyword, but it is a type, so that property is not necessary. Otherwise, this does indeed work, but it's soooo terribly slow. For my character with 300+ items in its inventory, this loop takes over 10 seconds. That delay is simply too long to be tolerated here :sad: Is there any way to better optimize this code?

 

EDIT2:

I've found a formlist in the CK called DLC1LibraryBookList. This seems to contain most of the books that are actually books, up to Dawnguard (224 in total). Yay, finally that's well close enough :) I'm using the above code in an OnInit() event to add the contents of this list to my formlists, and now it seems to work fine. There certainly are books that are missing, but it's close enough for me. This way also makes sure that books like the Black Books don't show up in the gift menu, which is a plus for this solution.

Unless there's a way to optimize the first approach, I'll stick with this way. Thanks for your help :)

Edited by WhiteWolf424242
Link to comment
Share on other sites

Ah, if it's for the player giving items, I would instead make a new reference alias in a quest that points at the player. Fill type, specific reference, cell any - 'Player'.

 

Then you can use the OnitemAdded event, and only run that function once OnInit. That's correct that formlists can't have the same form twice, so no need to worry about adding forms multiple time. Also, using Game.GetPlayer() every time will slow the function down. So something like this:

 


Formlist Property CustomPriestGiftList Auto  ; In the CK, containing the basic things.
Actor Property PlayerRef Auto 

Event OnInit()
    Int M = PlayerRef.GetNumItems()
    while M > 0
        M -= 1
        Form CurrentForm = PlayerRef.GetNthForm(M) 
        If CurrentForm as Book
            If CurrentForm.GetWeight() >= 1
                CustomPriestGiftList.AddForm(CurrentForm)
            Endif 
        Endif 
    Endwhile 
EndEvent

Event OnItemAdded(Form akBaseItem, Int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)
    If akBaseItem as Book 
        If akBaseItem.GetWeight() >= 1
            CustomPriestGiftList.AddForm(akBaseItem) 
        Endif 
    Endif 
EndEvent

 

You would add all of the lists that you want to include books in.

Edited by dylbill
Link to comment
Share on other sites

Yes and it should extend ReferenceAlias. Another option, if that's still too script intensive is to dump all of the book forms into a formlist in the ck. Then you run a script when the mod is installed using OnInit() that checks their weight and adds them to your gift lists if it's >= 1

 

Formlist Property AllVanillaBooks Auto
Formlist Property CustomPriestGiftList Auto  ; In the CK, containing the basic things.

Event OnInit()
    Int M = AllVanillaBooks.GetSize()
    While M > 0
        M -= 1
        Form BookForm = AllVanillaBooks.GetAt(M) 
        If BookForm.GetWeight() >= 1
            CustomPriestGiftList.AddForm(BookForm) 
        Endif 
    EndWhile 
EndEvent 

This won't account for books added by other mods though.

Link to comment
Share on other sites

After a bit of testing around, I think I'll stick with DLC1LibraryBookList. I've duplicated the list and added a few more select books, and I'm adding their contents to the gift lifts on script init.

Yes, this won't enable books added by mods, but I just find that the other way passes too many books - it includes journals, quest books, black books, stuff that just generally doesn't came across as a nice gift to me. The DLC1LibraryBookList (+my select additions) only contains library books that would make a nice gift.

I don't think that not including mod-added books is a problem, for a similar reason, since those books usually serve the mod's purpose and fall in the someone's journal or quest book category, which I actually want to avoid.

 

Thanks for all your help :)

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...