Need Help With a Script (door locking)

Post » Tue Mar 15, 2011 12:22 am

I made a house mod and have given myself my own bedroom. However, I want to stop other NPC's entering and need to know if I can lock the door.

I have set the door to player owned and have put a hard lock on it, but my problem is this: when I enter the door, it remains unlocked, even when I close it. Other NPC's wander in all the time and so do enemies when I run from them and into my house.

I don't want to mess about with setting NPC's to not walk in my room, in fact, I want them to chase me around the place when I annoy them lol, but I need a safe zone. I need to basically lock the door when I enter so they can't get to me.

So does anyone know how I'd even begin to make a door lock? And what script I'd need?
User avatar
danni Marchant
 
Posts: 3420
Joined: Sat Oct 07, 2006 2:32 am

Post » Mon Mar 14, 2011 4:52 pm

Set the door lock to "Needs A Key" but don't place the key in the game. As long as the door is Player owned, you won't need a key to go through it no matter how strong the lock is. This will effectively keep everyone else out. If you want companions to be able to enter with you, set the ownership to PlayerFaction.
User avatar
Pants
 
Posts: 3440
Joined: Tue Jun 27, 2006 4:34 am

Post » Tue Mar 15, 2011 3:18 am

Set the door lock to "Needs A Key" but don't place the key in the game. As long as the door is Player owned, you won't need a key to go through it no matter how strong the lock is. This will effectively keep everyone else out. If you want companions to be able to enter with you, set the ownership to PlayerFaction.


Thanks but it didn't work unfortunately :(

When I opened the door and closed it behind me, the NPC's who were chasing me still opened it. I think it has something to do with the fact that when you open a door, it stays open. So when I closed it, it didn't lock.

I hope there's a workaround as it is annoying. Thanks for trying though.
User avatar
alicia hillier
 
Posts: 3387
Joined: Tue Feb 06, 2007 2:57 am

Post » Mon Mar 14, 2011 5:38 pm

Thanks but it didn't work unfortunately :(

When I opened the door and closed it behind me, the NPC's who were chasing me still opened it. I think it has something to do with the fact that when you open a door, it stays open. So when I closed it, it didn't lock.

I hope there's a workaround as it is annoying. Thanks for trying though.


If you have the key in your inventory when you go through the door, it will be unlocked and stay unlocked. Make a new key for the door to require, but don't place it in game. Also try loading a clean save. If you don't have a recent enough save, replace the door itself and set it up as described. I use this setup for my own house mod and have never had any trouble.
User avatar
Angel Torres
 
Posts: 3553
Joined: Thu Oct 25, 2007 7:08 am

Post » Tue Mar 15, 2011 12:53 am

If you have the key in your inventory when you go through the door, it will be unlocked and stay unlocked. Make a new key for the door to require, but don't place it in game. Also try loading a clean save. If you don't have a recent enough save, replace the door itself and set it up as described. I use this setup for my own house mod and have never had any trouble.


Well, I did as you said and made sure not to place the key in game. I set the door to only be opened by player also. So, when I opened the door, closed it behind me and waited for 1 minute, I found one of my NPC's who stays in the house walk through the door. Even though I closed it.

I'm guessing that when the door is closed, it is NOT locked. Is there a way to script it or another method to make the door lock once it is closed?

It's an interior door btw, which simply opens without loading into another cell.
User avatar
Harry Hearing
 
Posts: 3366
Joined: Sun Jul 22, 2007 6:19 am

Post » Tue Mar 15, 2011 3:40 am

bump. Sorry for the bump, I just need to get this right, please help me.
User avatar
xemmybx
 
Posts: 3372
Joined: Thu Jun 22, 2006 2:01 pm

Post » Mon Mar 14, 2011 12:58 pm

You can write a script to toggle the door's lock state using the functions: GetLocked, Lock and Unlock. Use it on an activator near the door. Consider using a long rod-like activator so that it sticks out of the doorway on both sides. Use an OnActivate script and make sure to use GetActionRef so that the script only works for the player.
User avatar
Klaire
 
Posts: 3405
Joined: Wed Sep 27, 2006 7:56 am

Post » Tue Mar 15, 2011 2:06 am

You can write a script to toggle the door's lock state using the functions: GetLocked, Lock and Unlock. Use it on an activator near the door. Consider using a long rod-like activator so that it sticks out of the doorway on both sides. Use an OnActivate script and make sure to use GetActionRef so that the script only works for the player.


