atomatic locking door

Post » Sat May 28, 2011 1:14 am

im trying to make a script for a door that locks as soon as you come through it. so that if you unlock it and enter it and then exit it the door is locked again. how do i do this?
User avatar
Jimmie Allen
 
Posts: 3358
Joined: Sun Oct 14, 2007 6:39 am

Post » Sat May 28, 2011 3:37 am

Something like this would work whether you use a key to unlock the door or if picks, scrolls or spells are used. The script can be placed on the door. Since there is no OnActivate check it will not break CellChanged checks in the cell to which it teleports the player. So you do not have to depend on a cell change to initially lock the door set its lock level in the construction set to whatever level you desire. If you want it to be only possible to open with a key, set the lock level to 0 (seriously). For my sample script, I choose a lock level of 50.

Begin anon_DoorLockScript; Local script attached to door (ID).; Re-locks the door after the player passes through it.If ( CellChanged == 1 )    Lock 50endifEnd anon_DoorLockScript

User avatar
Olga Xx
 
Posts: 3437
Joined: Tue Jul 11, 2006 8:31 pm

Post » Sat May 28, 2011 12:54 am

im trying to make a script for a door that locks as soon as you come through it. so that if you unlock it and enter it and then exit it the door is locked again. how do i do this?


This is a script i knocked up for a re-locking safe for one of my own mods. With basic scripting knowledge, you should be able to tailor it for your project. Credit appreciated ;)


***************************************
begin alx_s_door_auto_relock_scrpt

short activate_count
float relock_timer

DontSaveObject

if ( menumode == 1 )
return
endif

;This part allows the player to open the door if they pick the lock or have
;the key in their inventory.
if ( GetLocked == 0 )
if ( OnActivate == 1 )
if ( activate_count < 2 )
set activate_count to ( activate_count + 1 )
endif
Activate
endif
else
if ( OnActivate == 1 )
if ( Player->GetItemCount, "alx_s_manor_key01" >= 1 )
Activate
set activate_count to ( activate_count + 1 )
else
Activate
endif
endif
endif

;This section relocks the door once it's closed
if ( activate_count == 2 )
if ( relock_timer < 2 )
set relock_timer to ( relock_timer + GetSecondsPassed )
elseif ( relock_timer >= 2 )
Lock, 100
PlaySound3D, "Open Lock"
set activate_count to 0
set relock_timer to 0
endif
endif

end
***************************************
User avatar
Mélida Brunet
 
Posts: 3440
Joined: Thu Mar 29, 2007 2:45 am

Post » Sat May 28, 2011 2:57 am

Ok, that is cool. As an aside question: can you make a door (chest/urn whatever) re-arm a trap after you have gotten into it?

ST
User avatar
Daniel Lozano
 
Posts: 3452
Joined: Fri Aug 24, 2007 7:42 am

Post » Fri May 27, 2011 6:41 pm

thanks im gonna try the simple one first but if that doenst work ill try the more complex one.
User avatar
Kari Depp
 
Posts: 3427
Joined: Wed Aug 23, 2006 3:19 pm

Post » Sat May 28, 2011 2:40 am

If you want it to be only possible to open with a key, set the lock level to 0 (seriously).


This is not good advice, as anyone with a Fenrick's Doorjam spell can open your "key only" door with a lock pick by simply increasing the lock level to 10 and then picking the lock. A lock level of 0 is something of a bug. Intentionally using a bug to get your mod to work is never wise. To make the door open only with a key, the script needs to be written to recognize when the player has a copy of the correct key.

As to the question about traps, sadly no. There is a script function to set a lock level, but no script function to set a trap level. And since trap information is reference data, it isn't even possible to use the PlaceItem, PlaceItemCell or PlaceAtMe functions to replace with a new copy. The new copy would be untrapped as each of those functions use default master object data which doesn't include reference data.
User avatar
Stephy Beck
 
Posts: 3492
Joined: Mon Apr 16, 2007 12:33 pm

Post » Fri May 27, 2011 7:07 pm

i did not realize that you could still open the door if it was set to lock level 0 thanks for informing me
User avatar
jess hughes
 
Posts: 3382
Joined: Tue Oct 24, 2006 8:10 pm

Post » Fri May 27, 2011 10:37 pm

You already have a script for an automatically relocking door. If you want one for a door that automatically relocks AND needs a specific key, I wrote one that should do the trick.

Begin Relocking_doorShort KeyUsedIf ( CellChanged == 1 )	Lock 20	Set KeyUsed to 0EndifIf ( OnActivate == 1 )	Activate	If ( GetLocked == 0 )		Set KeyUsed to 1	EndifElseif ( KeyUsed == 0 )	If ( GetLocked == 0 )		Messagebox "The door has a magical lock and can only be unlocked by the correct key."		Lock 20	EndifEndifEnd


