2022-06-16 12:02:24 +00:00
|
|
|
Scriptname ETR_TrackFoundItems 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
|
|
|
|
|
2022-06-21 20:10:12 +00:00
|
|
|
bool bBusy = false
|
2022-06-16 12:02:24 +00:00
|
|
|
int iFollowerIndex = 0
|
2022-06-21 20:10:12 +00:00
|
|
|
bool bAtHome = false
|
|
|
|
bool bRescanHome = false
|
|
|
|
bool bRescanPersistent = false
|
2022-06-22 18:03:51 +00:00
|
|
|
bool bRescanFollowers = false
|
2022-06-21 20:10:12 +00:00
|
|
|
ObjectReference lastDestContainer = None
|
|
|
|
bool lastDestIsPersistent = false
|
|
|
|
int iUpdateCount
|
2022-06-16 12:02:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
event OnInit()
|
|
|
|
OnPlayerLoadGame()
|
|
|
|
endevent
|
|
|
|
|
|
|
|
|
|
|
|
Event OnPlayerLoadGame()
|
|
|
|
AddInventoryEventFilter(ETR_ItemsFound)
|
2022-06-21 20:10:12 +00:00
|
|
|
Location currentLocation = PlayerRef.GetCurrentLocation()
|
|
|
|
bAtHome = currentLocation && currentLocation.HasKeyword(LocTypePlayerHouse)
|
|
|
|
lastDestContainer = None
|
2022-06-23 13:50:46 +00:00
|
|
|
bBusy = false
|
2022-06-16 12:02:24 +00:00
|
|
|
EndEvent
|
|
|
|
|
|
|
|
|
|
|
|
Event OnLocationChange(Location akOldLoc, Location akNewLoc)
|
2022-06-17 23:24:04 +00:00
|
|
|
|
2022-06-18 11:17:10 +00:00
|
|
|
bAtHome = akNewLoc && akNewLoc.HasKeyword(LocTypePlayerHouse)
|
2022-06-21 20:10:12 +00:00
|
|
|
lastDestContainer = None
|
2022-06-16 12:02:24 +00:00
|
|
|
|
2022-06-22 18:03:51 +00:00
|
|
|
bRescanFollowers = true
|
|
|
|
RegisterForSingleUpdate(3.0)
|
2022-06-18 11:17:10 +00:00
|
|
|
|
|
|
|
endEvent
|
|
|
|
|
|
|
|
|
2022-06-21 20:10:12 +00:00
|
|
|
Event OnMenuClose(String MenuName)
|
|
|
|
UnregisterForUpdate()
|
|
|
|
OnUpdate()
|
|
|
|
EndEvent
|
|
|
|
|
|
|
|
|
2022-06-18 11:17:10 +00:00
|
|
|
Event OnUpdate()
|
|
|
|
|
2022-06-22 18:03:51 +00:00
|
|
|
if bRescanFollowers
|
|
|
|
bRescanFollowers = false
|
|
|
|
|
|
|
|
int iCurrentFollowers = 0;
|
|
|
|
Actor[] aFollowers = ETR_Functions.GetPlayerFollowers()
|
|
|
|
int i = aFollowers.length
|
|
|
|
while i > 0
|
|
|
|
i -= 1
|
|
|
|
iCurrentFollowers += aFollowers[i].GetFormID()
|
|
|
|
endwhile
|
|
|
|
|
|
|
|
if iCurrentFollowers == iFollowerIndex
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
|
|
|
iFollowerIndex = iCurrentFollowers
|
|
|
|
Debug.Notification("Team changed, rescanning")
|
|
|
|
endif
|
|
|
|
|
2022-06-23 13:50:46 +00:00
|
|
|
if lastDestContainer && lastDestContainer as Actor && (lastDestContainer as Actor).IsPlayerTeammate()
|
|
|
|
lastDestContainer = None
|
|
|
|
bRescanHome = false
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2022-06-21 20:10:12 +00:00
|
|
|
if UI.IsMenuOpen("ContainerMenu")
|
|
|
|
RegisterForMenu("ContainerMenu")
|
|
|
|
return
|
|
|
|
endif
|
2022-06-18 11:17:10 +00:00
|
|
|
|
2022-06-21 20:10:12 +00:00
|
|
|
while bBusy
|
|
|
|
Debug.Notification("Found OnUpdate is busy")
|
|
|
|
Utility.wait(0.5)
|
|
|
|
endwhile
|
|
|
|
|
|
|
|
bBusy = true
|
|
|
|
|
|
|
|
iUpdateCount += 1
|
|
|
|
Debug.Notification("Running Found OnUpdate " + iUpdateCount)
|
2022-06-18 11:17:10 +00:00
|
|
|
|
2022-06-21 20:10:12 +00:00
|
|
|
if bRescanHome
|
2022-06-22 18:03:51 +00:00
|
|
|
bRescanHome = false
|
|
|
|
|
2022-06-22 14:06:25 +00:00
|
|
|
if lastDestContainer && lastDestContainer as PlayerBookShelfContainerScript
|
2022-06-22 13:20:07 +00:00
|
|
|
int iLimit = 10
|
2022-06-22 14:06:25 +00:00
|
|
|
while iLimit >= 0 && (lastDestContainer as PlayerBookShelfContainerScript).GetState() == "PlacingBooks"
|
2022-06-22 13:20:07 +00:00
|
|
|
Debug.Notification("Waiting for shelf update")
|
|
|
|
iLimit -= 1
|
|
|
|
Utility.wait(0.5)
|
|
|
|
endwhile
|
|
|
|
endif
|
|
|
|
|
2022-06-21 20:10:12 +00:00
|
|
|
ObjectReference cellStorage = ETR_Functions.GetCellStorage(PlayerRef, ETR_PersistentStorageList, ETR_CellStorageContainer)
|
2022-06-22 12:21:32 +00:00
|
|
|
ETR_Functions.SyncCellStorage(cellStorage, ETR_PersistentStorageList)
|
2022-06-21 20:10:12 +00:00
|
|
|
if ! bRescanPersistent
|
|
|
|
ETR_Functions.AddArtifactsToList(cellStorage, ETR_ItemsStored)
|
2022-06-18 11:17:10 +00:00
|
|
|
endif
|
2022-06-21 20:10:12 +00:00
|
|
|
endif
|
2022-06-18 11:17:10 +00:00
|
|
|
|
2022-06-21 20:10:12 +00:00
|
|
|
if bRescanPersistent
|
|
|
|
bRescanPersistent = false
|
|
|
|
Form[] aContainers = ETR_PersistentStorageList.ToArray()
|
|
|
|
int n = aContainers.length
|
|
|
|
while n > 0
|
|
|
|
n -= 1
|
2022-06-22 00:52:12 +00:00
|
|
|
ETR_Functions.AddArtifactsToList(aContainers[n], ETR_ItemsStored)
|
2022-06-18 11:17:10 +00:00
|
|
|
endwhile
|
2022-06-16 12:02:24 +00:00
|
|
|
endif
|
|
|
|
|
2022-06-21 20:10:12 +00:00
|
|
|
ETR_ItemsFound.Revert()
|
2022-06-22 00:52:12 +00:00
|
|
|
ETR_Functions.AddArtifactsToList(PlayerRef, ETR_ItemsFound, ETR_ItemsStored)
|
2022-06-22 08:28:12 +00:00
|
|
|
ETR_Functions.AddArtifactsFromFollowersToList(ETR_ItemsFound, ETR_ItemsStored)
|
2022-06-18 11:17:10 +00:00
|
|
|
|
2022-06-21 20:10:12 +00:00
|
|
|
bBusy = false
|
2022-06-16 12:02:24 +00:00
|
|
|
|
2022-06-17 23:24:04 +00:00
|
|
|
EndEvent
|
2022-06-16 12:02:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
event OnItemRemoved(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akDestContainer)
|
|
|
|
|
|
|
|
if akDestContainer
|
2022-06-21 20:10:12 +00:00
|
|
|
if lastDestContainer != akDestContainer
|
|
|
|
lastDestContainer = akDestContainer
|
|
|
|
lastDestIsPersistent = ETR_PersistentStorageList.HasForm(akDestContainer)
|
|
|
|
endif
|
2022-06-22 12:21:32 +00:00
|
|
|
|
2022-06-21 20:10:12 +00:00
|
|
|
; Moving items without latent functions should help with avoiding stack dumps
|
|
|
|
if lastDestIsPersistent
|
|
|
|
bRescanHome = false
|
|
|
|
bRescanPersistent = true
|
|
|
|
RegisterForSingleUpdate(0.5)
|
|
|
|
elseif bAtHome
|
|
|
|
bRescanHome = true
|
|
|
|
bRescanPersistent = false
|
|
|
|
RegisterForSingleUpdate(0.5)
|
2022-06-22 08:28:12 +00:00
|
|
|
elseif PlayerRef.GetItemCount(akBaseItem) == 0 && ! ETR_Functions.FollowersHaveItem(akBaseItem)
|
2022-06-21 20:10:12 +00:00
|
|
|
ETR_ItemsFound.RemoveAddedForm(akBaseItem)
|
|
|
|
ETR_ItemsNew.AddForm(akBaseItem)
|
|
|
|
endif
|
2022-06-22 08:59:20 +00:00
|
|
|
|
2022-06-18 11:17:10 +00:00
|
|
|
elseif bAtHome && akItemReference
|
2022-06-17 23:24:04 +00:00
|
|
|
ETR_ItemsFound.RemoveAddedForm(akBaseItem)
|
|
|
|
ETR_ItemsStored.AddForm(akBaseItem)
|
2022-06-19 20:35:56 +00:00
|
|
|
ETR_Functions.GetCellStorage(PlayerRef, ETR_PersistentStorageList, ETR_CellStorageContainer).AddItem(akBaseItem, 1, true)
|
2022-06-22 08:59:20 +00:00
|
|
|
|
2022-06-22 08:28:12 +00:00
|
|
|
elseif PlayerRef.GetItemCount(akBaseItem) == 0 && ! ETR_Functions.FollowersHaveItem(akBaseItem)
|
2022-06-16 12:02:24 +00:00
|
|
|
ETR_ItemsFound.RemoveAddedForm(akBaseItem)
|
|
|
|
ETR_ItemsNew.AddForm(akBaseItem)
|
|
|
|
endif
|
|
|
|
|
|
|
|
endevent
|