I looked at the Lock and Unlock pages on the elderscrolls wiki pages yet they confused me.

Vince, I know you do know how to make a lock as your mountain cabin has one. Will you do the decent thing and copy and paste the script here so it is clear just exactly how you do it?
User avatar
SexyPimpAss
 
Posts: 3416
Joined: Wed Nov 15, 2006 9:24 am

Post » Mon Mar 14, 2011 8:42 pm

Vince, are you going to reply?
User avatar
Wane Peters
 
Posts: 3359
Joined: Tue Jul 31, 2007 9:34 pm

Post » Tue Mar 15, 2011 1:27 am

Rowdy, I know it's been a month since you posted; anyway, here are two scripts you can use.
The first relocks an autoclosing door. The second says it is
for display cases, but will work on animated doors too. Make sure that persistent reference is checked
in the object edit window of the CS for the intended door.
Both scripts have full notes within and shouldn't be a prob for you to adapt
for your own uses.
I have playtested the first script, i know it will work like you want.
An irate NPC shouldn't be able to get in with the door locked.
(unless you gave him a copy of the scripts key!)

Here they are. Enjoy.
Death Ohwon

ScriptName 000estateAutoClosingLockingDoorscriptA

;This is a script for a key locked animated door.
;This script avoids messagebox display ingame.
;Key used here is ID a000estatemasterkeyPC, and door
;MUST use this key in door's CS reference edit.
;If you don't have key, will get message "needs the key".
;If you have key, will get message "unlocking...".
;Door now opens, and will close and relock automatically. Repeat.
;Note that if you close door manually it does NOT relock.
;You can open the door again while it is NOT locked.
;Door WILL relock next time it closes automatically.
;This is useful if you need to wait for a NPC or Companion to
;follow you in. The door will relock after they enter (on auto close).
;To set close delay time, alter the "set doorTimerA to x" line
;to the desired delay time equals "x".
;To change key used, set unic door ID and set key in CS,
;then change key ID after getitemcount functions in this script.
;And don't forget to rename this script after changes.
;Then apply new script to the new door.
;This script for The Island Estate mod.

float doorTimerA ;the door autoclose timer
short closeDoorA ;to check door state open or closed
ref mySelf ;a reference to the case itself

Begin GameMode
;this section for autoclose timing and locking
if closeDoorA == 1
if doorTimerA > 0
set doorTimerA to doorTimerA - getSecondsPassed
elseif GetOpenState == 1 ; if the door is still open
SetOpenState 0 ; close the door
set closeDoorA to 0
lock 100
endif
endif
End

begin OnActivate ;And, when we activate the case,
set mySelf to GetSelf ;Reference mySelf is set to the case

if GetOpenState == 3 ; if the door is closed

set doorTimerA to 4 ;change this number to desired autoclose delay.
set closeDoorA to 1
endif

if IsActionRef Player == 1 && mySelf.GetOpenState == 3 ;and the program checks if
;it is the player that activated it
;Now if the container is locked and the player has
; the key... (GetItemCount returns the number of items(in our case keys) the
; player has, so if the number is greater than 0 that means the player has
; the key).
if mySelf.GetLocked ==1 && Player.GetItemCount a000estatemasterkeyPC > 0

;then unlock
mySelf.UnLock

;and give a message that the door has been unlocked
message " Unlocking..."

;and then open
mySelf.Activate Player


;But if the door is locked and the player doesn't have a key,
elseif mySelf.GetLocked == 1 && Player.GetItemCount a000estatemasterkeyPC == 0

;then tell him he needs a key to unlock
Message " You need the key."

;And if the door is unlocked and the player doesn't have the key,

