» 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