Scriptname ETR_TrackStoredItems extends ReferenceAlias Actor Property PlayerRef Auto FormList Property ETR_ItemsNew Auto FormList Property ETR_ItemsFound Auto FormList Property ETR_ItemsStored Auto FormList Property ETR_PersistentStorageList Auto Container Property ETR_CellStorageContainer Auto Keyword Property LocTypePlayerHouse Auto bool bAtHome = false event OnInit() OnPlayerLoadGame() endevent Event OnPlayerLoadGame() AddInventoryEventFilter(ETR_ItemsStored) EndEvent Event OnLocationChange(Location akOldLoc, Location akNewLoc) bAtHome = akNewLoc && akNewLoc.HasKeyword(LocTypePlayerHouse) endEvent ; The item is already registered as stored, and we just stored more event OnItemRemoved(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akDestContainer) if ! bAtHome return endif if akDestContainer if !(akDestContainer as Actor) if ETR_PersistentStorageList.HasForm(akDestContainer) return endif elseif (akDestContainer as Actor).IsPlayerTeammate() return endif endif if ((akDestContainer && akDestContainer.GetParentCell() == PlayerRef.GetParentCell()) || (! akDestContainer && ETR_Functions.HasRefInCell(akBaseItem, None, true, ETR_PersistentStorageList))) ObjectReference cellStorage = ETR_Functions.GetCellStorage(PlayerRef, ETR_PersistentStorageList, ETR_CellStorageContainer) if cellStorage.GetItemCount(akBaseItem) == 0 cellStorage.AddItem(akBaseItem, 1, true) endif endif endevent ; We took a stored item, and we want to find out if it's the last stored item of its kind event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer) if akSourceContainer && !(akSourceContainer as Actor) && ETR_PersistentStorageList.HasForm(akSourceContainer) if ETR_Functions.GetItemCountInList(ETR_PersistentStorageList, akBaseItem) == 0 ETR_ItemsStored.RemoveAddedForm(akBaseItem) ETR_ItemsFound.AddForm(akBaseItem) endif elseif bAtHome ObjectReference cellStorage = ETR_Functions.GetCellStorage(PlayerRef, ETR_PersistentStorageList, ETR_CellStorageContainer) int iCount = cellStorage.GetItemCount(akBaseItem) if iCount > 0 && ! ETR_Functions.HasRefInCell(akBaseItem, None, true, ETR_PersistentStorageList) cellStorage.RemoveItem(akBaseItem, iCount, true) if ETR_Functions.GetItemCountInList(ETR_PersistentStorageList, akBaseItem) == 0 ETR_ItemsStored.RemoveAddedForm(akBaseItem) ETR_ItemsFound.AddForm(akBaseItem) endif endif endif endevent