1
artifact-tracker/Source/Scripts/ArtifactTrackerPlayer.psc

185 lines
4.5 KiB
Plaintext
Raw Normal View History

2022-06-30 10:31:01 +00:00
Scriptname ArtifactTrackerPlayer extends ReferenceAlias
FormList Property ETR_ItemsNew Auto
FormList Property ETR_ItemsFound Auto
FormList Property ETR_ItemsStored Auto
Keyword Property LocTypePlayerHouse Auto
Perk Property ETR_PickupPerk Auto
2022-06-30 10:31:01 +00:00
bool bAtHome = false
ObjectReference bookShelf = None
int iFollowerIndex = 0
int iArtifactCount = 0
2022-06-30 10:31:01 +00:00
event OnInit()
OnPlayerLoadGame()
endevent
Event OnPlayerLoadGame()
if ! IsLoaded()
ETR_ItemsNew.Revert()
ETR_ItemsFound.Revert()
ETR_ItemsStored.Revert()
UnregisterForUpdate()
Debug.Notification("Failed to initialize ArtifactTracker.dll")
return
endif
if ! (GetReference() as Actor).HasPerk(ETR_PickupPerk)
(GetReference() as Actor).AddPerk(ETR_PickupPerk)
endif
2022-06-30 10:31:01 +00:00
if skse.GetPluginVersion("Ahzaab's moreHUD Plugin") >= 30800
ahzmorehud.RegisterIconFormList("dbmNew", ETR_ItemsNew)
ahzmorehud.RegisterIconFormList("dbmFound", ETR_ItemsFound)
ahzmorehud.RegisterIconFormList("dbmDisp", ETR_ItemsStored)
endif
if skse.GetPluginVersion("Ahzaab's moreHUD Inventory Plugin") >= 10017
ahzmorehudie.RegisterIconFormList("dbmNew", ETR_ItemsNew)
ahzmorehudie.RegisterIconFormList("dbmFound", ETR_ItemsFound)
ahzmorehudie.RegisterIconFormList("dbmDisp", ETR_ItemsStored)
endif
if SKSE.GetPluginVersion("QuickLootEE") >= 0
QuickLootEE.RegisterNewItemsList(ETR_ItemsNew)
QuickLootEE.RegisterDisplayedItemsList(ETR_ItemsStored)
QuickLootEE.RegisterFoundItemsList(ETR_ItemsFound)
2022-06-30 10:31:01 +00:00
endif
int iNewArtifactCount = GetArtifactCount()
if iNewArtifactCount != iArtifactCount
iArtifactCount = iNewArtifactCount
Debug.Notification("Artifact list changed, rebuilding the list")
ETR_ItemsNew.Revert() ; rebuild the list
endif
2022-06-30 10:31:01 +00:00
; Rebuild all lists to avoid discrepancies, stale data, and broken records
RescanStoredArtifacts()
RescanFoundArtifacts()
RescanNewArtifacts()
Location currentLocation = (GetReference() as ObjectReference).GetCurrentLocation()
bAtHome = currentLocation && currentLocation.HasKeyword(LocTypePlayerHouse)
if bAtHome
RegisterForModEvent("AT_HomeInventoryUpdate", "OnHomeInventoryUpdate")
RegisterForMenu("ContainerMenu")
GotoState("AtHome")
2022-06-30 10:31:01 +00:00
else
UnregisterForModEvent("AT_HomeInventoryUpdate")
UnregisterForMenu("ContainerMenu")
GotoState("")
2022-06-30 10:31:01 +00:00
endif
EndEvent
Event OnLocationChange(Location akOldLoc, Location akNewLoc)
bAtHome = akNewLoc && akNewLoc.HasKeyword(LocTypePlayerHouse)
if bAtHome
RegisterForModEvent("AT_HomeInventoryUpdate", "OnHomeInventoryUpdate")
GotoState("AtHome")
2022-06-30 10:31:01 +00:00
elseif akOldLoc && akOldLoc.HasKeyword(LocTypePlayerHouse)
UnregisterForModEvent("AT_HomeInventoryUpdate")
GotoState("")
2022-06-30 10:31:01 +00:00
endif
int iCurrentFollowers = 0;
Actor[] aFollowers = GetPlayerFollowers()
int i = aFollowers.length
while i > 0
i -= 1
iCurrentFollowers += aFollowers[i].GetFormID()
endwhile
if iCurrentFollowers != iFollowerIndex
iFollowerIndex = iCurrentFollowers
RegisterForSingleUpdate(5.0) ; wait until followers load into the location
endif
endEvent
Event OnUpdate()
Debug.Notification("Team changed, updating ETR_ItemsFound")
RescanFoundArtifacts()
EndEvent
event OnHomeInventoryUpdate(string eventName, string strArg, float numArg, Form sender)
2022-06-30 10:31:01 +00:00
if bAtHome
SyncCellStorage()
endif
endevent
state AtHome
event OnBeginState()
RegisterForMenu("ContainerMenu")
endevent
event OnEndState()
UnregisterForMenu("ContainerMenu")
endevent
event OnMenuOpen(String MenuName)
if ! bAtHome
GotoState("")
return
endif
ObjectReference currentContainer = GetCurrentContainer()
if currentContainer as PlayerBookShelfContainerScript
bookShelf = currentContainer
endif
endevent
event OnMenuClose(String MenuName)
if bookShelf
ObjectReference ref = bookShelf
bookShelf = None
Utility.wait(1.0)
int iLimit = 10
while iLimit > 0 && (ref as PlayerBookShelfContainerScript).GetState() == "PlacingBooks"
iLimit -= 1
Utility.wait(0.5)
endwhile
SyncCellStorage()
endif
endevent
endstate
2022-06-30 10:31:01 +00:00
; NATIVE FUNCTIONS
bool function IsLoaded() native global
int function GetArtifactCount() native global
2022-06-30 10:31:01 +00:00
function RescanStoredArtifacts() native global
function RescanFoundArtifacts() native global
function RescanNewArtifacts() native global
ObjectReference function GetCellStorage() native global
ObjectReference function GetCurrentContainer() native global
function SyncCellStorage() native global
2022-06-30 10:31:01 +00:00
Actor[] function GetPlayerFollowers() native global