endif
endif
;And if the door is unlocked (key shouldn't matter here)
; and/or door is closed manually (which leaves it closed, unlocked),
if mySelf.Getlocked == 0
myself.Activate Player

endif
End
---------------------------------------------------------------
ScriptName 000estateLockUnlockwithmasterkeyScript01

;This is the script to unlock and lock the display cases
;locked with a000estatemasterkeyPC, the PCs master key to
;the estate. The key will unlock the case to open and relock
;the case after manual close. Remember that these cases are
;door objects in the CS. So this script should work on doors.
;this script is specific to the above key item, so any door/case
;this script is applied to will have to use this same key.
;Change the above key item to use a different key in another script.
;This script for The Island Estate mod.

;The way it will work ingame. No damned message boxes, just
;texts in the top left of the playscreen.
;If the case is locked and needs a key, if you don't have the key
;you get "This case needs a key" message. IF you have key case unlocks
;and opens you get "The case unlocks" message. Next case activation closes
;the case. Activate case third time and case locks and remains closed, you get
;"You locked the case" message. Next time activating and you start from the
;top again.

;a reference to the case itself
ref mySelf

;And, when we activate the case,
begin OnActivate

;Reference mySelf is set to the case
set mySelf to GetSelf

;and the program checks if it is the player that activated it
if IsActionRef Player == 1 && mySelf.GetOpenState == 3

;Now if the container is locked and the player has
; the key... (GetItemCount returns the number of items(in our case keys) the
; player has, so if the number is greater than 0 that means the player may have
; the key to the case)
if mySelf.GetLocked ==1 && Player.GetItemCount a000estatemasterkeyPC > 0

;then unlock the case
mySelf.UnLock

;and give a message that the case has been unlocked
message " You unlock the case with a key."

;and then open the case
mySelf.Activate Player

;and if not, check if the case is not locked
; and the player does have the key
elseif mySelf.GetLocked == 0 && Player.GetItemCount a000estatemasterkeyPC > 0

;then the player opens the case
; or lock it
mySelf.Lock 100
Message " You lock the case with a key."
PlaySound DRSLocked

;But if the case is locked and the player doesn't have a key,
elseif mySelf.GetLocked == 1 && Player.GetItemCount a000estatemasterkeyPC == 0

;then tell him he needs a key to unlock
Message " You need a key to unlock this case."

;And if the case is unlocked and the player doesn't have the key,

endif
else
mySelf.Activate Player
endif
end
User avatar
X(S.a.R.a.H)X
 
Posts: 3413
Joined: Tue Feb 20, 2007 2:38 pm

Post » Tue Mar 15, 2011 3:17 am

Here is a much shorter script that will do what you want. Just place this script on your door. If the door isn't a load-door, there is some more code that should be written, but since it's a house mod I assume it's a load door.

ScriptName OnlyPCDoorScriptref activatorBegin OnActivate	set activator to GetActionRef	Lock 100	if (activator == player || activator.GetInFaction PlayerFaction == 1)		; should work for the player and any followers		Unlock		Activate activator, 0			endifEnd

User avatar
Richus Dude
 
Posts: 3381
Joined: Fri Jun 16, 2006 1:17 am

Post » Mon Mar 14, 2011 9:32 pm

Doors also have a 'Minimal Use' attribute.

The WIKI says:
http://cs.elderscrolls.com/constwiki/index.php/Door
User avatar
Talitha Kukk
 
Posts: 3477
Joined: Sun Oct 08, 2006 1:14 am

Post » Tue Mar 15, 2011 4:31 am

Doors also have a 'Minimal Use' attribute.

The WIKI says:
http://cs.elderscrolls.com/constwiki/index.php/Door
I haven't ever tested it, but I think selecting 'Minimal Use' will cause following NPCs to likewise not use the door - if I'm reading the Wiki correctly, that is.
User avatar
Ashley Clifft
 
Posts: 3468
Joined: Thu Jul 26, 2007 5:56 am

Post » Tue Mar 15, 2011 2:52 am

The main reason the two scripts above are long as they are (other that the notes, of course)
was to avoid the vile MessageBox window.

You could also strip out the Message function lines and slim them up some,
I can't remember if this allows the MessageBox to pop up, if not,
no spam at all!

Reneer, I haven't tried your script yet, but looks good.
I believe I'll steal it for meself; Thanks!
User avatar
priscillaaa
 
Posts: 3309
Joined: Sat Dec 30, 2006 8:22 pm

Post » Mon Mar 14, 2011 8:14 pm

I haven't ever tested it, but I think selecting 'Minimal Use' will cause following NPCs to likewise not use the door - if I'm reading the Wiki correctly, that is.

This is my understanding, too.
And I have not tested it either.
User avatar
Hella Beast
 
Posts: 3434
Joined: Mon Jul 16, 2007 2:50 am


Return to IV - Oblivion