Jump to content

Script to Lock door to require a key


emallson

Recommended Posts

Right now I have the following Script that I use to close and lock a door when the player goes through a (slightly modified) TriggerOnActivateTrigger. It is based off of the PinkertonDoorUnlockSwitchScript in Fallout3.esm.

 

scn Vault113UnlockSwitchSCRIPT

ref MyLink
short wasActivated	;sets game mode block to run


begin OnTriggerEnter player
if IsActionRef player == 1
	set myLink to getLinkedRef
	
	activate myLink
	set wasActivated to 1	

endif
end

begin gameMode

if wasActivated  == 1
		set myLink to getLinkedRef

		if myLink.getLocked ==0
			MyLink.Lock 255
		endif
endif
end

 

It's probably not the best way to do it (being a hackjob), but it works. But my problem is that my key (v113finalkey) will not unlock it because it is never registered to the door.

 

The door starts out unlocked. When the player goes through, the door is closed and locked behind them. In the room they enter, there is a Very Easy chest with the key, some weapons, and some caps.

 

How can I register the key to the door?

 

I've come up with an alternative that might work. Simply hiding/deleting the unlocked door and unhiding/creating the locked one. Is that the way to go? Is there even a setKey type of function?

Link to comment
Share on other sites

I'm not aware of such a function...

But why don't you just set the door (or register it) to 'Needs a key' and make sure it is unlocked after it.

Then let it lock it to 255 again with your recent script, as you already did.

 

The adjustment to your trigger-script would be to add a OnLoad block which will run once when you enter the cell for the first time.

 

short unlocked

Begin OnLoad
       if unlocked == 0
               set myLink to getLinkedRef
               mylink.unlock
               set unlocked to 1
       endif
End

 

 

Next to that, you could always attach a script to the door that it will unlock when you activate the door, if you got the key....

Link to comment
Share on other sites

Ah I see. Good thinking. I tried it out and it worked perfectly! Here's the new script.

 

scn Vault113UnlockSwitchSCRIPT

ref MyLink
short wasActivated	;sets game mode block to run
short unlocked

begin OnLoad
if unlocked == 0
	set myLink to getLinkedRef
	mylink.unlock
	set unlocked to 1
endif
end

begin OnTriggerEnter player
if wasActivated == 0
	if IsActionRef player == 1
		set myLink to getLinkedRef
	
		activate myLink
		myLink.playsound3d DRSVaultVerticalRusty01Close
		set wasActivated to 1	

	endif
endif
end

begin gameMode

if wasActivated  == 1
		set myLink to getLinkedRef

		if myLink.getLocked == 0
			MyLink.Lock 255
			set wasActivated to 2
		endif
endif
end

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...