@ -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
;=====================================================================================
@ -11,37 +11,63 @@ event OnInit()
endevent
event OnPlayerLoadGame()
lastContainer = None
bLmHasGold = false
bLmHasSlot = false
RegisterForMenu("ContainerMenu")
RegisterForMenu("LootMenu")
endevent
event OnUpdate()
if lastContainer && UI.IsMenuOpen("LootMenu") && lastContainer == Game.GetCurrentCrosshairRef()
OpenHiddenSlot(lastContainer, true)
ObjectReference currentContainer = lastContainer
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
endevent
event OnMenuOpen(String MenuName)
if MenuName == "LootMenu"
UnregisterForUpdate()
; 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
lastContainer = None
UnregisterForUpdate()
ObjectReference lootMenuRef = Game.GetCurrentCrosshairRef()
if ! lootMenuRef
return
endif
Container baseContainer = lootMenuRef.GetBaseObject() as Container
if ! baseContainer || lootMenuRef.IsActivationBlocked() || _00E_ChestsWithHiddenSlots.Find(baseContainer) == -1
if ! ( lootMenuRef.GetBaseObject() as Container ) || lootMenuRef.IsActivationBlocked()
return
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
endif
@ -52,21 +78,35 @@ event OnMenuOpen(String MenuName)
return
endif
if currentContainer == containt erToFill
if currentContainer == containerToFill
; Opened hidden container
Utility.Wait(0.1)
; Move unclaimed items to the original container
containt erToFill.RemoveAllItems(lastContainer, true, true)
containerToFill.RemoveAllItems(lastContainer, true, true)
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
endif
if _00E_ChestsWithHiddenSlots.Find(currentContainer.GetBaseObject()) == -1
if IsProcessed(currentContainer)
return
endif
OpenHiddenSlot(currentContainer)
if bDoGold
IncrementGold(currentContainer)
endif
if bDoSlot
OpenHiddenSlot(currentContainer)
endif
endif
endevent
@ -75,6 +115,8 @@ event OnMenuClose(String MenuName)
if MenuName == "LootMenu"
UnregisterForUpdate()
lastContainer = None
bLmHasGold = false
bLmHasSlot = false
endif
endevent
@ -83,6 +125,39 @@ endevent
; 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)
if ! SetUpHiddenSlot(currentContainer)
@ -93,22 +168,22 @@ function OpenHiddenSlot(ObjectReference currentContainer, bool bLootMenu = false
messageToShow.Show()
if bLootMenu
containt erToFill.RemoveAllItems(currentContainer, true, true)
containerToFill.RemoveAllItems(currentContainer, true, true)
else
; Open hidden container after the original one closes
Utility.Wait(0.1)
If IsOwned(currentContainer)
containt erToFill.SetFactionOwner(SleightOfHandOwnerFaction)
containerToFill.SetFactionOwner(SleightOfHandOwnerFaction)
Else
containt erToFill.SetFactionOwner(none)
containerToFill.SetFactionOwner(none)
Endif
lastContainer = currentContainer
containt erToFill.Activate(PlayerREF, True)
containerToFill.Activate(PlayerREF, True)
endif
If containt erToFill == _00E_FS_SleightOfHand_HiddenSlot_BigSlotREF
If containerToFill == _00E_FS_SleightOfHand_HiddenSlot_BigSlotREF
_00E_EPHandler.GiveEP(_00E_BigHiddenSlotExpReward.GetValue() as int)
If _00E_HiddenSlotAchievementUnlocked.GetValueInt() == 0
UIEnchantingLearnEffectM.Play(PlayerREF)
@ -121,12 +196,6 @@ endfunction
bool function SetUpHiddenSlot(ObjectReference aContainer)
if aContainer.GetItemCount(_00E_HiddenSlotChecked)
return false
endif
aContainer.AddItem(_00E_HiddenSlotChecked, 1, true)
if ! DoesContainerHaveHiddenSlot()
return false
EndIf
@ -139,17 +208,17 @@ bool function SetUpHiddenSlot(ObjectReference aContainer)
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
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
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
EndIf
@ -163,9 +232,9 @@ EndFunction
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)
itemsToAdd.AddForm(_00E_FS_SleightOfHand_HiddenSlotUsedMarker)
@ -184,9 +253,9 @@ Function AddItemsToContainer(Formlist itemsToAdd, int iFormlistIndexOffset, int
Form formToAdd = itemsToAdd.GetAt(iIndex)
if formToAdd == Gold001
containt erToFill.AddItem(itemsToAdd.GetAt(iIndex), iHiddenSlotTier*5)
containerToFill.AddItem(itemsToAdd.GetAt(iIndex), iHiddenSlotTier*5)
Else
containt erToFill.AddItem(itemsToAdd.GetAt(iIndex), 1)
containerToFill.AddItem(itemsToAdd.GetAt(iIndex), 1)
EndIf
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
Message messageToShow
ObjectReference lastContainer
ObjectReference containterToFill
ObjectReference containerToFill
bool bLmHasGold
bool bLmHasSlot
Actor Property PlayerRef Auto
@ -289,6 +361,10 @@ GlobalVariable Property PlayerLevel Auto
GlobalVariable Property _00E_HiddenSlotAchievementUnlocked 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
ObjectReference Property _00E_FS_SleightOfHand_HiddenSlot_SmallSlotREF Auto
ObjectReference Property _00E_FS_SleightOfHand_HiddenSlot_MediumSlotREF Auto
@ -310,3 +386,5 @@ FormList Property _00E_FS_HiddenSlotRewardFormlists Auto
FormList Property _00E_ChestsWithHiddenSlots Auto
Faction Property SleightOfHandOwnerFaction Auto
Message Property _00E_FS_LockpickingGoldBuffMSG Auto