@ -1,4 +1,4 @@
Scriptname _00E_SleightOfHandAlias extends ReferenceAlias Hidden
Scriptname _00E_ContainerController extends ReferenceAlias Hidden
; This script sets up the sleight of hand loot of a chest upon activating it
; This script sets up the sleight of hand loot of a chest upon activating it
;=====================================================================================
;=====================================================================================
@ -11,37 +11,63 @@ event OnInit()
endevent
endevent
event OnPlayerLoadGame()
event OnPlayerLoadGame()
lastContainer = None
bLmHasGold = false
bLmHasSlot = false
RegisterForMenu("ContainerMenu")
RegisterForMenu("ContainerMenu")
RegisterForMenu("LootMenu")
RegisterForMenu("LootMenu")
endevent
endevent
event OnUpdate()
event OnUpdate()
if lastContainer && UI.IsMenuOpen("LootMenu") && lastContainer == Game.GetCurrentCrosshairRef()
ObjectReference currentContainer = lastContainer
OpenHiddenSlot(lastContainer, true)
lastContainer = None
if ! currentContainer
return
endif
if UI.IsMenuOpen("LootMenu") && currentContainer == Game.GetCurrentCrosshairRef()
if bLmHasGold
IncrementGold(currentContainer)
endif
if bLmHasSlot
OpenHiddenSlot(currentContainer, true)
endif
endif
endif
endevent
endevent
event OnMenuOpen(String MenuName)
event OnMenuOpen(String MenuName)
if MenuName == "LootMenu"
if MenuName == "LootMenu"
UnregisterForUpdate()
; Even when QuickLoot RE does not show up, it still sends open and close menu events
; Even when QuickLoot RE does not show up, it still sends open and close menu events
; To determine if QuickLoot is open, we check it 0.1 seconds later
; To determine if QuickLoot is open, we check it 0.1 seconds later
lastContainer = None
UnregisterForUpdate()
ObjectReference lootMenuRef = Game.GetCurrentCrosshairRef()
ObjectReference lootMenuRef = Game.GetCurrentCrosshairRef()
if ! lootMenuRef
if ! lootMenuRef
return
return
endif
endif
Container baseContainer = lootMenuRef.GetBaseObject() as Container
if ! ( lootMenuRef.GetBaseObject() as Container ) || lootMenuRef.IsActivationBlocked()
if ! baseContainer || lootMenuRef.IsActivationBlocked() || _00E_ChestsWithHiddenSlots.Find(baseContainer) == -1
return
return
endif
endif
bLmHasGold = lootMenuRef.GetItemCount(Gold001) >= 5
bLmHasSlot = false
if bLmHasGold || _00E_ChestsWithHiddenSlots.Find(lootMenuRef.GetBaseObject()) > -1
if ! bLmHasGold
bLmHasSlot = true
endif
if ! IsProcessed(lootMenuRef)
lastContainer = lootMenuRef
; Clears previous request automatically
RegisterForSingleUpdate(0.1)
endif
endif
lastContainer = lootMenuRef
; Clears previous request automatically
RegisterForSingleUpdate(0.1)
return
return
endif
endif
@ -52,21 +78,35 @@ event OnMenuOpen(String MenuName)
return
return
endif
endif
if currentContainer == containt erToFill
if currentContainer == containerToFill
; Opened hidden container
; Opened hidden container
Utility.Wait(0.1)
Utility.Wait(0.1)
; Move unclaimed items to the original container
; Move unclaimed items to the original container
containt erToFill.RemoveAllItems(lastContainer, true, true)
containerToFill.RemoveAllItems(lastContainer, true, true)
lastContainer = None
lastContainer = None
containterToFill = None
containerToFill = None
return
endif
bool bDoGold = currentContainer.GetItemCount(Gold001) >= 5
bool bDoSlot = _00E_ChestsWithHiddenSlots.Find(currentContainer.GetBaseObject()) > -1
if ! bDoGold && ! bDoSlot
return
return
endif
endif
if _00E_ChestsWithHiddenSlots.Find(currentContainer.GetBaseObject()) == -1
if IsProcessed(currentContainer)
return
return
endif
endif
OpenHiddenSlot(currentContainer)
if bDoGold
IncrementGold(currentContainer)
endif
if bDoSlot
OpenHiddenSlot(currentContainer)
endif
endif
endif
endevent
endevent
@ -75,6 +115,8 @@ event OnMenuClose(String MenuName)
if MenuName == "LootMenu"
if MenuName == "LootMenu"
UnregisterForUpdate()
UnregisterForUpdate()
lastContainer = None
lastContainer = None
bLmHasGold = false
bLmHasSlot = false
endif
endif
endevent
endevent
@ -83,6 +125,39 @@ endevent
; FUNCTIONS
; FUNCTIONS
;=====================================================================================
;=====================================================================================
bool function IsProcessed(ObjectReference targetContainer)
if targetContainer.GetItemCount(_00E_HiddenSlotChecked)
return true
endif
targetContainer.AddItem(_00E_HiddenSlotChecked, 1, true)
return false
endfunction
Function IncrementGold(ObjectReference targetContainer)
int iGoldMultiplicator = _00E_GoldMult.GetValue() as int
if iGoldMultiplicator == 0
; Prevent division by zero
iGoldMultiplicator = 5
endif
float fIncrementPercentage = ( PlayerREF.GetActorValue("Lockpicking") / iGoldMultiplicator ) / 100
int iGoldBuffAmount = ( targetContainer.GetItemCount(Gold001) * fIncrementPercentage ) as Int
if iGoldBuffAmount == 0
return
endif
targetContainer.AddItem(Gold001, iGoldBuffAmount)
if iGoldBuffAmount > 1
_00E_FS_LockpickingGoldBuffMSG.Show(iGoldBuffAmount as Int)
EndIf
EndFunction
function OpenHiddenSlot(ObjectReference currentContainer, bool bLootMenu = false)
function OpenHiddenSlot(ObjectReference currentContainer, bool bLootMenu = false)
if ! SetUpHiddenSlot(currentContainer)
if ! SetUpHiddenSlot(currentContainer)
@ -93,22 +168,22 @@ function OpenHiddenSlot(ObjectReference currentContainer, bool bLootMenu = false
messageToShow.Show()
messageToShow.Show()
if bLootMenu
if bLootMenu
containt erToFill.RemoveAllItems(currentContainer, true, true)
containerToFill.RemoveAllItems(currentContainer, true, true)
else
else
; Open hidden container after the original one closes
; Open hidden container after the original one closes
Utility.Wait(0.1)
Utility.Wait(0.1)
If IsOwned(currentContainer)
If IsOwned(currentContainer)
containt erToFill.SetFactionOwner(SleightOfHandOwnerFaction)
containerToFill.SetFactionOwner(SleightOfHandOwnerFaction)
Else
Else
containt erToFill.SetFactionOwner(none)
containerToFill.SetFactionOwner(none)
Endif
Endif
lastContainer = currentContainer
lastContainer = currentContainer
containt erToFill.Activate(PlayerREF, True)
containerToFill.Activate(PlayerREF, True)
endif
endif
If containt erToFill == _00E_FS_SleightOfHand_HiddenSlot_BigSlotREF
If containerToFill == _00E_FS_SleightOfHand_HiddenSlot_BigSlotREF
_00E_EPHandler.GiveEP(_00E_BigHiddenSlotExpReward.GetValue() as int)
_00E_EPHandler.GiveEP(_00E_BigHiddenSlotExpReward.GetValue() as int)
If _00E_HiddenSlotAchievementUnlocked.GetValueInt() == 0
If _00E_HiddenSlotAchievementUnlocked.GetValueInt() == 0
UIEnchantingLearnEffectM.Play(PlayerREF)
UIEnchantingLearnEffectM.Play(PlayerREF)
@ -121,12 +196,6 @@ endfunction
bool function SetUpHiddenSlot(ObjectReference aContainer)
bool function SetUpHiddenSlot(ObjectReference aContainer)
if aContainer.GetItemCount(_00E_HiddenSlotChecked)
return false
endif
aContainer.AddItem(_00E_HiddenSlotChecked, 1, true)
if ! DoesContainerHaveHiddenSlot()
if ! DoesContainerHaveHiddenSlot()
return false
return false
EndIf
EndIf
@ -139,17 +208,17 @@ bool function SetUpHiddenSlot(ObjectReference aContainer)
if messageToShow == _00E_FS_SleightOfHand_HiddenSlot_sSmallSlotFound
if messageToShow == _00E_FS_SleightOfHand_HiddenSlot_sSmallSlotFound
containt erToFill = _00E_FS_SleightOfHand_HiddenSlot_SmallSlotREF
containerToFill = _00E_FS_SleightOfHand_HiddenSlot_SmallSlotREF
iFormlistIndex = Utility.RandomInt(0, 2) + iFormlistIndexOffset
iFormlistIndex = Utility.RandomInt(0, 2) + iFormlistIndexOffset
Elseif messageToShow == _00E_FS_SleightOfHand_HiddenSlot_sMediumSlotFound
Elseif messageToShow == _00E_FS_SleightOfHand_HiddenSlot_sMediumSlotFound
containt erToFill = _00E_FS_SleightOfHand_HiddenSlot_MediumSlotREF
containerToFill = _00E_FS_SleightOfHand_HiddenSlot_MediumSlotREF
iFormlistIndex = Utility.RandomInt(3, 5) + iFormlistIndexOffset
iFormlistIndex = Utility.RandomInt(3, 5) + iFormlistIndexOffset
Elseif messageToShow == _00E_FS_SleightOfHand_HiddenSlot_sBigSlotFound
Elseif messageToShow == _00E_FS_SleightOfHand_HiddenSlot_sBigSlotFound
containt erToFill = _00E_FS_SleightOfHand_HiddenSlot_BigSlotREF
containerToFill = _00E_FS_SleightOfHand_HiddenSlot_BigSlotREF
iFormlistIndex = Utility.RandomInt(6, 7) + iFormlistIndexOffset
iFormlistIndex = Utility.RandomInt(6, 7) + iFormlistIndexOffset
EndIf
EndIf
@ -163,9 +232,9 @@ EndFunction
Function AddItemsToContainer(Formlist itemsToAdd, int iFormlistIndexOffset, int iHiddenSlotTier)
Function AddItemsToContainer(Formlist itemsToAdd, int iFormlistIndexOffset, int iHiddenSlotTier)
containt erToFill.RemoveAllItems()
containerToFill.RemoveAllItems()
if containt erToFill == _00E_FS_SleightOfHand_HiddenSlot_BigSlotREF
if containerToFill == _00E_FS_SleightOfHand_HiddenSlot_BigSlotREF
if ! itemsToAdd.HasForm(_00E_FS_SleightOfHand_HiddenSlotUsedMarker)
if ! itemsToAdd.HasForm(_00E_FS_SleightOfHand_HiddenSlotUsedMarker)
itemsToAdd.AddForm(_00E_FS_SleightOfHand_HiddenSlotUsedMarker)
itemsToAdd.AddForm(_00E_FS_SleightOfHand_HiddenSlotUsedMarker)
@ -184,9 +253,9 @@ Function AddItemsToContainer(Formlist itemsToAdd, int iFormlistIndexOffset, int
Form formToAdd = itemsToAdd.GetAt(iIndex)
Form formToAdd = itemsToAdd.GetAt(iIndex)
if formToAdd == Gold001
if formToAdd == Gold001
containt erToFill.AddItem(itemsToAdd.GetAt(iIndex), iHiddenSlotTier*5)
containerToFill.AddItem(itemsToAdd.GetAt(iIndex), iHiddenSlotTier*5)
Else
Else
containt erToFill.AddItem(itemsToAdd.GetAt(iIndex), 1)
containerToFill.AddItem(itemsToAdd.GetAt(iIndex), 1)
EndIf
EndIf
iIndex -= 1
iIndex -= 1
@ -281,7 +350,10 @@ int iBigSlotChance = 15
; This formlist will be filled with the formlist containing the items that will actually be added into the container
; This formlist will be filled with the formlist containing the items that will actually be added into the container
Message messageToShow
Message messageToShow
ObjectReference lastContainer
ObjectReference lastContainer
ObjectReference containterToFill
ObjectReference containerToFill
bool bLmHasGold
bool bLmHasSlot
Actor Property PlayerRef Auto
Actor Property PlayerRef Auto
@ -289,6 +361,10 @@ GlobalVariable Property PlayerLevel Auto
GlobalVariable Property _00E_HiddenSlotAchievementUnlocked Auto
GlobalVariable Property _00E_HiddenSlotAchievementUnlocked Auto
GlobalVariable Property _00E_BigHiddenSlotExpReward Auto
GlobalVariable Property _00E_BigHiddenSlotExpReward Auto
; Use this to control how much the lockpicking skill increments the gold found in chest. When changing, remember to change in _00E_LootContainer.psc as well!
; Current calculation: Gold in chest*((Lockpicking/iGoldMultiplicator)/100)
GlobalVariable Property _00E_GoldMult Auto
; These REFs simply provide the containers that will be filled when finding a secret slot
; These REFs simply provide the containers that will be filled when finding a secret slot
ObjectReference Property _00E_FS_SleightOfHand_HiddenSlot_SmallSlotREF Auto
ObjectReference Property _00E_FS_SleightOfHand_HiddenSlot_SmallSlotREF Auto
ObjectReference Property _00E_FS_SleightOfHand_HiddenSlot_MediumSlotREF Auto
ObjectReference Property _00E_FS_SleightOfHand_HiddenSlot_MediumSlotREF Auto
@ -310,3 +386,5 @@ FormList Property _00E_FS_HiddenSlotRewardFormlists Auto
FormList Property _00E_ChestsWithHiddenSlots Auto
FormList Property _00E_ChestsWithHiddenSlots Auto
Faction Property SleightOfHandOwnerFaction Auto
Faction Property SleightOfHandOwnerFaction Auto
Message Property _00E_FS_LockpickingGoldBuffMSG Auto