Jump to content

[LE] detect pressed key while reading a book


Archny

Recommended Posts

Hi Everyone, I'm creating this Skyrim Special Edition mod and I have found a big problem and I hope you guys can help me get through it.

 

Problem: detect if the player has pressed a key like "Numpad1" while reading a book.

 

The idea is:

- in the book there is some options for the player to choose from and each option has a small image related to it and a number too. So while the book is open the player will press a button end choose that option. So pressing Numpad1 would choose option with number 1 and so on. The idea of using MessageBox came in mind but it does not give the option to show images and that is an important part of the mod. And it would be great to know how to close the book and the inventory from that single key press.

 

This is was I already have but it's not working:

 

 

Scriptname myBookScript extends ObjectReference

 

int mNumpad1 = 79
int mNumpad2 = 80
int mNumpad3 = 81
Event OnRead()
RegisterForKey(mNumpad1)
RegisterForKey(mNumpad2)
RegisterForKey(mNumpad3)
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
EndEvent
Thanks in advance
Edited by Archny
Link to comment
Share on other sites

Are you starting the game with SKSE? -- OnKeyDown and RegisterForKey require SKSE to function.

 

Are you starting a new game or using a save where the book in question has not yet been loaded? -- Objects already loaded tend not to recognize changes while new instances will.

Link to comment
Share on other sites

Are you starting the game with SKSE? -- OnKeyDown and RegisterForKey require SKSE to function.

 

Are you starting a new game or using a save where the book in question has not yet been loaded? -- Objects already loaded tend not to recognize changes while new instances will.

 

yes I'm Starting the with skse64_loader, and yes SKSE is working also, I have another scripts that use SKSE and they are working fine.

 

I tried to start a new game but it didn't work either.

Link to comment
Share on other sites

As a test, try using OnInit event to register the keys instead of the OnRead event. It may be that the keys are not getting registered at the point you want since the "book menu" pauses the game normally. If this is indeed the case, there will need to be some "workarounds" put into place to ensure that the keys only trigger the OnKeyDown event when you want rather than at any point after the book is first loaded.

Link to comment
Share on other sites

As a test, try using OnInit event to register the keys instead of the OnRead event. It may be that the keys are not getting registered at the point you want since the "book menu" pauses the game normally. If this is indeed the case, there will need to be some "workarounds" put into place to ensure that the keys only trigger the OnKeyDown event when you want rather than at any point after the book is first loaded.

 

Yah I changed the OnRead event to OnInit but, it didn't work out. Oh man is not being easy

Link to comment
Share on other sites

Also try Debug.Trace and then check the log file. I haven't checked, but it is possible that Notification doesn't work while you're in the book reading menu. So the keys may be getting processed and it is just the notifications that are failing.

 

I changed debug.notification to debug.trace but, it didn't work either. But this error is showing

 

Unable to call RegisterForKey - no native object bound to the script object, or object is of incorrect type

Edited by Archny
Link to comment
Share on other sites

SKSE isn't installed correctly, the most common mistake made, reinstall it...

 

btw to fix any potential mistakes first Skyrim, second Dawnguard, followed by Hearthfire, which leads to Dragonborn. Then to Quote Tony Montana. "Then and only then do you install the SKSE scripts" Overwrite where applicable ON Dawnguard, followed by Hearthfire, which leads to Dragonborn and lastly SKSE.

 

It NOT a matter of just packing Scripts.rar then SKSE. ☺

Link to comment
Share on other sites

SKSE isn't installed correctly, the most common mistake made, reinstall it...

 

btw to fix any potential mistakes first Skyrim, second Dawnguard, followed by Hearthfire, which leads to Dragonborn. Then to Quote Tony Montana. "Then and only then do you install the SKSE scripts" Overwrite where applicable ON Dawnguard, followed by Hearthfire, which leads to Dragonborn and lastly SKSE.

 

It NOT a matter of just packing Scripts.rar then SKSE. ☺

 

My Masters are in the right order already and they are also in the right order for the esp I'm currently working on.

 

And for SKSE not being installed correctly, I would like for you to be more specific, cuz SKSE functions are working fine in my mod, the Scripts are compiling nice and I'm seeing the effects of SKSE functions inside the Game.

 

The way I installed SKESE was:

- files (skse64_1_5_80.dll skse64_loader.exe skse64_steam_loader.dll) where put inside Skyrim folder, same level as the data folder

- Data/Scripts was packed and install via ModManager2

- Data/Scripts/Source all the .psc files were put inside Skyrim Data folder -> inside Source folder -> inside Scripts folder in order for the creation kit to recognize SKSE scripts

 

I'm testing mods by launching skryrim through skse64_loader.exe directly and also though ModOrganizer2 just to be sure, but the results are still the same

 

well if I did something wrong please tell me. Thanks

Link to comment
Share on other sites

Unable to call RegisterForKey - no native object bound to the script object, or object is of incorrect type

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

 

As a workaround, you can put the book reference in a quest alias and assign the script to that. The book will be persistent as long it's held into the alias. The script needs to extend ReferenceAlias then.

 

Make sure to set the quest to 'start game enabled'. Good luck!

Link to comment
Share on other sites

  • Recently Browsing   0 members

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