Jump to content

Scripting: Locking/Unlocking in a Fragment.


Recommended Posts

What I'm trying to accomplish:

 

When the Player attempts to activate a lock on a container or door, instead of opening the lockpick mini-game, a message box will appear with options to choose how you want to unlock the container/door (Strength Check/Use Explosives) and will unlock the container/door if the player passed.

 

How I've tried to accomplish this so far:

 

Give the Player a Perk with a Entry Point; Activate, and set the following Target conditions for the entry;

 

GetObjectType Terminal = 0 AND, GetObjectType Container = 1 OR, GetObjectType Door = 1 OR, GetLocked = 1 AND, and finally GetLockLevel <= 100.

 

The following code in the perk fragment is simplified:

 

LockpickMenu.Show() ;The Message Box that will present the following options
If ButtonPressed == 0 ; Option 1: Do Nothing
ElseIf ButtonPressed == 1 ; Option 2: Test of Strength
Unlock
ElseIf ButtonPressed == 2 ; Option 3: Test of Melee
Unlock
ElseIf ButtonPressed == 3 ; Option 4: Test of Explosives
Unlock
ElseIf ButtonPressed == 4 ; Option 5: Lockpick Minigame
LockpickReminder.Show() ; A Message
EndIf

 

Properties for ButtonPressed, LockpickMenu, and LockpickReminder has been filled successfully.

My Problem is that I can't find a good way to input a function to replicate Unlock or SetLockLevel(0), as using Unlock would state, when compiled, that its a variable needing to be defined, and SetLockLevel is not a recognized function. Can Unlock be defined in the properties, and if so, how? I read in a topic that you can't define a function in a fragment, but didn't recognize a good workaround that fits my situation. Besides that, I've scoured the Creation Kit wiki and other sites for clues, but to no avail. If the intended code can't work in a perk fragment, how should this be approached then?

 

Any Help will be greatly appreciated.

 

 

 

 

Link to comment
Share on other sites

Just tried that, but It still states when compiling "variable unlock is undefined". Way I figured, I have to define it in properties or figure out to throw this code in a seperate script and have this perk try to trigger that script, which I'm not sure how to do either.

Link to comment
Share on other sites

Alright, here's an update. After some Trial and Error, I can't say it worked. After first set of testing, I found that no matter which option I picked, the Papyrus Logs indicated that only the first option got selected (I put Traces under each option). After looking around, I concluded that this was probably attributed to the fact that when I created the Int ButtonPressed property, the const. was greyed out and checked so now it remains a const value (that's my guess anyway). So after attaching akTargetRef.SetLockLevel(0) under the first option to see if it actually worked, I find that the option was triggered, but the Door was still locked.

 

This brings up a new question (assuming the code stays in the Frag): How can I make the Int Property not const, as it was checked and greyed out during creation.

 

While the original questions remains: Is akTargetRef.SetLockLevel(0) (or something similar) usable in a perk fragment? If not, what would be the best way to go about it?

 

Like before, any help is greatly appreciated.

Link to comment
Share on other sites

Sorry, I didn't look too carefully at your code.

 

You want this:

 

int ButtonPressed = LockpickMenu.Show()

 

Unless ButtonPressed is a property, then it should just be:

 

ButtonPressed = LockpickMenu.Show()

Edited by Reneer
Link to comment
Share on other sites

Just so you know, the example on the CK wiki is wrong. You need to use "Unlock()" with the brackets, so that it knows you want the function "Unlock", not a non-existant variable.

 

I also don't think you gain anything from "ButtonPressed" being a property rather than a variable. So to change that go to the Advanced tab in the fragments section of the window, select edit script and in that window remove the property definition. Then save and close that window, go back to the Papyrus Fragment tab and define "Int ButtonPressed = 0" in the normal area. You don't need to use " = 0" or whatever, but it's usually good to have an initial value.

 

Also if you're anything like me and want to know exactly what's happening in the scripts, just add stupid amounts of "Debug.Trace"es and pore over the papyrus logs, and remember to either comment them out or compile as release rather than debug.

Link to comment
Share on other sites

Thanks to both of you, I've finally got it working. Initially, I tried using just "ButtonPressed = LockpickMenu.Show()" because that's how it was in the second example of Options Menu on CreationKit.com, though it kept telling me that ButtonPressed needed to be defined, so I made it a property because I didn't know of any other way of doing it. Making it a property didn't work, so I ended up leaving it out. I've used unlock() at one point but compile still gave out an error with it, can't remember what it was now. < Ignore any of that if it doesn't make sense, because it shouldn't. :tongue: And by the way Galvon, I do put Debugs in it (that's how I knew it was only picking first option on my previous post), I just left it out to make it simpler for any helpers to read it. And thanks on how to remove properties on a frag. I misspelled a property at one point, so I tried looking up how, but didn't find any useful answers.

 

TL;DR: Turns out, I had all the phrases (and more) to do it, its just the right way of putting it together kept alluding me due to wrong assumptions and continuous compiling errors (which occasionally would point at stuff which is not really causing it, its weird like that sometimes). Thank you both very much.

 

For others who want the correct code for this situation as reference, here it is:

 

int ButtonPressed = LockpickMenu.Show() ; The Message Box that will present the options.
If ButtonPressed == 0 ; Option 1: Do Nothing.
ElseIf ButtonPressed == 1 ; Option 2: Test Strength.
akTargetRef.Unlock()
ElseIf ButtonPressed == 2 ; Option 3: Test Melee.
akTargetRef.Unlock()
ElseIf ButtonPressed == 3 ; Option 4: Test Explosive.
akTargetRef.Unlock()
ElseIf ButtonPressed == 4 ; Option 5: Lockpick Minigame.
LockpickReminder.Show() ; A Message
EndIf

;Warning: This Coding is simplified to just proof of concept, it doesn't really test your strength or melee to unlock, it goes ahead and unlocks it.

 

Edited for typos and clarifying.

Edited by JackRob
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...