Jump to content

Script to remove key on Door Unlock


se7enraven

Recommended Posts

When you are using a real key instead of the misc item, maybe the key is removed before the script starts, resulting in the message being displayed regardless

 

Maybe try

Scriptname FXM:FXMscriptMetroTainDoor02 extends ObjectReference

Key Property TheKey Auto
Message Property NoKeyMsg Auto

Event OnActivate (ObjectReference AkActionRef)
If AkActionRef == Game.Getplayer()
    RegisterForPlayerTeleport() ; Add this line to your script
If self.islocked()
NoKeyMsg.show()
Endif
Endif
EndEvent

Event onPlayerTeleport()
ObjectReference DoorRef = (Self as ObjectReference)
DoorRef.Lock()
    DoorRef.SetLockLevel(254) ; so it will require its Key
UnregisterForPlayerTeleport()
EndEvent

 

Link to comment
Share on other sites

I hope Zorkaz doesn't mind if I rewrote this script:

Scriptname FXM:FXMscriptMetroTainDoor02 extends ObjectReference Const

Key Property myKey Auto Const

Event OnActivate (ObjectReference akActionRef)
	Actor PlayerRef = Game.GetPlayer()	; for optimization
	If akActionRef == PlayerRef
		Int iKeyCount = PlayerRef.GetItemCount(myKey)
		If iKeyCount == 0
			Debug.Notification("I don't have the key.")	; you don't have to create a Message form for a simple message. Of course you can change the text but the quote marks are necessary.
		ElseIf iKeyCount >= 1
			RegisterForPlayerTeleport()
			PlayerRef.RemoveItem(myKey, iKeyCount, abSilent = True)
		EndIf
	EndIf
EndEvent

Event OnPlayerTeleport()
	ObjectReference DoorRef = (Self as ObjectReference)
	DoorRef.Lock()
	DoorRef.SetLockLevel(254)
	UnregisterForPlayerTeleport()
EndEvent
Edited by LarannKiar
Link to comment
Share on other sites

This script works, but the message still posts (Upper left in hud) when teleporting, and all the keys for that type are removed. I would like only a single key to be removed, as the player an purchase multiple keys ("metro pass"). And while I do appreciate the ease of not having to link the same message for every set up, I do like how default messages post in the enter of the screen as opposed to the upper left. Thank you!

Link to comment
Share on other sites

This script works, but the message still posts (Upper left in hud) when teleporting, and all the keys for that type are removed. I would like only a single key to be removed, as the player an purchase multiple keys ("metro pass"). And while I do appreciate the ease of not having to link the same message for every set up, I do like how default messages post in the enter of the screen as opposed to the upper left. Thank you!

 

 

 

Scriptname FXM:FXMscriptMetroTainDoor02 extends ObjectReference Const

Key Property myKey Auto Const
Message Property myMessage Auto Const

Event OnActivate (ObjectReference akActionRef)
	Actor PlayerRef = Game.GetPlayer()	; for optimization
	If akActionRef == PlayerRef
		Int iKeyCount = PlayerRef.GetItemCount(myKey)
		If iKeyCount == 0
			If Self.GetOpenState() == 3 && Self.IsLocked() == 1
				myMessage.Show()
			EndIf
		ElseIf iKeyCount >= 1
			RegisterForPlayerTeleport()
			PlayerRef.RemoveItem(myKey, 1, abSilent = True)
		EndIf
	EndIf
EndEvent

Event OnPlayerTeleport()
	ObjectReference DoorRef = (Self as ObjectReference)
	DoorRef.Lock()
	DoorRef.SetLockLevel(254)
	UnregisterForPlayerTeleport()
EndEvent

 

 

Link to comment
Share on other sites

Everything works well except two "keys" are still removed. I'm not sure if it matters, but the other door does not have the script on it and is located outside the playable area of the cell. I really do appreciate the help and your patience. Thank You!

Link to comment
Share on other sites

  • Recently Browsing   0 members

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