ArgoTheFurry Posted March 3, 2017 Share Posted March 3, 2017 (edited) Hello, I'm creating my first mod and I'm pretty much done but I have a problem I have a door in my dungeon. Player is supposed to open them and walk further into the dungeon. Door is supposed to close and lock automatically after few seconds. I suck with math/programming/scripts- all that crazy stuff. So far I have a script I found somewhere. It works perfectly- it closes the door after the amount of time I specify. However it does not lock them. I'd like the script to close the door and lock it with my dungeon key that I've created. Here is the script I have now Scriptname AutoCloseDoor extends ObjectReference Event OnInit() SetOpen(false) ;when script starts, the door gets closed EndEvent Event OnActivate(ObjectReference akActionRef) int openstate = self.GetOpenState() if(openstate == 1 || openstate == 2) ;door is open or opening utility.wait(3) ;wait 3 seconds SetOpen(false) ;close door endif EndEvent Int Property NewProperty123 Auto I would be very grateful if someone could simply add what I need to this existing script so I can just copy-paste it and finally have my mod ready.And also it would be nice to know if (after adding something to the script) I'd also have to choose some options in that Script Box later Cheers. Edited March 3, 2017 by ArgoTheFurry Link to comment Share on other sites More sharing options...
IsharaMeradin Posted March 3, 2017 Share Posted March 3, 2017 The command you are looking for is Lock. I suspect it would need to be placed after closing the door. However, in your script I am not sure if Self.Lock() would work or if you'd need to do something else. I would suggest that if you want it to close and lock at a particular point or distance that instead of trying to calculate a timer you place a trigger volume box and use the OnTriggerEnter or OnTriggerLeave event to perform the closing and locking. Link to comment Share on other sites More sharing options...
ArgoTheFurry Posted March 3, 2017 Author Share Posted March 3, 2017 The command you are looking for is Lock. I suspect it would need to be placed after closing the door. However, in your script I am not sure if Self.Lock() would work or if you'd need to do something else. I would suggest that if you want it to close and lock at a particular point or distance that instead of trying to calculate a timer you place a trigger volume box and use the OnTriggerEnter or OnTriggerLeave event to perform the closing and locking.Thank you for your answer. Is that "volume box" something that "triggers" something when you get close enough to it? (Or, judging by what you posted- you leave this volume box close to the door and when player walks away from the door this volume box locks the door? If I am correct this would be perfect! Way better than scripts to close/lock after some duration because it may be tricky- I want to make sure player can't leave the room once they enter and move away from the door and in some cases they could try to whirlwind sprint out of there before it closes or something like that. So once again- thank you very much for your response. However it still doesnt change the fact I have no idea how to do it. :3Would you be so kind to post what I have to do (script/anything else) to set up that "volume box"? Link to comment Share on other sites More sharing options...
IsharaMeradin Posted March 3, 2017 Share Posted March 3, 2017 A trigger volume box is an invisible box in-game that either something happens when an object enters or when an object leaves. In the Creation Kit you access them with the icon that looks like a cube with a T on it. It will place a small cube in the cell which you can size to your needs. You can also highlight an object in the render window prior to clicking on the icon and the trigger box will be placed around that object. At any rate, you can place one at the door and extend it to the point where you want the door to be locked and use the OnTriggerLeave event. Or you can place one where you want the door to be locked and use the OnTriggerEnter event instead. Either way will work. It may be easier to set up the first as if you need to adjust the point of exit you have only one edge you really need to tweak. Do be sure to make the volume box large enough that there are no gaps that the player could prematurely exit (at least not without using tcl in the console and walking through the walls/floor/ceiling). As far as the script, there are probably several viable approaches. Here are a few methods. Please be aware that I have not tested them nor am 100% sure of functionality.Method #1 Script #1 on the door ScriptName DoorScript Extends ObjectReference Function CloseAndLock() Self.SetOpen(false) Self.Lock() EndFunction Script #2 on the trigger. Use OnTriggerEnter if placing volume box at the lock point onwards. Use OnTriggerLeave if placing volume box from door to lock point. ScriptName TriggerScript Extends ObjectReference DoorScript Property DS Auto ;custom property needs to be "NAME_OF_SCRIPT Property VARIABLE_NAME Auto" {point this at the door} Bool DoOnce = false Event OnTriggerLeave(ObjectReference akActionRef) If akActionRef == Game.GetPlayer() && DoOnce == false DoOnce = true DS.CloseAndLock() EndIf EndEvent Alternative Script #2 ScriptName TriggerScript Extends ObjectReference ObjectReference Property MyDoor Auto DoorScript DS Bool DoOnce = false Event OnInit() DS = MyDoor as DoorScript EndEvent Event OnTriggerLeave(ObjectReference akActionRef) If akActionRef == Game.GetPlayer() && DoOnce == false DoOnce = true DS.CloseAndLock() EndIf EndEvent What is happening with both versions of script #2 is that when the player leaves the trigger a function is called on the door's script which tells the door to close and lock. Method #2 A single script on the trigger ScriptName TriggerScript Extends ObjectReference ObjectReference Property MyDoor Auto Bool DoOnce = false Event OnTriggerLeave(ObjectReference akActionRef) If akActionRef == Game.GetPlayer() && DoOnce == false DoOnce = true MyDoor.SetOpen(false) MyDoor.Lock() EndIf EndEvent If you want to be sure that the player cannot turn around and pick the door lock and leave, you'll probably have to do some extra stuff. But one thing at a time, right? Link to comment Share on other sites More sharing options...
ArgoTheFurry Posted March 3, 2017 Author Share Posted March 3, 2017 THANK YOU! THANK YOU SO MUCH! I used the second script- short one. I used it on the trigger box and IT WORKED! EXACTLY AS I WANTED IT TO BE IN MY DUNGEON! It's so nice of you that you spend time explaining many things to me, creating and sharing those scripts. I really, really appreciate it. I used the onTriggerEnter, made a nice box with no gaps and pretty close to the door so the player who enters will trigger it quickly but not too quickly to get stuck in a door or something crazy like that :3 The door locked itself with a Novice lock and while I have no idea about scripts I recall it was even mentioned on Creation Kit page, that when you dont specify a lock strength it will lock with a novice one. You helped me so much already I cant expect anything else ;3 I'll try to browse more but so far I havent found any mentioned ways how to lock it with a custom key :3 (not that I wouldnt like bit more help here and there if someone was feeling that generous again) :laugh: Anyway, once again- thanks a lot :) Link to comment Share on other sites More sharing options...
IsharaMeradin Posted March 3, 2017 Share Posted March 3, 2017 SetLockLevel is the function you would need to increase the lock strength beyond novice. However, there may be a way to set the lock strength and designate a key from within the CK. But that is beyond me. Link to comment Share on other sites More sharing options...
ArgoTheFurry Posted March 3, 2017 Author Share Posted March 3, 2017 (edited) SetLockLevel is the function you would need to increase the lock strength beyond novice. However, there may be a way to set the lock strength and designate a key from within the CK. But that is beyond me.yes, I have found the information about this SetStockLevel thingy :3 Now I just need to figure out how to used it :ohmy: #edit I don't know how... but I managed to create a script that did exactly what I wanted... Scriptname LockItPlease extends ObjectReference Event OnInit() SetOpen(false) EndEvent Event OnActivate(ObjectReference akActionRef) int aiLockLevel = self.GetLockLevel() if(aiLockLevel == 1 || aiLockLevel == 0) self.SetLockLevel(255) endif EndEvent ObjectReference Property NewProperty Auto That's what I did... I actually managed to make it work and I even tested in game- door locked behind me, I turned and it was set to Requires Key. My reaction is probably really dumb but... f yeah, Im proud of myself xD Now I just need to figure out how to assign my particular custom key to this door. I cant do it through the normal "click on door piece" option because then it will be locked in the dungeon. Edited March 4, 2017 by ArgoTheFurry Link to comment Share on other sites More sharing options...
IsharaMeradin Posted March 4, 2017 Share Posted March 4, 2017 Since it is YOUR door, you should know what the lock level is starting out and what you want it to be later. You can probably simply set it to 255 without checking the lock level to begin with. And if you feel you must check the lock level, you can just check that it isn't 255 before setting it to 255. Anyway, congrats on getting a working script. That is always a feel good moment. Link to comment Share on other sites More sharing options...
ArgoTheFurry Posted March 4, 2017 Author Share Posted March 4, 2017 (edited) Sorry, I dont understand your last reply. My problem is not with the lock level. I set it to 255 to be a "requires key" door. But I simply dont know how to assign my dungeon key to that particular door (I cant simply "lock it" in the options menu and assign my custom key because this door has to be open when player goes through the dungeon, so I have to leave it unlocked)- scripts make it close and lock into "requires key" but I have no idea how to assign my key to this door. Alternatively Im looking for another script which would unlock that door if player kills an enemy whos in that room. I tried to make a script with OnDeath function on that enemy but I have no idea how to connect that enemy with that door. #edit I DID IT!!! I just placed another trigger box where player goes after defeating the enemy... and linked it to the door and force it to open. F yeah. Thank you for your help, Ishara. I really appreciate it. Edited March 4, 2017 by ArgoTheFurry Link to comment Share on other sites More sharing options...
ktulhu Posted May 25 Share Posted May 25 On 3/4/2017 at 4:32 AM, ArgoTheFurry said: Help, I'm asking for help in creating a simple script. The script should open the shutters in the morning and close them in the evening. Link to comment Share on other sites More sharing options...
Recommended Posts