It doesn't need to bother checking if the player has the correct key because the game engine handles that for it. That makes it useful as a generic script because it can be used with numerous doors without customizing it. The script works based on the fact that a lockpick unlocks a door without activating it while a key only works when the door is activated. So the script simply verifies that the unlock and activate occur on the same frame (which indicates the correct key was used) or else it relocks the door. As soon as the door is unlocked with the correct key, the flag variable "KeyUsed" is turned on to prevent the door from automatically relocking itself while the player is nearby.

However, when the player leaves and returns, the door is relocked and the flag is reset, so the door becomes "key only" once again.


[edit] changed variable name DoOnce to KeyUsed,
User avatar
Nikki Morse
 
Posts: 3494
Joined: Fri Aug 25, 2006 12:08 pm

Post » Fri May 27, 2011 10:02 pm

However, when the player leaves and returns, the door is relocked and the flag is reset, so the door becomes "key only" once again.


That is awesome! This little gem of a script should be added into the "scripting for dummies" if it is not already ;)

ST
User avatar
Benji
 
Posts: 3447
Joined: Tue May 15, 2007 11:58 pm

Post » Sat May 28, 2011 3:17 am

That is awesome! This little gem of a script should be added into the "scripting for dummies" if it is not already ;)


Thanks. Scripting for dummies does have an example script for a chest that relocks itself every 10 seconds, but to the best of my knowledge, there's nothing explaining how to ensure the correct key is used with a door or container without needing a custom script containing the key ID.
User avatar
Misty lt
 
Posts: 3400
Joined: Mon Dec 25, 2006 10:06 am

Post » Fri May 27, 2011 11:15 pm

I really like this script :)

I would like to try and get a variation of it working though - I have a building complex that I would like to gradually open up but instead of having 5 different keys to carry around I've been trying to adjust this script so that depending on the journal entry the same key will unlock multiple doors but only at different stages of the quest

this would mean having 5 different scripts - one for each different section of the complex but at least I don't have to carry 5 different keys around anymore

However I'm having difficulty working out how to do the script I tried

Begin Relocking_doorShort KeyUsedIf ( CellChanged == 1 )	Lock 20	Set KeyUsed to 0EndifIf [ GetJournalIndex "CT_Access" < 1 ]         Messagebox "Only the correct key will open this door."         ReturnEndifIf ( onactivate == 1 )	Activate	If ( GetLocked == 0 )		Set KeyUsed to 1	EndifElseif ( KeyUsed == 0 )	If ( GetLocked == 0 )		Messagebox "The door has a magical lock and can only be unlocked by the correct key."		Lock 20	EndifEndifEnd


But when I was a cell away from my complex I ended up with the messge box popping up 3X and not disappearing

Am just wondering what I am doing wrong - and if by putting a condition up front whether that means the door will now be able to be picklocked if the first condition is not met?
User avatar
Umpyre Records
 
Posts: 3436
Joined: Tue Nov 13, 2007 4:19 pm

Post » Fri May 27, 2011 7:50 pm

Worse - you put your messagebox under a condition that is ALWAYS true, until you update your journal, and does not depend on whether you want to open the lock or not. In fact, the box pops up not 3 but hundreds of times, only newer ones stumble the older ones away faster than you notice. Put the condition inside the OnActivate block.

...and is it logical to point that the player should have the correct key even though he may already have THE SAME KEY, only on an earlier stage?
User avatar
Gisela Amaya
 
Posts: 3424
Joined: Tue Oct 23, 2007 4:29 pm

Post » Fri May 27, 2011 6:36 pm

Worse - you put your messagebox under a condition that is ALWAYS true, until you update your journal, and does not depend on whether you want to open the lock or not. In fact, the box pops up not 3 but hundreds of times, only newer ones stumble the older ones away faster than you notice. Put the condition inside the OnActivate block.

...and is it logical to point that the player should have the correct key even though he may already have THE SAME KEY, only on an earlier stage?


Thanks Kir about an hour after posting I realized that I should have put the condition inside the OnActivate section

As for the key - through Dialogue they are told that they now have access to a new area and that their key will be upgraded - um - actually nothing happens to the key just a journal entry is posted - hence my wanting a script that could prevent the palyer from opening the door even if they have the correct key but have not yet met the journal entry condition.

I tried rewriting the script to allow for trying a door before getting the key - i wanted a message box to appear when the door is activated to alert the player that they need the correct key or permission to enter - however the messagebox is not appearing - if someone can offer some advice or point out what I am doing wrong I'd much appreciate it :)

