0 of 0

File information

Last updated

Original upload

Created by

Kevin Fitzgerald

Uploaded by

Keukotis

Virus scan

Safe to use

17 comments

  1. Keukotis
    Keukotis
    • supporter
    • 213 kudos
    Sticky
    I had a detailed write-up on exactly how this works, but it was long and I figured no one would want to read it. Your questions made me realize that, yeah, maybe some of you do want full details, so I've now written up... just all of it. All of the information.

    Fallout 4 Systems
    First, I need to explain the existing legendary spawning process (for random legendaries - the named legendary items that you find in shops are called "aspirational" internally and are handled separately when the game starts). I mention in the description that it's way different from the one in Starfield, because it is. Starfield has a built-in system for doing this. In Fallout 4 though, this is all handled by a script that runs on every legendary actor (Fallout NV and older Bethesda games had separate record types for NPCs and creatures, but in Skyrim and later they are all actor records). When randomized actors spawn, if their race record has a keyword for allowing legendaries, then there's a chance that they will spawn as a legendary. The script watches for that and when it sees a legendary actor, it creates an item at that actor's feet based on a list of acceptable items they could carry (which appears to be unused in the base game, so it'll just spawn any weapon or armor appropriate for the player's level). It will then iterate through all legendary effects that could potentially be applied to that weapon that aren't already in its list. If it can't find a legendary effect to apply (because no more exist or because nothing else in the list can be applied to that item), it clears the list and tries again from the pool of all legendary effects. Once it has an effect chosen, it applies the effect, adds the effect to the list, and puts the item into the actor's inventory (yes, up until this point the item really is sitting at the actor's feet, which was funny to watch when I tested this). Finally, it marks the actor as having spawned a legendary item so nothing can mess up and spawn another one. This last step is important because the whole process is slow and we don't want stuff to accidentally trigger twice. The slow speed and limit of 1 will present some limitations for me later.

    I should also cover the existing vendor system. Vendors work by container. There is a container hidden, usually down in the floor (you can see it using the TCL console command), that holds all of the randomized inventory for the vendor to stock. That randomization is handled by LeveledItem records, which give chances for different things to spawn based usually on Player level (but sometimes other stuff). Nearly every vendor container has several LeveledItem lists, some of which are marked as Use All. Think of LeveledItem records as "quantum items" if you want: when they aren't observed, they could be anything in the list. But when the Player enters the cell where a LeveledItem record exists, the LeveledItem will collapse into a single one of the items in its list. If Use All is marked though, it will collapse into a single one of every item in its list. LeveledItems with Use All usually contain other LeveledItem records, and thus they're a great way to build general stock lists for placing in multiple vendor containers. Remember how "there's a chance" for an actor to be legendary? That's handled by the similar LeveledActor record. LeveledItem, LeveledActor, and LeveledSpell are responsible for most of the randomization in the game world. LeveledLists will respawn when the vendor container respawns, and each time they do, they'll reroll all of their items and chances based on Player level at the time of respawn.

    Okay, now that we understand the existing systems, we know what needs to be done: get the existing legendary item system to interact with the LeveledItem records that vendor containers carry. That's where this mod comes in.
    1. Keukotis
      Keukotis
      • supporter
      • 213 kudos
      Legendary Vendors
      I started by creating an item and attaching a script that runs when the item spawns. If the item has an owning container, the script will tell the normal legendary spawning process to run on the owning container. This worked, but was unreliable when attempting to add multiple legendary items. Remember: the container gets marked when the process finishes so that it can't spawn another legendary item. The process is also unpredictably slow; it might take half a second, it might take 3 seconds. If I add 5 Legendary Items to a container, it might spawn 5 items, but it also might spawn 2 or 3. I am of course unmarking the container as having spawned a legendary item each time, but doing that on separate instances of the script running at unpredictably different speeds leads to unpredictable results.

      To work around this, I created Legendary1, Legendary2, Legendary3, etc. Each item knows how many total to spawn. This means that on the same script instance, I can cycle unmarking the container and asking for a legendary however many times we need. When finished, the Legendary Item will drop itself from the vendor container and delete itself, ensuring that the associated script and all data gets dropped by the game engine. No save bloat here!

      To randomize which of these items to spawn, I created LeveledItem lists that have a 20% chance none. I added "Legendary Item" MISC records at levels 1, 13, 25, 37, and 50 for the 1, 2, 3, 4, and 5 values, respectively. This means you always have a 20% chance of no legendaries, which is good. We want a bit of random! At level 1, you have an 80% chance of 1 legendary item. Level 13, you now have a 40% of 1 item, and a 40% chance of two items. At level 50 and above, you have the same 20% chance of nothing, and a 16% chance each for 1, 2, 3, 4, or 5 items.

      But wait... remember that unused feature of legendary items in the base game? You can totally pass a list of acceptable items to spawn! I have used that to create more Legendary Item types that spawn only weapons, only armor, or only melee weapons. Each of these works using the existing LeveledItem records of all weapons, all armors, and all melee weapons.

      Okay, so now I have four leveled lists that can be added to vendor inventories: Any, Weapon, Armor, and Melee. These spawn a randomized Legendary Item that will then trigger the process to create appropriate legendaries in its owning container. To get these into vendor inventories, I could just put them in there. But that's kind of rude! It'll conflict with any other mod that also wants to add to those containers.

      Instead, we turn to the method I've used for several mods from Skyrim (when Papyrus was introduced) to Starfield: the LeveledItem.AddForm Papyrus function! Papyrus is an object-oriented scripting language and LeveledItem itself is ultimately a child of Form, so we can add a LeveledItem into an existing LeveledItem by script. This is stored in your save (just once, so it's small) rather than affecting the game files directly, so it won't conflict with any other mods. And remember how Use All means the LeveledItem will spawn everything you put into it? So all we have to do is find a Use All LeveledItem record that is already in the vendor's container and use a script to add one of these four new LeveledItem records into it.

      So now, I went through every vendor in the game. This is easier than it sounds because Bethesda is actually very reliable about labeling them internally. If you search for "vendor" in the Creation Kit, you will get all of the vendor containers in your results. I checked each vendor to see if they already sold weapons and/or armor. If they do, I next checked the different vendors' Use All LeveledItem records to see which vendors shared some of the same lists. I don't want to add to two lists that a vendor uses, because then you could spawn way too many legendaries. This part took a bit and was annoying, but eventually I found ways to add to every base-game and Far Harbor vendor such that I only affected a single list from each vendor. Whether I added my Any, Weapon, Armor, or Melee list was based on what the vendor already was selling. Unfortunately, most of the vendors in Nuka World are build really annoyingly. A few used existing lists, and so they were already covered. The rest used way too many intermixing lists. I had to decide between letting Nuka World vendors sell 0-15 legendaries or just not adding to them at all, and I chose the latter.
    2. Keukotis
      Keukotis
      • supporter
      • 213 kudos
      With all of that context now set, I can actually answer the questions I've received.

      Will this work with a mod that adds new items to the game?
      Yes, if the author added those items into the existing lists in the game. I use the all weapons and armor, all weapons, all armor, and all melee weapons lists. If another mod adds to those, they'll work just fine with this.

      Will this work with a mod that adds new legendary effects?
      Same answer. I'm just triggering the base-game process for generating random legendary items. If a mod adds to the lists of all legendary effects for weapons or armors, then it'll work fine with this.

      Which vendors are affected?
      Everyone in the base game and all DLC that sells weapons, except most Nuka World vendors because they are built differently. So if a mod uses a base-game or DLC list that I happened to have added to, it will be covered already. Otherwise you'd need me or someone else to make a patch, which is super simple. For the record, these are all of the LeveledItem records that I have affected:

      • VL_Vendor_General
      • VL_Vendor_General_Drumlin
      • VL_Vendor_PowerArmor
      • VL_Vendor_Clothing
      • VL_Vendor_Armor
      • VL_Vendor_Weapon
      • LL_Vendor_Components_Diamond_Swatter
      • LLC_DCShopArmor
      • DLC03_LLI_Trapper_Weapons_Woods_All
      • DLC03_VL_Vendor_Clothing
      • LL_Armor_Synth_Set_Full_Dirty
      I was actually shocked at how small this list was. Building this same system for Starfield required 38 lists for the base game and another 2 for Shattered Space. Fallout 4's vendors were just a lot more forgiving here. Importantly: this probably does not cover merchants in your settlements. These vendor inventories are built differently and... I just don't trust that I wouldn't be making them able to spawn up to 25 legendaries, so I skipped them. Go to normal shops and you'll already see plenty of legendary items.
  2. VoxVenatu
    VoxVenatu
    • supporter
    • 0 kudos
    I highly highly recommend making it noticeable on the main page, to any who download, that you HAVE to interact more than once for that legendary item to actually appear. I only just now got annoyed with it enough to come here and see what was causing the "Legendary item" placeholder to sit in their trade inventory lol. I was just assuming the few times I found that placeholder thing, that maybe there was a mod conflict or something (as I have probably too many different legendary mods  😁)
  3. ChroKorgoth
    ChroKorgoth
    • member
    • 1 kudos
    Just tried the mod and it seems to be working but do the legendary item only spawn on the vendor once i opened his inventory to trade at least once? I ask because the first time I went to Trudy for example she had a misc item called Legendary Item, then when i closed the conversation and tried to trade again she had a legendary for sale. So for the mod to work its magic I have to initiate the trade conversation twice?
    1. Keukotis
      Keukotis
      • supporter
      • 213 kudos
      The process is slow, but the vendor container should load before you open it once. Let me test some more if I can reduce the delay.
    2. ChroKorgoth
      ChroKorgoth
      • member
      • 1 kudos
      Thanks for the reply, for reference I walked from Starlight Drive-In to the Drumlin Dinner to trade with Trudy so no fast travel was used, I also met Trashcan Carla along the road and the same thing happened with her, had to trade twice for the legendary item to spawn
    3. Keukotis
      Keukotis
      • supporter
      • 213 kudos
      I tested this some more. I was able to massively speed up the process by changing how the cycle happens, but you're right! I can't believe I didn't notice, but vendor containers actually do not fill their contents upon you entering the cell. They really don't until you open them. That's... annoying. I'll see if I can do something else, but it's possible that'll just be what's needed.

      EDIT: Yup, there's no way to fix this issue. Vendor containers do not load their inventory (and thus calculate their LeveledItem records) until the player opens them. That's annoying, but minor, I guess. I've uploaded the new version with the faster spawn cycle process.
    4. ChroKorgoth
      ChroKorgoth
      • member
      • 1 kudos
      Oh there is no problem, it is really just a minor thing, I will roleplay as if there was an option to ask the vendor if he sells anything special :p

      Thanks for looking it up tho, the mod is still a really nice addition to the game!
  4. Pfaulke
    Pfaulke
    • member
    • 2 kudos
    Thanks for the fun mod.  Is it possible to flag the .esp as an esl without messing up the scripts?
    1. Keukotis
      Keukotis
      • supporter
      • 213 kudos
      I can't think of any reason making this an ESL should harm it. Nothing about this depends on its references being unchanged.
  5. ChroKorgoth
    ChroKorgoth
    • member
    • 1 kudos
    Interesting mod, so if a vendor sells a weapon from a mod they can also sell a legendary version of it? Also, does this mod affect settlement shops or only shops at Diamond City and other vanilla vendors?
    1. Keukotis
      Keukotis
      • supporter
      • 213 kudos
      Maybe, maybe not. Whether they can sell legendaries of a mod-added weapon depends on if that weapon was added to the list of all weapons that the game uses when generating legendary items.
  6. seraphael
    seraphael
    • member
    • 30 kudos
    It’s almost strange that no one thought of this idea earlier! It makes interacting with vendors more engaging while also serving as a money sink, helping to balance the economy more effectively.

    Which types of vendors are affected by this? Are the major ones like in DC and Goodneighbor more likely to have legendaries in stock, as would probably be more appropriate? Also, is it compatible with Commonwealth Weaponry Vendors?
  7. softbanker
    softbanker
    • member
    • 2 kudos
    Would this work with Nail guns and Saw rifles from When pigs fly? 
  8. LordNighthawk4
    LordNighthawk4
    • member
    • 19 kudos
    Cool idea, first thought it did not work/requires a new save until i saw a "legendary item" in trudys inventory (just started a new playthrough last night) and waited a moment.

    Does this also work with far harbor and nuka world items?
    1. Keukotis
      Keukotis
      • supporter
      • 213 kudos
      Far Harbor, absolutely yes.

      Nuka World, only a couple of vendors. Most of the rest are built such that there just wasn't a way to slip this in correctly. It's unfortunate. I wish they'd have used some standard lists for more of those vendors, or at least not have shared the new lists between so many of them.

      You'll see that this requires Far Harbor only. That's because the other vendors from DLC that it does affect do just use some of the standard, base-game lists already.
  9. Hangover3000
    Hangover3000
    • supporter
    • 0 kudos
    Thank you for this upload! I'm going to try this out rn. I'm curious to see if it will work with custom vendors as well.