Jump to content

How can I automatize keywords adding


alexalexalex11314

Recommended Posts

Special Edition only

 

Is there any software or CK-function or something which could help me with adding kewords to some items?

For Ex, if there is an item and it has two keywords: ArmorGauntlets and ArmorHeavy, can I add my own keyword somehow to ALL the items with those keywords at one time?

 

 

I really don't want to add keywords all night long, especially one item by one. And another night again, one by one, if something changes.

 

As I understand, there is a similar function in SSE edit, but I'm not shure and couldn't figure it out how it works. Is there is something like that you know, tell me please.

Link to comment
Share on other sites

There might be a way via adding a script that fires from a quest that is hidden that runs once at the beginning of the game and applies the keyword to any item with the qualifying keyword, which if that's possible would work with mods that include items using your qualifying keyword. check www.creationkit.com for some tutorials if you need.

 

Mind you, that means in CK the items won't have your keyword, but in game it gets added while the game is running.

Link to comment
Share on other sites

  • 1 year later...

Keywords can't be added via script, they can only be added via CK and they are immutable. There is a workaround where you can create a form list with your keyword and then use script to add the form list, not sure if that would work in your situation.

I am also looking for a way to add a keyword (or two) two a whole slew of Armor items, to do it manually is... well, not gonna happen, I want to play Skyrim not Creation Kit.

You can add a Keyword via SSEEdit which would be faster than using the CK (even with the CK optimisations) but it's still means doing each item one at a time.

I'm looking for a way to script it in SSEEdit, will post an update if I find a solution.

Link to comment
Share on other sites

Well that was easier than I thought, took a while to figure out Pascal again, it's been a long time since I coded with that.

There is already a script to add keywords in SEEdit, it adds keywords to weapons though, so a bit of tweaking is required.

Then all you need to do is select the armor you want to change (you can shift click to select more than one) and then apply script.

At the top you need to edit this line to add the formid of the keyword you want to add.

slKeywords.Add('0006BBE8');

The only other change is the filter on signature

if Signature(e) <> 'WEAP' then

needs to change to

if Signature(e) <> 'ARMO' then

Although the filter is only needed if you apply the script to an entire esm instead of just selecting the items you want.

 

I have included the script in case you don't have it in your SEEdit for some reason.

{
  This script will add keywords to the keywords list of selected armor.
  Almost no practical use, just a demo.
}
unit UserScript;

var
  slKeywords: TStringList;

function Initialize: integer;
begin
  // keywords to add
  slKeywords := TStringList.Create;
  slKeywords.Add('0006BBE8'); // ArmorClothing [KYWD:0006BBE8]
  //slKeywords.Add('0008F958'); // VendorItemWeapon
  // instead can also load keywords from a text file (one keyword per line)
  // ProgramPath - path were xEdit exe file is
  // DataPath    - path to game's Data folder
  // slKeywords.LoadFromFile(ProgramPath + 'keywords.txt');
end;
    
function Process(e: IInterface): integer;
var
  kwda, k: IInterface;
  i, j: integer;
  exists: boolean;
begin
  Result := 0;

  // apply only to weapons
  if Signature(e) <> 'ARMO' then
    Exit;

  // get existing keywords list or add a new
  kwda := ElementBySignature(e, 'KWDA');
  if not Assigned(kwda) then
    kwda := Add(e, 'KWDA', True);
    
  // no keywords subrecord (it must exist) - terminate script
  if not Assigned(kwda) then begin
    AddMessage('No keywords subrecord in ' + Name(e));
    Result := 1;
    Exit;
  end;

  // iterate through additional keywords
  for i := 0 to slKeywords.Count - 1 do begin
  
    // check if our keyword already exists
    exists := false;
    for j := 0 to ElementCount(kwda) - 1 do
      if IntToHex(GetNativeValue(ElementByIndex(kwda, j)), 8) = slKeywords[i] then begin
        exists := true;
        Break;
      end;
    
    // skip the rest of code in loop if keyword exists
    if exists then Continue;
    
    // CK likes to save empty KWDA with only a single NULL form, use it if so
    if (ElementCount(kwda) = 1) and (GetNativeValue(ElementByIndex(kwda, 0)) = 0) then
      SetEditValue(ElementByIndex(kwda, 0), slKeywords[i])
    else begin
      // add a new keyword at the end of list
      // container, index, element, aOnlySK
      k := ElementAssign(kwda, HighInteger, nil, False);
      if not Assigned(k) then begin
        AddMessage('Can''t add keyword to ' + Name(e));
        Exit;
      end;
      SetEditValue(k, slKeywords[i]);
    end;
  
  end;
  
  // update KSIZ keywords count
  if not ElementExists(e, 'KSIZ') then
    Add(e, 'KSIZ', True);
  SetElementNativeValues(e, 'KSIZ', ElementCount(kwda));
  
  AddMessage('Processed: ' + Name(e));

end;

function Finalize: integer;
begin
  slKeywords.Free;
end;

end.

Despite the original authors comment about it not having any practical purposes it turns out it did, at least for me.

Edited by LordWabbit2
Link to comment
Share on other sites

  • 2 weeks later...

Well that was easier than I thought, took a while to figure out Pascal again, it's been a long time since I coded with that.

There is already a script to add keywords in SEEdit, it adds keywords to weapons though, so a bit of tweaking is required.

Then all you need to do is select the armor you want to change (you can shift click to select more than one) and then apply script.

 

By the gawds, thank you. This was exactly what I've been looking for.

Link to comment
Share on other sites

  • 3 months later...

Well that was easier than I thought, took a while to figure out Pascal again, it's been a long time since I coded with that.

There is already a script to add keywords in SEEdit, it adds keywords to weapons though, so a bit of tweaking is required.

Then all you need to do is select the armor you want to change (you can shift click to select more than one) and then apply script.

Thank you very much for this solution and script! Helped me solve a similar problem.

Link to comment
Share on other sites

  • 6 months later...

Hey, just wanted to add that this is possible to do with papyrus as well if you're willing to use SKSE and Papyrus Extender. https://www.nexusmods.com/skyrimspecialedition/mods/22854

 

Papyrus Extender has the function

AddKeywordToForm(Form akForm, Keyword akKeyword) global native. 

The GameData script from SKSE has the function

GetAllArmor(string modName, Keyword[] keywords = None, bool playable = true, bool ignoreTemplates = true, bool ignoreEnchantments = true, bool onlyEnchanted = false, bool ignoreSkin = true) global native

So you could do something like this on a quest that's start game enabled:

 

Scriptname TM_AddKeywordsScript extends Quest 

Keyword Property ArmorGauntlets Auto 
Keyword Property ArmorHeavy Auto 
Keyword Property MyKeyword auto 

Event OnInit() 
    
    Keyword[] ArmorKeywords = New Keyword[2] 
    ArmorKeywords[0] = ArmorGauntlets
    ArmorKeywords[1] = ArmorHeavy
    
    Int ModCount = Game.GetModCount() 
    Int I = 0 
    While I < ModCount 
        String ModName = Game.GetModName(I) 
        Form[] ModArmors = GameData.GetAllArmor(ModName, ArmorKeywords, True, False, False, False, false) 
        Int L = ModArmors.Length 
        ;Utility.Wait(0.1)
        Int IA = 0 
        While IA < L
            PO3_SKSEFunctions.AddKeywordToForm(ModArmors[IA], MyKeyword) 
            IA += 1
        EndWhile 
        I += 1 
    EndWhile
    Self.Stop() ;Stop this quest
EndEvent
Link to comment
Share on other sites

  • Recently Browsing   0 members

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