Jump to content
Sign in to follow this  
Jebbalon

Hearthfire Script needs inventory event filter

Recommended Posts

Posted (edited)

This is more of a bug report but also a question about using inventory event filters...

I came across a stack dump in my papyrus log this evening (it happens). It contained references to the hearthfire script BYOHHouseBuildingPlayerScript.psc which in this case tracks the number of logs cut at sawmills.Sawn Logs are a weightless non-playable miscellaneous item added to player. 

The issue I see is that the script is not filtering for only the logs. Therefore EVERY item added to or removed from the player is tracked by that script. In my case the stack dump coincided with being thrown in Falkreath Jail. That included all my items being taken and later returned. That generated many of the inventory events that this script then had to process no doubt leading to the stack dump situation.

Here is just 2 stack dump snippets from the log...
 

Spoiler


[10/06/2019 - 12:21:55AM] Dumping stack 122764:
[10/06/2019 - 12:21:55AM]     Frame count: 1 (Page count: 1)
[10/06/2019 - 12:21:55AM]     State: Waiting on other stack for call (Freeze state: Freezing)
[10/06/2019 - 12:21:55AM]     Type: Normal
[10/06/2019 - 12:21:55AM]     Return register: [BYOH_QF_BYOHHouseBuilding_0100305D <BYOHHouseBuilding (0300305D)>]
[10/06/2019 - 12:21:55AM]     Has stack callback: No
[10/06/2019 - 12:21:55AM]     Stack trace:
[10/06/2019 - 12:21:55AM]         [alias Player on quest BYOHHouseBuilding (0300305D)].BYOHHouseBuildingPlayerScript.OnItemAdded() - "byohhousebuildingplayerscript.psc" Line 11
[10/06/2019 - 12:21:55AM]             IP: 108    Instruction: 2    Line: 11
[10/06/2019 - 12:21:55AM]             [akBaseItem]: [SoulGem < (0002E4E2)>]
[10/06/2019 - 12:21:55AM]             [aiItemCount]: 3
[10/06/2019 - 12:21:55AM]             [akItemReference]: None
[10/06/2019 - 12:21:55AM]             [akSourceContainer]: [ObjectReference < (000EF437)>]
[10/06/2019 - 12:21:55AM]             [::temp2]: [BYOH_QF_BYOHHouseBuilding_0100305D <BYOHHouseBuilding (0300305D)>]
[10/06/2019 - 12:21:55AM]             [::temp3]: [byohhousebuildingscript <BYOHHouseBuilding (0300305D)>]
[10/06/2019 - 12:21:55AM]             [::NoneVar]: None


[10/06/2019 - 12:21:55AM] Dumping stack 122814:
[10/06/2019 - 12:21:55AM]     Frame count: 3 (Page count: 3)
[10/06/2019 - 12:21:55AM]     State: Waiting on other stack for return (Freeze state: Freezing)
[10/06/2019 - 12:21:55AM]     Type: Normal
[10/06/2019 - 12:21:55AM]     Return register: 0
[10/06/2019 - 12:21:55AM]     Has stack callback: No
[10/06/2019 - 12:21:55AM]     Stack trace:
[10/06/2019 - 12:21:55AM]         [ (00000014)].Actor.GetItemCount() - "<native>" Line ?
[10/06/2019 - 12:21:55AM]             IP: 0
[10/06/2019 - 12:21:55AM]             [param1]: [MiscObject < (0300300E)>]
[10/06/2019 - 12:21:55AM]         [BYOHHouseBuilding (0300305D)].byohhousebuildingscript.UpdateLogCount() - "byohhousebuildingscript.psc" Line 516
[10/06/2019 - 12:21:55AM]             IP: 175    Instruction: 2    Line: 516
[10/06/2019 - 12:21:55AM]             [::temp71]: [Actor < (00000014)>]
[10/06/2019 - 12:21:55AM]             [::temp72]: [MiscObject < (0300300E)>]
[10/06/2019 - 12:21:55AM]             [::temp73]: 0
[10/06/2019 - 12:21:55AM]             [::temp74]: 0.000000
[10/06/2019 - 12:21:55AM]             [::NoneVar]: None
[10/06/2019 - 12:21:55AM]             [::temp75]: False
[10/06/2019 - 12:21:55AM]             [logCount]: 0
[10/06/2019 - 12:21:55AM]             [currentElement]: 0
[10/06/2019 - 12:21:55AM]             [::temp76]: False
[10/06/2019 - 12:21:55AM]             [::temp77]: False
[10/06/2019 - 12:21:55AM]             [::temp78]: None
[10/06/2019 - 12:21:55AM]             [::temp79]: False
[10/06/2019 - 12:21:55AM]         [alias Player on quest BYOHHouseBuilding (0300305D)].BYOHHouseBuildingPlayerScript.OnItemAdded() - "byohhousebuildingplayerscript.psc" Line 11
[10/06/2019 - 12:21:55AM]             IP: 108    Instruction: 2    Line: 11
[10/06/2019 - 12:21:55AM]             [akBaseItem]: [Form < (000EBA02)>]
[10/06/2019 - 12:21:55AM]             [aiItemCount]: 1
[10/06/2019 - 12:21:55AM]             [akItemReference]: None
[10/06/2019 - 12:21:55AM]             [akSourceContainer]: [ObjectReference < (000EF437)>]
[10/06/2019 - 12:21:55AM]             [::temp2]: [BYOH_QF_BYOHHouseBuilding_0100305D <BYOHHouseBuilding (0300305D)>]
[10/06/2019 - 12:21:55AM]             [::temp3]: [byohhousebuildingscript <BYOHHouseBuilding (0300305D)>]
[10/06/2019 - 12:21:55AM]             [::NoneVar]: None
 

