Jump to content

Script to find all items with a given keyword (KYWD)?


taleden

Recommended Posts

In a papyrus script, what's the easiest way to find all FormIDs of a certain type (say, ARMO) which have a certain keyword (say, KYWD 0006BBE3 "ArmorMaterialIron"?

 

I'm trying to extend a mod which modifies sets of items, but it does this by hardcoding Form ID Lists (FLST) of the appropriate items (i.e. Iron Cuirass, Iron Helmet, etc). I'm trying to find a way to make it automatically support mods that add new armors or weapons, so I thought maybe I can just search for the material keywords instead. I don't necessarily mind iterating every single armor and weapon, since I'll only have to do it once per session and then I can store the lists of FormIDs for later -- I just want to be able to do it in a script rather than hardcoded ID lists so that it can pick up any items added by other mods, even if their load order is later.

 

Thanks for any suggestions! I'm just getting into Skyrim modding so apologies if this is documented somewhere, I wasn't able to find it.

Link to comment
Share on other sites

Have you looked at the GetFormFromFile function?

 

I did see that, but I don't think it will do what I want. The problem is that I don't know the FormIDs ahead of time, I only know the type (like ARMO) and a keyword (like ArmorMaterialIron) and I want to find every matching form that's loaded in memory -- no matter if it's an original from Skyrim.esm (like Iron Cuirass) or something added by a mod (like Iron Mask).

 

The closest I can think is to use Game.GetForm() in a loop with every possible ID number, and then for the ones that return something, check their type and keywords. Since it looks like the first two hex digits of a FormID are its mod load order, this would mean 16.7million (16^6) tests per mod (assuming there's some way to know how many mods are loaded in total). This is clearly crazy, but.. might be crazy enough to work. I'm not sure how long it would take but if it's under a minute it might be doable; I only really have to do the scan once when the mod first loads and then store the results, so it doesn't ever have to be done again for that save file (except by user request, like if they load a new mod that adds weapons or armors).

 

Another alternative I've been imagining is to start with hardcoded lists of the relevant items from the base game, and then add event hooks to catch new items to add to the lists during play. If I can trigger whenever the player gains any item and whenever the player opens a merchant dialog -- and if there's some way to scan the items the merchant is offering when that dialog opens -- then I could quickly add new matches (like Iron Mask) at those points.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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