Jump to content

[LE] detect pressed key while reading a book


Archny

Recommended Posts

 

This is because the book is in the player inventory/container, therefore it has no valid ID and the script won't work.

 

 

Ghaunadaur Big thanks man, you helped me find the solution. Although I didn't go for quest since I don't have a good understand of how it works yet, but I went into a slightly different approach.

 

I took the book in question and I added it in a custom cell and then I referenced it into the script, and then I used this ObjectReference to register all keys that I need, then I used this same Object to unregister all keys when the player hits "scape" or "tab" in order to close the book. So here is the final solution.

 

 

 

Scriptname myBookScript extends ObjectReference

ObjectReference Property myBookRef auto

int mNumpad1 = 79
int mNumpad2 = 80
int mNumpad3 = 81
int mScape = 1
int mTab = 15
Event OnRead()
myBookRef.RegisterForKey(mNumpad1)
myBookRef.RegisterForKey(mNumpad2)
myBookRef.RegisterForKey(mNumpad3)
myBookRef.RegisterForKey(mScape)
myBookRef.RegisterForKey(mTab)
EndEvent
Event OnKeyDown(Int KeyCode)
Debug.notification("A registered key has been pressed")
If KeyCode == mNumpad1
Debug.notification("1st option")
elseIf KeyCode == mNumpad2
Debug.notification("2nd option")
elseIf KeyCode == mNumpad3
Debug.notification("3rd option")
EndIf
;==responsable to unregister all registered keys
if keyCode == mScape || keyCode == mTab
myBookRef.UnregisterForAllKeys()
Debug.notification("Book closed, all key unregistered")
EndIf
EndEvent
Thanks to everyone who gave their time to help. Also if you guys find any performance issue with this code please share here.
Edited by Archny
Link to comment
Share on other sites

  • Recently Browsing   0 members

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