Begin CT_Passkey;Based on an original script by ToccattaShort KeyUsedShort CheckaccessIf ( CellChanged == 1 )	Lock 20	Set KeyUsed to 0	Set Checkaccess to 0EndifIf ( Checkaccess==0 )	ReturnEndifIf ( onactivate == 1 )	Set Checkaccess to 1Endif[If ( Checkaccess==1 )	If [ GetJournalIndex "CT_Access" < 1 ]		If ( GetLocked == 1 )			Messagebox "Dunhaven staff and approved visitors only."			Set Checkaccess to 0		Endif	Endif[Elseif ( GetLocked == 0 ) ; Prevents forced entry	Messagebox "This door resists your attempts to open it."	Lock 20	Set Checkaccess to 0EndifIf [ GetJournalIndex "CT_Access" >= 1 ]	Activate	If ( GetLocked == 0 )		Set KeyUsed to 1		Set Checkaccess to 0	EndifElseif ( KeyUsed == 0 )	If ( GetLocked == 0 )		Messagebox "This door resists your attempts to open it without the correct key."		Lock 20		Set Checkaccess to 0	EndifEndifEnd


Nevermind after a marathon effort which included many attempts where as soon as the journal was updated and i entered the cell i was instantly transported to the building - I think that happened from activating the door before the journal was updated and then when reentering the cell zoom

I finally got it to work

Begin CT_Passkey;Based on an original script by ToccattaShort KeyUsedIf ( CellChanged == 1 )	Lock 20	Set KeyUsed to 0	EndifIf ( OnActivate == 1 ) 	If ( GetJournalIndex "CT_Access" >= 1 )		ActivateElse		Messagebox "Authorized access only."		Playsound3d "Door Latched Two Open"		If ( GetLocked == 0 )			Set KeyUsed to 1		Endif	EndifElseif ( KeyUsed == 0 )	If ( GetLocked == 0 )		Messagebox "This door resists your attempts to open it without the correct key."		Lock 20	Endif	Endif		End

User avatar
James Smart
 
Posts: 3362
Joined: Sun Nov 04, 2007 7:49 pm

Post » Sat May 28, 2011 5:27 am

wow i just decided to check on the thread again for the first time in months and was suprised to see how much it took off. though reading through it i was wondering if the last script is completely working?
User avatar
Ashley Tamen
 
Posts: 3477
Joined: Sun Apr 08, 2007 6:17 am

Post » Fri May 27, 2011 8:36 pm

I tried entering the following script:

Begin CT_Passkey

;Based on an original script by Toccatta

Short KeyUsed

If ( CellChanged == 1 )
Lock 20
Set KeyUsed to 0
Endif

If ( OnActivate == 1 )
If ( GetJournalIndex "CT_Access" >= 1 )
Activate
Else
Messagebox "Authorized access only."
Playsound3d "Door Latched Two Open"
If ( GetLocked == 0 )
Set KeyUsed to 1
Endif
Endif

Elseif ( KeyUsed == 0 )
If ( GetLocked == 0 )
Messagebox "The door groans and squeaks as you attempt to open it. You stop pushing for fear of breaking the door. You need to find the right key!" "Ok"
Lock 20
Endif
Endif

End
he script would not save properly
User avatar
Michelle Smith
 
Posts: 3417
Joined: Wed Nov 15, 2006 2:03 am

Post » Fri May 27, 2011 6:38 pm

What error did you get?
User avatar
Clea Jamerson
 
Posts: 3376
Joined: Tue Jun 20, 2006 3:23 pm

Post » Sat May 28, 2011 1:05 am

I got a message saying that the endif sequences were not functioning. I'm trying a different mod of that script.
User avatar
Auguste Bartholdi
 
Posts: 3521
Joined: Tue Jun 13, 2006 11:20 am

Post » Sat May 28, 2011 9:11 am

I got a message saying that the endif sequences were not functioning. I'm trying a different mod of that script.

not necessary. you just missed an endif.
User avatar
Nikki Lawrence
 
Posts: 3317
Joined: Sat Jul 01, 2006 2:27 am

Post » Sat May 28, 2011 3:51 am

not necessary. you just missed an endif.

Where?

Begin CT_Passkey        ;Based on an original script by Toccatta        Short KeyUsed        If ( CellChanged == 1 )        Lock 20        Set KeyUsed to 0     Endif        If ( OnActivate == 1 )         If ( GetJournalIndex "CT_Access" >= 1 )            Activate        Else            Messagebox "Authorized access only."            Playsound3d "Door Latched Two Open"            If ( GetLocked == 0 )                Set KeyUsed to 1            Endif        Endif            Elseif ( KeyUsed == 0 )        If ( GetLocked == 0 )            Messagebox "The door groans and squeaks as you attempt to open it. You stop pushing for fear of breaking the door. You need to find the right key!" "Ok"            Lock 20        Endif     Endif    End

User avatar
Benji
 
Posts: 3447
Joined: Tue May 15, 2007 11:58 pm

Post » Fri May 27, 2011 6:59 pm

my mistake, the lack of formatting and consistency tricked my eyes.

perhaps he doesn't have a journal entry for CT_Access?
User avatar
Kortknee Bell
 
Posts: 3345
Joined: Tue Jan 30, 2007 5:05 pm

Post » Sat May 28, 2011 12:47 am

I had another journal entry in it's place. It did't work. I had adjusted all things that needed adjusting, like door type, journal entry, everything.
User avatar
Suzy Santana
 
Posts: 3572
Joined: Fri Aug 10, 2007 12:02 am


Return to III - Morrowind