Moved lockpicking gold bonus to ContainerController

This commit is contained in:
Eddoursul 2024-01-13 20:15:35 +01:00
parent 5dc76239c8
commit 6e1bf5a6e9
6 changed files with 118 additions and 97 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -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 lastContainer = lootMenuRef
; Clears previous request automatically ; Clears previous request automatically
RegisterForSingleUpdate(0.1) RegisterForSingleUpdate(0.1)
endif
endif
return return
endif endif
@ -52,29 +78,45 @@ event OnMenuOpen(String MenuName)
return return
endif endif
if currentContainer == containterToFill 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
containterToFill.RemoveAllItems(lastContainer, true, true) containerToFill.RemoveAllItems(lastContainer, true, true)
lastContainer = None lastContainer = None
containterToFill = None containerToFill = None
return return
endif endif
if _00E_ChestsWithHiddenSlots.Find(currentContainer.GetBaseObject()) == -1 bool bDoGold = currentContainer.GetItemCount(Gold001) >= 5
bool bDoSlot = _00E_ChestsWithHiddenSlots.Find(currentContainer.GetBaseObject()) > -1
if ! bDoGold && ! bDoSlot
return return
endif endif
if IsProcessed(currentContainer)
return
endif
if bDoGold
IncrementGold(currentContainer)
endif
if bDoSlot
OpenHiddenSlot(currentContainer) OpenHiddenSlot(currentContainer)
endif endif
endif
endevent endevent
event OnMenuClose(String MenuName) 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
containterToFill.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)
containterToFill.SetFactionOwner(SleightOfHandOwnerFaction) containerToFill.SetFactionOwner(SleightOfHandOwnerFaction)
Else Else
containterToFill.SetFactionOwner(none) containerToFill.SetFactionOwner(none)
Endif Endif
lastContainer = currentContainer lastContainer = currentContainer
containterToFill.Activate(PlayerREF, True) containerToFill.Activate(PlayerREF, True)
endif endif
If containterToFill == _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
containterToFill = _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
containterToFill = _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
containterToFill = _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)
containterToFill.RemoveAllItems() containerToFill.RemoveAllItems()
if containterToFill == _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
containterToFill.AddItem(itemsToAdd.GetAt(iIndex), iHiddenSlotTier*5) containerToFill.AddItem(itemsToAdd.GetAt(iIndex), iHiddenSlotTier*5)
Else Else
containterToFill.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

View File

@ -1,57 +1,5 @@
Scriptname _00E_ChestAndDoorLockScript extends ObjectReference Scriptname _00E_ChestAndDoorLockScript extends ObjectReference
;=====================================================================================
; GOLDBUFF
;=====================================================================================
; 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)
int iGoldMultiplicator = 5
int iCurrentGoldCount
float fPlayerLockpicking
bool bDone
Message Property _00E_FS_LockpickingGoldBuffMSG Auto
MiscObject Property Gold001 Auto
Event OnOpen(ObjectReference akActionRef)
if !bDone && (Self.GetBaseObject().GetType() == 28) ; check if it's a container otherwise the script tries to call this stuff on doors
bDone = True
iCurrentGoldCount = Self.GetItemCount(Gold001)
fPlayerLockpicking = PlayerREF.GetActorValue("Lockpicking")
if iCurrentGoldCount >= 5 && fPlayerLockpicking >= 15
IncrementGold()
EndIf
EndIf
EndEvent
;=====================================================================================
; FUNCTIONS
;=====================================================================================
Function IncrementGold()
float fIncrementPercentage = (fPlayerLockpicking/iGoldMultiplicator)/100
int iGoldBuffAmount = (iCurrentGoldCount*fIncrementPercentage) as Int
Self.AddItem(Gold001, iGoldBuffAmount)
if iGoldBuffAmount > 1
_00E_FS_LockpickingGoldBuffMSG.Show(iGoldBuffAmount as Int)
EndIf
EndFunction
;=====================================================================================
; ORIGINAL SCRIPT
;=====================================================================================
Event OnLoad() Event OnLoad()
BlockActivation(True) BlockActivation(True)
EndEvent EndEvent
@ -101,7 +49,11 @@ Event OnHit(ObjectReference akAggressor, Form akSource, Projectile akProjectile,
_00E_sDoorLocked.Show() _00E_sDoorLocked.Show()
WPNTG06ControlStaffShootFailM.Play(Self) WPNTG06ControlStaffShootFailM.Play(Self)
ElseIf projectileLevel >= lockLevel ElseIf projectileLevel >= lockLevel
UnlockLock() ; Unlock
Self.Lock(False)
_00E_UILockpickingUnlockM.Play(Self)
_00E_Ability_Antimagic_FXSShader.Play(Self)
self.PlaceAtMe(_00E_UnlockLockExplosion, 1)
EndIf EndIf
EndIf EndIf
@ -166,15 +118,6 @@ Event OnActivate(ObjectReference akActionRef)
EndEvent EndEvent
Function UnlockLock()
Self.Lock(False)
_00E_UILockpickingUnlockM.Play(Self)
_00E_Ability_Antimagic_FXSShader.Play(Self)
self.PlaceAtMe(_00E_UnlockLockExplosion, 1)
EndFunction
Formlist Property _00E_SuntempleLocations Auto Formlist Property _00E_SuntempleLocations Auto
Projectile Property _00E_UnlockProjectile_Novice Auto Projectile Property _00E_UnlockProjectile_Novice Auto