VikingII Posted January 31, 2013 Share Posted January 31, 2013 (edited) I know the way to lock a door by using an activator like in this example, but I want to lock the door every time I close it, and unlock every time I open it only if I have the key. I figured out this kind of script: ScriptName MainDoorClose&Lock Begin OnActivate if MainDoor.GetOpenState == 1 ;when the player closes the door it will be locked MainDoor.SetOpenState 0 MainDoor.lock 0 else MainDoor.GetOpenState == 0 ; when the player tries to open the locked door, it performs the normal check for the key. If ; <----------- the player has the "MainDoorKey" ; <------------ MainDoor gets open else ; <----------- the player has not the "MainDoorKey" ; <------------- ask for a key to be opened endif endif end I don’t know if GECK allows something like this since in vanilla is impossible to drop a key, so there is no need to perform a second check. But could there be ways to set a door to it original state? Edited January 31, 2013 by VikingII Link to comment Share on other sites More sharing options...
prensa Posted January 31, 2013 Share Posted January 31, 2013 (edited) VikingII - Hello! To make the door lock whenever it's shut should be easy, I tried this script which seems to work well: SCN SelfLockingDoorScript Begin gamemode if MainDoor.GetOpenState == 3 MainDoor.lock 0 endif end Give the door a reference name (MainDoor) & set it persistent, set the door lock level & key (if it has one) as normal, attach the script to the door. It's nice & simple, just checks whether the door is shut (animated door shut is 3) & locks it if it is shut. If you've set your door to pickable & you don't have a key then you have to pick the lock again whenever it's shut. If you've set the door to open with a key & you have that key you will unlock it with said key. "I don’t know if GECK allows something like this since in vanilla is impossible to drop a key," To make a droppable key, just make a Misc Item, call it something like SpecialKey, use the key model & set the door to locked but key to none. Then add an onactivate check for the "key" in the player's inventory. Something like this: Begin onactivate ;If the door is open allow it to shut if MainDoor.GetOpenState == 1activate endif ;If the door is closed & the player hasn't got the key allow them to pick the lock if MainDoor.GetOpenState == 3if player.GetItemCount SpecialKey == 0activate endifendif ;If the door is shut but the player has the key open the door. if player.GetItemCount SpecialKey == 1if MainDoor.GetOpenState == 3MainDoor.SetOpenState 1activate endifendif end That will mean the door can still be picked if you have no key (as long as you've set a lock level on the door & not open only with a key), will open if you have the key & you can drop the key. Place it in the door script above the locking script segment. I've just thrown this together on the fly, I've tested it in game & all worked well but obviously I've not done loads of testing on it. :) Hope this helps! Prensa Edited January 31, 2013 by prensa Link to comment Share on other sites More sharing options...
VikingII Posted January 31, 2013 Author Share Posted January 31, 2013 Simple & beautiful like as any script should be and works like a charm! That is exactly what I have been searched for. And thanks for the droppable key advice, I was planning to use a script to remove the key but I think your method feels more natural in game. :thumbsup: Link to comment Share on other sites More sharing options...
prensa Posted January 31, 2013 Share Posted January 31, 2013 VikingII - Hello! Happy to have helped! :) Prensa Link to comment Share on other sites More sharing options...
zombieman00 Posted July 21, 2013 Share Posted July 21, 2013 Thanks VikingII for bringing this up and thank you prensa for those awesome instructions. I used your script to take control of the top corner room of Moiriarty's for some fan fiction I've been working on. I put a lot of furniture and goodies in there, but thanks to all the other mods I have running, random NPCs keep coming in and ruining the party lol. Now I can lock them out completely hahahaha. Thanks again to you both for the awesome scripting instructions. Link to comment Share on other sites More sharing options...
pkleiss Posted July 22, 2013 Share Posted July 22, 2013 If you would like to take it a step further, I have a script for an auto door. This will automatically close and lock a door a set time after the player opens it. No need to close the door... ScriptName DoorScript Float Timer Begin OnLoad ; if the player left the door open the last time he was in here, close it. If GetOpenState == 1 SetOpenState 0 If GetLockLevel > 0 Lock EndIf EndIf End Begin OnActivate Set Timer to 10 ; The door will close and lock itself in 10 seconds. Activate End Begin GameMode If Timer > 0 Set Timer to Timer - GetSecondsPassed ElseIf GetOpenState == 1 SetOpenState 0 Set Timer to 0 If GetLockLevel > 0 Lock EndIf EndIf If GetOpenState == 3 Set Timer to 0 EndIf End Link to comment Share on other sites More sharing options...
Recommended Posts