Welcome to the AFK Mods bug tracker. In order to report an issue, 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.

An account will be required to submit an issue, so if you need one and are unable to register, please contact us via the forums at https://afkmods.iguanadons.net/

Issue Data
Status: Closed
Issue Type: Bug Report
Project: Unofficial Fallout 4 Patch
Component: Fallout 4: Vanilla
Category: Settlements & Workshops
Assigned To: Sclerocephalus
Platform: All
Severity: Low
Votes: 0
Watching: N/A
Opened By KernalsEgg on Jul 7, 2018 1:47 pm
Last Edited By Sclerocephalus on Sep 8, 2018 6:06 am
Closed By Sclerocephalus on Sep 9, 2018 1:49 pm
Resolution: Fixed
Comment: Fixed for UFO4P 2.0.5

Issue #24775: WorkshopFloraHarvestTime Actor Value Not Set on Workshop Flora Creation

There appears to be a bug with newly created workshop plants (mutfruit, tatos, corn, etc.) being SetHarvested(False) when they first reload. For instance, if I create a mutfruit plant, unload and reload the workshop, the mutfruit plant will suddenly have fruit on it. This occurs because the Actor Value WorkshopFloraHarvestTime is only set when the plant is activated (through the OnActivate() event in WorkshopObjectScript), and not when it is created.

Therefore, when the plant is first placed, WorkshopFloraHarvestTime defaults to 0. So, when the game checks whether a day has elapsed in the HandleWorkshopReset() function (as per the WorkshopObjectScript), it will always return true. That is, assuming that the player is at least 1 in-game day into the save.

I call this a bug because the HandleCreation() function goes out of it's way to ensure that there won't be any fruit on any newly created plant. So, it doesn't make much sense that the plant could then instantly grow fruit on reload, given that it would otherwise take a full day.

A simple fix would be to run SetValue(WorkshopParent.WorkshopFloraHarvestTime, Utility.GetCurrentGameTime()) where HandleCreation() has SetHarvested(True). I had a quick look over the UFO4P WorkshopObjectScript (with the find feature) and I didn't come across anything addressing this issue. Additionally, installing UFO4P doesn't appear to fix this issue in-game.

This section of code appears to work as a solution, and can be implemented into an external script. It's just something that I've included in my mod in absence of another fix.

Event OnInit()
	Self.RegisterForCustomEvent(akSender = WorkshopParent, asEventName = "WorkshopObjectBuilt";)

Event WorkshopParentScript.WorkshopObjectBuilt(WorkshopParentScript akSender, Var[] akArgs)
	If ((akArgs[0] As WorkshopObjectScript).GetBaseObject() As Flora)
		If (!(akArgs[0] As WorkshopObjectScript).GetValue(akAV = WorkshopParent.WorkshopFloraHarvestTime))
			(akArgs[0] As WorkshopObjectScript).SetValue(akAV = WorkshopParent.WorkshopFloraHarvestTime, afValue = Utility.GetCurrentGameTime())



2 comment(s) [Closed]
Sclerocephalus said:
Actually, that actor value is not only not properly initialized. I also doesn't get properly updated, and handling of the flora harvest times is basically a somplete mess.

Your fix is way too complicated though. Workflow is as follows:
- If you build an object, an OnObjectPlaced event fires on WorkshopScript
- OnObjectPlaced calls BuildObjectPUBLIC on WorkshopParentScript
- BuildObjectPUBLIC calls HandleCreation on WorkshopObjectScript, also does other stuf and finally sends a WorkshopObjectBuilt event.

Now we can listen to that event of course. But we can also initialize the actor value earlier, in the HandleCreation.function: BuildObjectPUBLIC calls that function with bNewlyBuilt = true. It is the only instance calling that function with that bool passed in as true, so if we check for bNewlyBuilt == true, we can be sure that the code only runs right after the object has been created.

So we best modify a block of code in the HandleCreation function as follows:
	if bNewlyBuilt
		; if flora, mark initially as harvested
		if GetBaseObject() as Flora
			;UFO4P 2.0.5 Bug #24775: also initialize the related actor value:
			SetValue (WorkshopParent.WorkshopFloraHarvestTime, Utility.GetCurrentGameTime())

But there's anothe problem: As you can see in the HandleDestruction() function, "destroyed" doesn't mean "harvested" at the same time (although the 3D art changes) because that function separately marks any destroyed crops as harvested. Which, in turn, means however that we also should not touch the harvested state on any crop that is destroyed already. Otherwise, it could appear regrown immediately after repair, and that makes little sense.

In other words, there is a check for destroyed crops missing in the HandleReset() function:
		;UFO4P 2.0.5 Bug #24775: also check for destroyed crops. Otherwise, they may be regrown immediately after the repair:
		if !IsDestroyed() && IsActorAssigned() && utility.GetCurrentGameTime() > (harvestTime + floraResetHarvestDays)

And we also have to re-initialize the actor value after a crop has been repaired. Otherwise, they could still regrow faster than newly built crops. This requires an edit to the OnDestructionStageChanged event:
	elseif aiCurrentStage == 0 && IsBed() == false


		;UFO4P 2.0.5 Bug #24775: added check:
		;Reset the actor value that controls the harvest time. Otherwise, this crop will regrow faster than a newly built one.
		if GetBaseObject() as Flora
			SetValue(WorkshopParent.WorkshopFloraHarvestTime, Utility.GetCurrentGameTime())


Comment #1 Sep 8, 2018 6:05 am  Edited by Sclerocephalus on Sep 9, 2018 9:43 am
Sclerocephalus said:
A note on your own script:

You really should store "akArgs[0] as WorkshopObjectScript" in a variable as that will save you the time for subsequent re-evaluations. Admittedly, it saves little in a single instance, but if that's done consistently throughout your scripts (i.e. storing anything that's used more than once in your script in a variable, so you won't have to re-evaluate it), the gain will be quite noticeable.

And with the workshop scripts, every little helps anyway.

Showing Comments 1 - 2 of 2