Welcome to the AFK Mods bug tracker. In order to report an issue, you need to have a VALIDATED account to post one. Once you have followed the link the registration email sent you, please select a project from the drop down menu below. Select “Open New Issue” and fill out the form with as many details as possible.

Please also consider sending your bug report to Bethesda if you are reporting on an issue with Skyrim Special Edition, Fallout 4, or Starfield. Doing so will help everyone on all platforms.

Issue Data
Status: Closed
Issue Type: Bug Report
Project: Unofficial Fallout 4 Patch
Component: Fallout 4: Vanilla
Category: Quests & Dialogue
Assigned To: Sclerocephalus
Platform: All
Severity: Medium
Votes: 0
Watching: N/A
Opened By Sclerocephalus on Apr 24, 2020 4:36 pm
Last Edited By Sclerocephalus on Nov 11, 2020 5:57 am
Closed By Sclerocephalus on Nov 24, 2020 7:57 pm
Resolution: Fixed
Comment: Fixed for UFO4P 2.1.2

Issue #28982: The custom item quest (CustomItemQuest [QUST:0022576B]) may fail to spawn unique items as intended

 
Unique items - such as Kellog's gun, Brandis's gun, Grognak's Axe, Tessa's Fist, the Wazer Wifle and many others - do not exist at game start and also are not added via leveled lists, but are created at run time when they are needed. Their creation (and placement, if required) is handled by the custom item quest [NB: there may be more than one custom item quest running in the game: every DLC that adds unique items to the game comes with its own custom item quest to handle them].

To create an item, an external script (e.g. on a trigger or on another quest) sets a specific stage on the custom item quest script. Each stage on that quest corresponds to a specific item.
For this to work, the custom item quest holds the following data for each item (this set of data makes a struct, and the structs are held in an array).
- the quest stage corresponding to the item
- a leveled list to spawn the base item from
- a form list with the mods to be added to the base item
- a marker to place the item at OR a container to place it in
- optionally an alias to fill with the ref of the created item

Once a stage on the quest has been set, CustomItemQuestScript (attached to this quest) starts running: it looks for the stage in its data array and subsequently creates the corresponding item.

To understand what's wrong, we have to look at an item request on an external script.
We take DN109 as an example: this quest starts running the first time the player comes to Quincy (handled by an OnLocationChange event), and the fragment on its startup stage looks as follows:

Function Fragment_Stage_0000_Item_00()
CustomItemQuest.SetStage(270)
CustomItemQuest.SetStage(310)
Alias_Tessa.GetActorRef().EquipItem(Armor_Power_Raider_ArmRight)
EndFunction


The first line sets the stage to create Clint's Gun, the second line sets the stage to create Tessa's Fist. A look at the custom item quest shows that they are both created in the respective actors' inventories
The third line is the most interesting one: this line is supposed to equip Tessa's Fist. Armor_Power_Raider_ArmRight is the base object of Tessa's Fist, and IF Tessa has an instance of it in her inventory (if everything went right, this would be Tessa's Fist), she will equip that instance. IF NOT however, this line creates a new ref to the base object and equips that one instead.

Those of us who have played the game know that she usually has the fist in her inventory and a standard power armor item equipped instead. Apparently therefore, CustomItemQuestScript has not created the unique item by the time this fragment tries to equip it, and when it has been created later on, it ends up in her inventory [NB: there is a third scenario possible: if DN109 shuts down before CustomItemQuestScript has created the item, the custom item quest loses the reference to create the item in (because it uses Tessa's alias on DN109 instead of her actual reference) and the item cannot be obtained by the player at all].

In fact, most external scripts that let the custom item quest create an item are trying to manipulate this item more or less immediately after they have set the stage, and whether this will work or not only depends on whether CustomItemQuestScript is fast enough with creating it. With the current quest design, it is ceratinly not (as explained below). Though, even if item creation starts running earlier, there is no guarantee that the item is already created when the scripts try to run operations on it. This situation is actually the worst because it may be difficult to repeat (after all, how fast the item creation is processed will also depend on the overall script activity in the background). Thus, some of the reports on missing unique items we did close in the past because we could not reproduce them may have been valid bug reports.

The SetStage() function is latent, i.e. it will not return until all fragments on the stage it sets have finished running. Thus, if the fragments on the individual stages of the custom item quest(s) would call CustomItemQuestScript directly, SetStage() would not return until the item has been created, and all subsequent operations on them would work. Unfortunately though, there are no fragments on the stages of the custom item quest: whoever conceived the quest left them all empty and made CustomItemQuestScript listen for an OnStageSet() event instead, and this is what broke it: now StageSet() returns immediately and the OnStageSet() event starts a separate thread to create the item that runs in parallel with the operations on the external script that called for the item creation.

Related Issues: 26492  27316  28891  30815