Jump to content

[Solved] [Papyrus] How to add entries to a formlist in papyrus ?


worik

Recommended Posts

Problem 1:

I have a formlist which contains keywords.

I am looking for a way how I could extend add more keywords to that formlist and do this by a script. (opposed to: click it in the CK)

I am pretty sure there is a way, though I havent found it yet by looking through other mods as examples.

 

An example or a pointer to a mod with sources would be nice.

 

Problem 2:

I want to extend add keyword to this formlist that were defined in another mod. But I don't want the hard dependency and don't want to have the other mod as a mandatory master.

So basically I have only the other mod's IDs and the keywords to operate with.

Again the question how I could do this in a Papyrus script.

 

Practical background for what I would like to use it: (just for the interested ones, thus in spoilers)

Spoiler

I am creating a mod with NPCs and shops and with the intention of selling stuff, including stuff from LL mods.

 

Now, to have the merchant selling only the right merchandise, I created a formlist with the vanilla stuff that should be for sale, too.

 

But I would like to have these naughty merchants to be flexibly reacting to install LL mods. Detecting the other mods and triggering optional routines if detected is fine with me.

What I don't understand yet is this keyword thing in papyrus.

If I hard-depend on the other LL mods, I can simply add their keywords to my formlist and be done with it.

But that's contradicting my wish for flexibility.

 

Example:

Being Female adds contraception potions, and has a nice keyword for it.

Adding this keyword hard-depending into my merchant formlist works perfectly.

But how would I add a thing like


{0x00BA3A, _FWContraceptionItem}

to my merchant's formlist without that hard dependency ?

 

Edit: 20191124 corrected my bad title :blush:

Link to comment

First of all be careful with the word "extends". You do not "extend" a formlist by adding forms to it. Extending a formlist would be creating a script that inherits from formlist, like so:

 

Quote

Scriptname MyScript extends FormList

 

With that out of the way, have you looked at the SLAdventures_DLCAndModCompScript from Sexlab Adventures? It loads forms from mods and, among other things, adds them to formlists (see the functions LoadFormsDawnguard() and LoadFormsDragonborn()). Not with keywords, but it works exactly the same for those. 

Link to comment
2 hours ago, worik said:

a keyword that is to be derived by strings only (ID+name) in problem 2.

https://www.creationkit.com/index.php?title=Keyword_Script

https://www.creationkit.com/index.php?title=FormList_Script

Google is your friend.

 

There are two functions of note in the Keyword script, one that gets a keyword from a string, one that gets the string name from a keyword.

 

To add to a form list, you just use AddForm. Nothing unusual.

 

 

That said, if you can use arrays and StorageUtil / JsonUtil instead, it's generally more flexible and more performant.

 

StorageUtil has have set-like, or array-like behaviour, while FormList has only set-like behaviour; the forms in a FormList must be unique, you cannot have duplicates.

 

Sometimes this is not what you want. Sometimes, it is.

 

; Add a keyword to a FormList by name.

; Returns true if it managed to add the keyword.

; Requires SKSE.

Bool Function AddKeywordToFormListByName(string name, FormList targetList)

    Keyword theKeyword = Keyword.GetKeyword(name)

    If theKeyword

        targetList.AddForm(theKeyword)

        Return true

    EndIf

    Return false

EndFunction

 

I haven't checked that with a compiler, but I think that's what you mean?

 

And as Teutonic so rightly points out, when you say "extend" you could mean as in "inheritance".

It would be more clear to say that you wish to "add to" a form list.

Link to comment
1 hour ago, Teutonic said:

You do not "extend" a formlist by adding forms to it.

35 minutes ago, Lupine00 said:

It would be more clear to say that you wish to "add to" a form list.

:classic_blush::classic_laugh: Thank you both! Yes,  "adding" is the right wording. By first glance your examples look like the right pointers that I was looking for :classic_happy:?:wine:

 

Link to comment

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

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

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. For more information, see our Privacy Policy & Terms of Use