2022-06-16 12:02:24 +00:00
|
|
|
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
|
2022-06-21 20:10:12 +00:00
|
|
|
FormList Property ETR_ExcludeFromNew Auto
|
|
|
|
FormList Property ETR_ExcludeMisc Auto
|
2022-06-16 12:02:24 +00:00
|
|
|
|
|
|
|
Container Property ETR_CellStorageContainer Auto
|
|
|
|
|
|
|
|
Keyword Property LocTypePlayerHouse Auto
|
|
|
|
|
2022-06-21 20:10:12 +00:00
|
|
|
bool bBusy = false
|
2022-06-16 12:02:24 +00:00
|
|
|
bool bAtHome = false
|
2022-06-21 20:10:12 +00:00
|
|
|
bool bRescanHome = false
|
|
|
|
bool bRescanPersistent = false
|
|
|
|
ObjectReference lastDestContainer = None
|
|
|
|
bool lastDestIsPersistent = false
|
|
|
|
ObjectReference lastSourceContainer = None
|
|
|
|
bool lastSourceIsPersistent = false
|
|
|
|
int iUpdateCount
|
2022-06-16 12:02:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
event OnInit()
|
|
|
|
OnPlayerLoadGame()
|
|
|
|
endevent
|
|
|
|
|
|
|
|
|
|
|
|
Event OnPlayerLoadGame()
|
|
|
|
AddInventoryEventFilter(ETR_ItemsStored)
|
2022-06-21 20:10:12 +00:00
|
|
|
Location currentLocation = PlayerRef.GetCurrentLocation()
|
|
|
|
bAtHome = currentLocation && currentLocation.HasKeyword(LocTypePlayerHouse)
|
|
|
|
if bAtHome
|
|
|
|
GotoState("AtHome")
|
|
|
|
else
|
|
|
|
GotoState("")
|
|
|
|
endif
|
2022-06-16 12:02:24 +00:00
|
|
|
EndEvent
|
|
|
|
|
|
|
|
|
|
|
|
Event OnLocationChange(Location akOldLoc, Location akNewLoc)
|
|
|
|
bAtHome = akNewLoc && akNewLoc.HasKeyword(LocTypePlayerHouse)
|
2022-06-21 20:10:12 +00:00
|
|
|
if bAtHome
|
|
|
|
GotoState("AtHome")
|
|
|
|
else
|
|
|
|
GotoState("")
|
|
|
|
endif
|
2022-06-16 12:02:24 +00:00
|
|
|
endEvent
|
|
|
|
|
|
|
|
|
2022-06-21 20:10:12 +00:00
|
|
|
Event OnMenuClose(String MenuName)
|
|
|
|
UnregisterForUpdate()
|
|
|
|
OnUpdate()
|
|
|
|
EndEvent
|
|
|
|
|
|
|
|
|
|
|
|
Event OnUpdate()
|
2022-06-16 12:02:24 +00:00
|
|
|
|
2022-06-21 20:10:12 +00:00
|
|
|
if UI.IsMenuOpen("ContainerMenu")
|
|
|
|
RegisterForMenu("ContainerMenu")
|
2022-06-16 12:02:24 +00:00
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2022-06-21 20:10:12 +00:00
|
|
|
while bBusy
|
|
|
|
Debug.Notification("Stored OnUpdate is busy")
|
|
|
|
Utility.wait(0.5)
|
|
|
|
endwhile
|
2022-06-16 12:02:24 +00:00
|
|
|
|
2022-06-21 20:10:12 +00:00
|
|
|
bBusy = true
|
|
|
|
|
|
|
|
iUpdateCount += 1
|
|
|
|
Debug.Notification("Running Stored OnUpdate " + iUpdateCount)
|
|
|
|
|
|
|
|
if bRescanHome
|
|
|
|
if lastSourceContainer && lastSourceContainer as Actor && (lastSourceContainer as Actor).IsPlayerTeammate()
|
|
|
|
lastSourceContainer = None
|
2022-06-16 12:02:24 +00:00
|
|
|
return
|
|
|
|
endif
|
2022-06-21 20:10:12 +00:00
|
|
|
ObjectReference cellStorage = ETR_Functions.GetCellStorage(PlayerRef, ETR_PersistentStorageList, ETR_CellStorageContainer)
|
|
|
|
ETR_Functions.SyncCellStorage(cellStorage, ETR_ExcludeMisc)
|
2022-06-16 12:02:24 +00:00
|
|
|
endif
|
|
|
|
|
2022-06-21 20:10:12 +00:00
|
|
|
if bRescanPersistent
|
2022-06-16 12:02:24 +00:00
|
|
|
|
2022-06-21 20:10:12 +00:00
|
|
|
ETR_ItemsStored.Revert()
|
|
|
|
Form[] aContainers = ETR_PersistentStorageList.ToArray()
|
|
|
|
int n = aContainers.length
|
|
|
|
while n > 0
|
|
|
|
n -= 1
|
|
|
|
ETR_Functions.AddArtifactsToList(aContainers[n], ETR_ItemsStored, ETR_ExcludeMisc, true)
|
|
|
|
endwhile
|
2022-06-16 12:02:24 +00:00
|
|
|
|
2022-06-21 20:10:12 +00:00
|
|
|
ETR_ItemsFound.Revert()
|
|
|
|
ETR_Functions.AddArtifactsToList(PlayerRef, ETR_ItemsFound, ETR_ExcludeFromNew)
|
|
|
|
|
|
|
|
Actor[] aFollowers = ETR_Functions.GetPlayerFollowers()
|
|
|
|
int i = aFollowers.length
|
|
|
|
while i > 0
|
|
|
|
i -= 1
|
|
|
|
ETR_Functions.AddArtifactsToList(aFollowers[i], ETR_ItemsFound, ETR_ExcludeFromNew)
|
|
|
|
endwhile
|
2022-06-16 12:02:24 +00:00
|
|
|
|
|
|
|
endif
|
|
|
|
|
2022-06-21 20:10:12 +00:00
|
|
|
bBusy = false
|
|
|
|
|
|
|
|
EndEvent
|
2022-06-16 12:02:24 +00:00
|
|
|
|
|
|
|
|
2022-06-21 20:10:12 +00:00
|
|
|
; We acquired a stored item, and we want to find out if we just have taken the last stored item of its kind
|
2022-06-16 12:02:24 +00:00
|
|
|
event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)
|
|
|
|
|
2022-06-21 20:10:12 +00:00
|
|
|
if akSourceContainer
|
|
|
|
if lastSourceContainer != akSourceContainer
|
|
|
|
lastSourceContainer = akSourceContainer
|
|
|
|
lastSourceIsPersistent = ETR_PersistentStorageList.HasForm(akSourceContainer)
|
|
|
|
endif
|
|
|
|
if bAtHome || lastSourceIsPersistent
|
|
|
|
bRescanHome = bAtHome
|
|
|
|
bRescanPersistent = true
|
|
|
|
RegisterForSingleUpdate(0.5)
|
2022-06-16 12:02:24 +00:00
|
|
|
endif
|
|
|
|
elseif bAtHome
|
2022-06-19 20:35:56 +00:00
|
|
|
ObjectReference cellStorage = ETR_Functions.GetCellStorage(PlayerRef, ETR_PersistentStorageList, ETR_CellStorageContainer)
|
2022-06-21 20:10:12 +00:00
|
|
|
if cellStorage.GetItemCount(akBaseItem)
|
|
|
|
ETR_Functions.SyncCellStorage(cellStorage, ETR_ExcludeMisc)
|
2022-06-19 20:35:56 +00:00
|
|
|
if ETR_Functions.GetItemCountInList(ETR_PersistentStorageList, akBaseItem) == 0
|
2022-06-17 23:24:04 +00:00
|
|
|
ETR_ItemsStored.RemoveAddedForm(akBaseItem)
|
|
|
|
ETR_ItemsFound.AddForm(akBaseItem)
|
|
|
|
endif
|
2022-06-16 12:02:24 +00:00
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
|
|
|
endevent
|
2022-06-21 20:10:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
state AtHome
|
|
|
|
|
|
|
|
; The item is already registered as stored, and we just stored more
|
|
|
|
event OnItemRemoved(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akDestContainer)
|
|
|
|
|
|
|
|
if akDestContainer
|
|
|
|
if lastDestContainer != akDestContainer
|
|
|
|
lastDestContainer = akDestContainer
|
|
|
|
lastDestIsPersistent = ETR_PersistentStorageList.HasForm(akDestContainer)
|
|
|
|
endif
|
|
|
|
if ! lastDestIsPersistent
|
|
|
|
bRescanHome = true
|
|
|
|
bRescanPersistent = false
|
|
|
|
RegisterForSingleUpdate(0.5)
|
|
|
|
endif
|
|
|
|
elseif akItemReference
|
|
|
|
ObjectReference cellStorage = ETR_Functions.GetCellStorage(PlayerRef, ETR_PersistentStorageList, ETR_CellStorageContainer)
|
|
|
|
if cellStorage.GetItemCount(akBaseItem) == 0
|
|
|
|
cellStorage.AddItem(akBaseItem, 1, true)
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
|
|
|
endevent
|
|
|
|
|
|
|
|
endstate
|