the first shows the script firing for a Soul Gem being returned to me from the Falkreath evidence chest ( FalkreathEvidenceChest [REFR:000EF437] ). The second shows checking for the number of logs ( BYOHMaterialLog "Sawn Log" [MISC:0300300E] ) Which happens in another script BYOHHouseBuildingScript.psc. It was after Cabbage Soup (000EBA02) was returned to me.

The controlling quest is BYOHHouseBuilding [QUST:0300305D]

Here is the BYOHHouseBuildingPlayerScript.psc - it is short enough...
 

Spoiler

Scriptname BYOHHouseBuildingPlayerScript extends ReferenceAlias  
{script on player to track player's location}

Event OnLocationChange(Location akOldLoc, Location akNewLoc)
	;debug.trace(self + ": " + akOldLoc + ", " + akNewLoc)
	(GetOwningQuest() as BYOHHouseBuildingScript).PlayerChangeLocation(akOldLoc, akNewLoc)
EndEvent

Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)
	;debug.trace(self + "OnItemAdded " + akBaseItem + ", itemCount=" + aiItemCount)
	(GetOwningQuest() as BYOHHouseBuildingScript).UpdateLogCount()
endEvent

Event OnItemRemoved(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akDestContainer)
	;debug.trace(self + "OnItemRemoved " + akBaseItem + ", itemCount=" + aiItemCount)
	(GetOwningQuest() as BYOHHouseBuildingScript).UpdateLogCount()
endEvent

; check for DLC01.esm to update vampire lord hate list
Event OnPlayerLoadGame()
	;debug.trace(self + " OnPlayerLoadGame...")
	if (GetOwningQuest() as BYOHHouseBuildingScript).bInitializedOtherDLC == false
		(GetOwningQuest() as BYOHHouseBuildingScript).InitializeOtherDLC()
	endif
endEvent

 

Adding AddInventoryEventFilter(BYOHMaterialLog) to both OnItemAdded() and OnItemRemoved() would do it. Right?
 

Spoiler

MiscObject Property BYOHMaterialLog Auto
...

Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)
	;debug.trace(self + "OnItemAdded " + akBaseItem + ", itemCount=" + aiItemCount)
	AddInventoryEventFilter(BYOHMaterialLog)
	(GetOwningQuest() as BYOHHouseBuildingScript).UpdateLogCount()
endEvent

Event OnItemRemoved(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akDestContainer)
	;debug.trace(self + "OnItemRemoved " + akBaseItem + ", itemCount=" + aiItemCount)
	AddInventoryEventFilter(BYOHMaterialLog)
	(GetOwningQuest() as BYOHHouseBuildingScript).UpdateLogCount()
endEvent

 

Also, that is the proper way of adding Inventory Event Filters ? correct ?
I've seen some scripting that puts the AddInventoryEventFilter() in say the OnInit() event. But I'm not sure that is correct as each could use different filters. Putting the function call into the event makes sense to me, outside the event where it is used doesn't. 

Anyway, thanks in advance for any insight into this.

If it is good thing to add into USSEP I'd be happy to add tracker ticket.

-Jebbalon

Edited by Jebbalon
added more info and spelling

Share this post


Link to post
Share on other sites

The correct method for this is actually to put it in the OnInit() event directly on the ReferenceAlias script. I have no idea what the hell we were thinking back when this was "corrected" but I'm equally surprised that nobody ever noticed either. While what we had done for UHFP 2.0.1 worked for any existing saves, it would not have covered a new game due to placing it in the wrong section of our retro script.

Look at NN01CrimsonNirnrootScript. That's how it should have been done in this case too.

If you could please open a ticket with all the details you laid out here that would be great - or just link back to this forum topic. Either way we don't want to lose track of this one.

Share this post


Link to post
Share on other sites

Opened Issue #27626

Adding the filter to OnInit() works too then. One of my scripts for tracking gold, I put them in the OnItemAdded/Removed and that worked too. - I guess there are instances where it would need separate filters for Added vs. Removed. Like gold added to sweetroll vendor and sweetrolls removed.
The restriction is to have the filter in the script instance where it is used. Which is all the wiki really explains.

Thanks Arthmoor

-Jebbalon

Share this post


Link to post
Share on other sites

Putting the filter calls into the event itself is likely to cause problems in the long run. That's why Bethesda never uses them that way. It's not something that need to be called repeatedly, and the way it's described makes it sound like you could be toggling the filter on and off each time, or worse, stacking multiple filters on top of each other.

Share this post


Link to post
Share on other sites

Ahhh... That makes sense now.

Ok, so does it have to go in OnInit() or can it also go in OnBeginState() or even OnUpdate() ?

Share this post


Link to post
Share on other sites

Nope. For something like this you only want it setting the filter once. Other stuff putting it in a state that's only called once for each function would be fine. It all depends on when it needs to be done.

Basically anything that's active at game start should set its filter in the OnInit() for the ReferenceAlias script.

Don't stick it in an OnUpdate() because those are expected to be called multiple times.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

Support us on Patreon!

Patreon
×
×
  • Create New...