@ -1,4 +1,4 @@
Scriptname _00E_ContainerController extends ReferenceAlias Hidden
Scriptname _00E_ContainerBonusControl extends Quest Hidden
; This script sets up the sleight of hand loot of a chest upon activating it
int function _GetScriptVersion() Global
@ -6,140 +6,51 @@ int function _GetScriptVersion() Global
endFunction
;=====================================================================================
; EVENT S
; FUNCTION S
;=====================================================================================
event OnInit()
RegisterForMenu("ContainerMenu")
RegisterForMenu("LootMenu")
PlayerREF.AddPerk(_00E_LockpickingReqPerk)
endevent
event OnPlayerLoadGame()
lastContainer = None
bLmHasGold = false
bLmHasSlot = false
RegisterForMenu("ContainerMenu")
RegisterForMenu("LootMenu")
if ! PlayerREF.HasPerk(_00E_LockpickingReqPerk)
PlayerREF.AddPerk(_00E_LockpickingReqPerk)
endif
endevent
function OnOpenContainer(ObjectReference targetContainer)
event OnUpdate()
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
; Lockpicking menu
while targetContainer.IsLocked() && Utility.IsInMenuMode()
Utility.WaitMenuMode(1.0)
endwhile
event OnMenuOpen(String MenuName)
if MenuName == "LootMenu"
; 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
if ! ( lootMenuRef.GetBaseObject() as Container ) || lootMenuRef.IsLocked() || lootMenuRef.IsActivationBlocked() || lootMenuRef.GetActorOwner() == Player
return
endif
bLmHasGold = lootMenuRef.GetItemCount(Gold001) >= 5
bLmHasSlot = false
if bLmHasGold || _00E_ChestsWithHiddenSlots.HasForm(lootMenuRef.GetBaseObject())
if ! bLmHasGold
bLmHasSlot = true
endif
if ! IsProcessed(lootMenuRef)
lastContainer = lootMenuRef
; Clears previous request automatically
RegisterForSingleUpdate(0.1)
endif
endif
; Game mode and still locked
if targetContainer.IsLocked()
return
endif
if MenuName == "ContainerMenu"
ObjectReference currentContainer = EnderalFunctions.GetCurrentContainer()
if ! currentContainer || currentContainer as Actor || currentContainer.GetActorOwner() == Player || currentContainer.GetParentCell() != PlayerREF.GetParentCell()
return
endif
if currentContainer == containerToFill
; Opened hidden container
Utility.Wait(0.1)
; Move unclaimed items to the original container
containerToFill.RemoveAllItems(lastContainer, true, true)
lastContainer = None
containerToFill = None
return
endif
bool bDoGold = currentContainer.GetItemCount(Gold001) >= 5
bool bDoSlot = _00E_ChestsWithHiddenSlots.HasForm(currentContainer.GetBaseObject())
; Wait for it to open
int i
while i < 20 && targetContainer.GetOpenState() == 2
Utility.WaitMenuMode(0.1)
i += 1
endwhile
if ! bDoGold && ! bDoSlot
return
endif
if IsProcessed(currentContainer)
; Leave if we are not in the container menu yet
if SKSE.GetVersion()
if ! UI.IsMenuOpen("ContainerMenu")
return
endif
if bDoGold
IncrementGold(currentContainer)
endif
if bDoSlot
OpenHiddenSlot(currentContainer)
endif
elseif ! Utility.IsInMenuMode()
return
endif
endevent
event OnMenuClose(String MenuName)
if MenuName == "LootMenu"
UnregisterForUpdate()
lastContainer = None
bLmHasGold = false
bLmHasSlot = false
if targetContainer.GetItemCount(_00E_HiddenSlotChecked)
return
endif
endevent
targetContainer.AddItem(_00E_HiddenSlotChecked, 1, true)
;=====================================================================================
; FUNCTIONS
;=====================================================================================
if targetContainer.GetItemCount(Gold001) >= 5
IncrementGold(targetContainer)
endif
bool function IsProcessed(ObjectReference targetContainer)
if targetContainer.GetItemCount(_00E_HiddenSlotChecked)
return true
if _00E_ChestsWithHiddenSlots.HasForm(targetContainer.GetBaseObject())
OpenHiddenSlot(targetContainer)
endif
targetContainer.AddItem(_00E_HiddenSlotChecked, 1, true)
return false
endfunction
Function IncrementGold(ObjectReference targetContainer)
@ -186,8 +97,8 @@ function OpenHiddenSlot(ObjectReference currentContainer, bool bLootMenu = false
containerToFill.SetFactionOwner(none)
Endif
lastContainer = currentContainer
containerToFill.Activate(PlayerREF, Tru e)
containerToFill. lastContainer = currentContainer
containerToFill.Activate(PlayerREF, fals e)
endif
If containerToFill == _00E_FS_SleightOfHand_HiddenSlot_BigSlotREF
@ -215,17 +126,17 @@ bool function SetUpHiddenSlot(ObjectReference aContainer)
if messageToShow == _00E_FS_SleightOfHand_HiddenSlot_sSmallSlotFound
containerToFill = _00E_FS_SleightOfHand_HiddenSlot_SmallSlotREF
containerToFill = _00E_FS_SleightOfHand_HiddenSlot_SmallSlotREF as _00E_HiddenSlotContainer
iFormlistIndex = Utility.RandomInt(0, 2) + iFormlistIndexOffset
Elseif messageToShow == _00E_FS_SleightOfHand_HiddenSlot_sMediumSlotFound
containerToFill = _00E_FS_SleightOfHand_HiddenSlot_MediumSlotREF
containerToFill = _00E_FS_SleightOfHand_HiddenSlot_MediumSlotREF as _00E_HiddenSlotContainer
iFormlistIndex = Utility.RandomInt(3, 5) + iFormlistIndexOffset
Elseif messageToShow == _00E_FS_SleightOfHand_HiddenSlot_sBigSlotFound
containerToFill = _00E_FS_SleightOfHand_HiddenSlot_BigSlotREF
containerToFill = _00E_FS_SleightOfHand_HiddenSlot_BigSlotREF as _00E_HiddenSlotContainer
iFormlistIndex = Utility.RandomInt(6, 7) + iFormlistIndexOffset
EndIf
@ -356,11 +267,7 @@ 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 containerToFill
bool bLmHasGold
bool bLmHasSlot
_00E_HiddenSlotContainer containerToFill
Actor Property PlayerRef Auto
ActorBase Property Player Auto
@ -396,5 +303,3 @@ FormList Property _00E_ChestsWithHiddenSlots Auto
Faction Property SleightOfHandOwnerFaction Auto
Message Property _00E_FS_LockpickingGoldBuffMSG Auto
Perk Property _00E_LockpickingReqPerk Auto