se7enraven Posted December 21, 2021 Share Posted December 21, 2021 Hello! I am requesting a script which removes the key used to unlock it, or posts a message. So basically it is a regular door, but removes the key when opened or posts a specific message if the player does not have the key. I am working with the following conditions: -"DoorA" is an animated door load door. It is locked and requires "KeyA" to unlock. -If the player does not have "KeyA", door will remained locked and post "MessageNoGo". -if the player has "KeyA", "DoorA" will unlock and remove "KeyA" from the player's inventory. Once open, player will transport to linked cell. -"DoorA" will lock again after player transport, and requires another "KeyA" to unlock. Other info: -This script must be applied to different doors. ("DoorA", "DoorB", etc.) -Each door requires a different key. ("KeyA", "KeyB", etc.) I thank you for your time and reading this, and if the script is used, I promise to credit the script author on my mod release. -Peace! Link to comment Share on other sites More sharing options...
Zorkaz Posted December 21, 2021 Share Posted December 21, 2021 There's a thousand ways to do this but there's one with the key being a misc item. (Useful for keycards) You could put this on the door and don't forget to fill out the properties afterwards MiscObject Property TheKey Auto Message Property NoKeyMsg Auto Event OnActivate (ObjectReference AkActionRef) If AkActionRef == Game.Getplayer() If Game.Getplayer().geitemcount (TheKey) > 0 Self.unlock() Game.Getplayer().removeitem (TheKey,1) Else NoKeyMsg.show() Endif Endif EndEventAdditionally the same script but with a timer so the door will lock itself. MiscObject Property TheKey Auto Message Property NoKeyMsg Auto Event OnActivate (ObjectReference AkActionRef) If AkActionRef == Game.Getplayer() If Game.Getplayer().geitemcount (TheKey) > 0 Self.unlock() StartTimer (5, 10) Game.Getplayer().removeitem (TheKey,1) Else NoKeyMsg.show() Endif Endif EndEvent Event OnTimer (Int AiTimerID) If AiTimerID == 5 Self.lock() Endif EndEvent Link to comment Share on other sites More sharing options...
LarannKiar Posted December 21, 2021 Share Posted December 21, 2021 The script posted above will work flawlessly but note that if you use MiscItem or MiscObject instead of Key form, you won't see the [Requires: my Key] button prompt when you approach the door. Link to comment Share on other sites More sharing options...
Zorkaz Posted December 21, 2021 Share Posted December 21, 2021 You could also use Key Property TheKey Auto instead of MiscObject Property TheKey Auto Link to comment Share on other sites More sharing options...
Zorkaz Posted December 21, 2021 Share Posted December 21, 2021 If you're going with a key maybe try this Key Property TheKey Auto Message Property NoKeyMsg Auto Event OnActivate (ObjectReference AkActionRef) If AkActionRef == Game.Getplayer() If Game.Getplayer().geitemcount (TheKey) > 0 StartTimer (5, 10) Game.Getplayer().removeitem (TheKey,1) Else NoKeyMsg.show() Endif Endif EndEvent Event OnTimer (Int AiTimerID) If AiTimerID == 5 Self.lock() Endif EndEvent Link to comment Share on other sites More sharing options...
se7enraven Posted December 22, 2021 Author Share Posted December 22, 2021 Hey guys! Thanks for the reply! I tried using the script: Scriptname FXMscriptMEtroTrainTeleport extends ObjectReferenceKey Property TheKey AutoMessage Property NoKeyMsg AutoEvent OnActivate (ObjectReference AkActionRef)If AkActionRef == Game.Getplayer()If Game.Getplayer().geitemcount (TheKey) > 0StartTimer (5, 10)Game.Getplayer().removeitem (TheKey,1)ElseNoKeyMsg.show()EndifEndifEndEventEvent OnTimer (Int AiTimerID)If AiTimerID == 5Self.lock()EndifEndEvent I get these errors: Compiling "FXMscriptMEtroTrainTeleport"...C:\Users\se7enraven\AppData\Local\Temp\PapyrusTemp\FXMscriptMEtroTrainTeleport.psc(8,20): geitemcount is not a function or does not existC:\Users\se7enraven\AppData\Local\Temp\PapyrusTemp\FXMscriptMEtroTrainTeleport.psc(8,41): cannot compare a void to a int (cast missing or types unrelated)No output generated for FXMscriptMEtroTrainTeleport, compilation failed.Batch compile of 1 files finished. 0 succeeded, 1 failed.Failed on FXMscriptMEtroTrainTeleport Thank you for your time! Link to comment Share on other sites More sharing options...
Zorkaz Posted December 22, 2021 Share Posted December 22, 2021 My badgeitemcount should be getitemcount Link to comment Share on other sites More sharing options...
se7enraven Posted December 22, 2021 Author Share Posted December 22, 2021 So, the message posts when no key is in inventory, which is good. When the key IS in the inventory, the message still posts, but the door opens and works anyway. The only other problem is, the door does not lock again. I am wondering if maybe I should attack this problem in a different way? The idea was to have a metro train system, and the key (metro pass) is required to access the trains to move from station to station. I am starting to wonder if maybe I should have the train "door" just be an activator, and teleports the player to a marker in another cell? Being that you are an expert at this (I have "The Wilderness" and "Marshlands" installed and playing them) what do you think I should do? I Thank you for your help! Link to comment Share on other sites More sharing options...
LarannKiar Posted December 22, 2021 Share Posted December 22, 2021 When the key IS in the inventory, the message still posts, but the door opens and works anyway. To suppress the "Key has been removed." notification: Game.Getplayer().RemoveItem(TheKey, abSilent = True) The only other problem is, the door does not lock again. I am wondering if maybe I should attack this problem in a different way? Try RegisterForPlayerTeleport(). (I haven't used it in an OnActivate() event but it definitely works with load doors). (...) Event OnActivate (ObjectReference akActionRef) If AkActionRef == Game.Getplayer() RegisterForPlayerTeleport() ; Add this line to your script (...) 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 More sharing options...
se7enraven Posted December 22, 2021 Author Share Posted December 22, 2021 Awesome! I think that did it. It's a little buggy, as sometimes the message still posts, but I can use it. Thank you Zorkaz and LarannKiar for the good work! When the mod is released, I will make sure to add you to the credits. This is what the final script looks like: 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 Game.Getplayer().getitemcount (TheKey) > 0 Game.Getplayer().RemoveItem(TheKey, 1, abSilent = True) Else 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 More sharing options...
Recommended Posts