Jump to content

External file with kist of keywords


Recommended Posts

I would like users of my mod to be able to write a text file with a list of keywords (comma separated, new line - doesn't matter)

that my mod can then create an array or formlist from and use. I've been looking at papyrusutils and also PapyrusINIgetter but it's not clear that they can do what I want.

Currently I have added an array of keywords directly to the mod, but this is in response to a request from just one user, if another user wants a different list then no-go!

Is this familiar to anyone? Any suggestions?

 

dioziet

Link to comment
Share on other sites

Consider writing a script for SSEEdit? It should theoretically be possible. One of my mods has an SSEEdit script that uses three separate text files to associate different types of keywords with various formlists. But don't ask me how to write such a thing. The base code was written for me and I was guided in making small adjustments that I needed.

 

Each user would have to run it for themselves but you could design the mod such that they'd only need to do so if they have other mods present that yours needs to account for but does not already do so.

Link to comment
Share on other sites

You can do this with MiscUtil from PapyrusUtil. It has the function ReadFromFile. I do something similar with my MCM Creator mod. You could tell users to separate keywords with a new line. So the text file would look something like:

 

ActorTypeNPC

ActorTypeCreature

 

Then in the script you can do this:

 

Formlist Property MyKeywords Auto 

Event OnInit() 
    AddKeywordsTolistFromFile(MyKeywords)
EndEvent

Function AddKeywordsTolistFromFile(Formlist akFormlist) 
    String FileContents = MiscUtil.ReadFromFile("data/Mymod/Keywords.txt") ;get entire contents of file
    Int I = 0 
    Int M = StringUtil.GetLength(FileContents) 
    
    While I < M
        Int NextLine = StringUtil.Find(FileContents, "\n", I) ;find next line
        If NextLine == -1
            NextLine = M
        Endif 
        
        String KeyWordName = StringUtil.Substring(FileContents, I, (NextLine - I)) ;get text of current line
        Keyword FileKeyword = Keyword.GetKeyword(KeyWordName) 
        If FileKeyword 
            akFormlist.AddForm(FileKeyword)
        Endif
        
        I = (NextLine + 1) ;check next line.
    EndWhile
EndFunction
Link to comment
Share on other sites

I wonder...? if i can use part of this logic for one of my problems. I haven't dived into it yet, but it's been in my head for around 2 months, and for the moment i'm just processing the idea in my mind.



If anyone has a bone to throw, i'll be glad to pick it up...

Link to comment
Share on other sites

For that, you would need to do some testing. As a simple test, make another esp and make the same keyword in that esp as in your mod. Add the keyword in the extra esp to something and use HasKeyword on it in your mod and see if it returns true. The above I don't think would work because I think the skse function GetKeword would return only 1 keyword form, probably the first it finds in your load order, but I'm just guessing.

 

Also for HasKeyword, I would assume it would only return true for items that have the keyword from your esp, as keywords from another esp, even if they have the same name would have a different formID.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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