ZodiarkeTheFirstBorn Posted February 8, 2020 Share Posted February 8, 2020 Is it possible to make one-use keys for chests that break after use? Lots of people have mods that make lockpicking harder, would be nice to have 'small keys' or 'silver keys' which can be found or purchased. I'll make it myself if it's possible to make. Just wondering if it can be done. Link to comment Share on other sites More sharing options...
IsharaMeradin Posted February 8, 2020 Share Posted February 8, 2020 Theoretically. You'd need to create the key and assign it to the container / door. You'd need to use some code from my key ring mod (tho there is a better method within my Inventory Management System mod) in order to determine if the key has been used. By default, if the key is within player inventory it will be used instead of the lockpicking mini-game. In essence, you are getting the door / container object, finding its key object and then looking in the player inventory for it. If it is there, then after the door / container has been opened remove the key. If you want to be really "immersive" silently add a broken key in its place. But it probably would not work with my key ring (from either mod). Because the key ring keeps the keys out of the player inventory until they need to be used and then puts them back into the key ring inventory. That is not to say that it couldn't be made to work, just wouldn't work side by side initially. Most likely, you will require the use of SKSE. What you'd need from my key ring is the code used to obtain the targeted door / container (personally prefer the method from IMS over the one in Key Ring) plus the code that looks up the key object for that door.Taken from the key ring within Inventory Management System RebuiltComments added to help explain ;PROPERTIES GlobalVariable Property myHotKey Auto ;Assign the global variable record holding the value of the Scan Code for the desired key ;TIP: by using a global variable record you can either set up an MCM for the player to change the key assignment ;or the player can use the console to change the value of the key. ;downside code must be put in place somewhere to unregister for the old key and register for the new key. ;easier to do with an MCM menu as that can be handled in the OnConfigClose event ;FUNCTIONS ;this is a custom function which prevents the user defined hot key from calling the code at inappropriate times ;requires SKSE Bool Function SafeProcess() If (!Utility.IsInMenuMode()) \ && (!UI.IsMenuOpen("Dialogue Menu")) \ && (!UI.IsMenuOpen("Console")) \ && (!UI.IsMenuOpen("Crafting Menu")) \ && (!UI.IsMenuOpen("MessageBoxMenu")) \ && (!UI.IsMenuOpen("ContainerMenu")) ;IsInMenuMode to block when game is paused with menus open ;Dialogue Menu check to block when dialog is open ;Console check to block when console is open - console does not trigger IsInMenuMode and thus needs its own check ;Crafting Menu check to block when crafting menus are open - game is not paused so IsInMenuMode does not work ;MessageBoxMenu check to block when message boxes are open - while they pause the game, they do not trigger IsInMenuMode ;ContainerMenu check to block when containers are accessed - while they pause the game, they do not trigger IsInMenuMode Return True Else Return False EndIf EndFunction ;this function checks to see if the targeted object has a key assigned to it and returns that value otherwise it returns NONE Form Function GetLockedObjKey(ObjectReference LockedObj) If LockedObj If LockedObj.IsLocked() Key LockedObjKey = LockedObj.GetKey() If LockedObjKey Debug.Notification("Found "+LockedObjKey.GetName()) Return LockedObjKey as Form Else Debug.Notification("Key not found") Return None EndIf EndIf EndIf EndFunction ;this function calls a function which gets the objects key Function LockedObjectPrep(ObjectReference ObjRef) Form TheKey = GetLockedObjKey(ObjRef) ;this is where you would check player iventory for the key in question EndFunction ;EVENTS ;requires SKSE Event OnKeyDown(Int KeyCode) If KeyCode == myHotKey.GetValue() Ref = Game.GetCurrentCrosshairRef() If Ref != None && SafeProcess() == true If (((Ref.GetBaseObject().GetType() == 29) && (Ref.GetOpenState() == 3)) || (Ref.GetBaseObject().GetType() == 28)) LockedObjectPrep(Ref) EndIf EndIf EndIf EndEvent Does not include code to register for the key press or to update the key assignment if changed. That code for me was handled on a different script attached to the same object. The method from the Key Ring mod utilizes an item which when equipped starts a quest to fill up to a certain number of aliases with nearby objects that are locked. It may or may not get the object that the player intends to interact with. Thus it is an inferior method albeit it may be a non-skse method. Cannot remember to be honest. Link to comment Share on other sites More sharing options...
Recommended Posts