Jump to content

HELP NVSE Keystroke detection


tequilajusthitme

Recommended Posts

I want to write a script that toggles high jump, and this is where i got to before i realized that the script would run but not detect key strokes- i realize i left out a varriable required to get it to toggle. NVSE is running, and the script does run. Im by no means an experienced modder, so if you have time could you write a script that adds a perk with one keystroke, then removes it when it is tapped again? I feel that I could really use some examples. thanks

ScriptName 00Hotkey08

Short UToggle

Begin OnEquip Player

printc "test1"

if IsKeyPressed 22 != UToggle

set UToggle to IsKeyPressed 22

;Key U is pressed

printc "test2"

if UToggle ;Button pressed

RewardKarma -200

printc "test3"

;Test is function runs

else ;release

RewardKarma -200

printc "test4"

endif

endif

End

the text file is below, complete with indentations

Link to comment
Share on other sites

Let's take a look:

 

ScriptName 00Hotkey08

Short UToggle

Begin OnEquip Player
printc "test1"
if IsKeyPressed 22 != UToggle
	set UToggle to IsKeyPressed 22
	;Key U is pressed
	printc "test2"
	if UToggle ;Button pressed
		RewardKarma -200
		printc "test3"
		;Test is function runs
	else ;release
		RewardKarma -200
		printc "test4"
	endif
endif
End

 

Well, the first problem I notice is here:

 

Begin OnEquip Player

 

This is the mode that occurs very briefly just before the game switches (in gamemode) the object that owns this method. I highly doubt the player can press the U key during this event in an ordinary situation.

 

The rest of it is a bit odd, but not unusual for code. What you mainly need is to change the begin line to something like this:

 

Begin GameMode

 

That should help a bit.

Link to comment
Share on other sites

Let's take a look:

 

ScriptName 00Hotkey08

Short UToggle

Begin OnEquip Player
printc "test1"
if IsKeyPressed 22 != UToggle
	set UToggle to IsKeyPressed 22
	;Key U is pressed
	printc "test2"
	if UToggle ;Button pressed
		RewardKarma -200
		printc "test3"
		;Test is function runs
	else ;release
		RewardKarma -200
		printc "test4"
	endif
endif
End

 

Well, the first problem I notice is here:

 

Begin OnEquip Player

 

This is the mode that occurs very briefly just before the game switches (in gamemode) the object that owns this method. I highly doubt the player can press the U key during this event in an ordinary situation.

 

The rest of it is a bit odd, but not unusual for code. What you mainly need is to change the begin line to something like this:

 

Begin GameMode

 

That should help a bit.

 

Thanks, but the script wont start if i change it to a quest and start it w/ the game. What am i doing wrong? How would you script it?

Thanks for the quick reply!

Link to comment
Share on other sites

I tend to use quest scripts for hotkey detection most of the time, manually specifying the script delay time to about 0.1 seconds, although using a scripted token (unplayable, therefore invisible armour) in the player's inventory is also an easy way to do it, and object scripts are processed every frame.

 

If you haven't already, take a look at my tutorial on detecting keypresses. Hopefully it'll shed some more light on this type of script.

 

P.S. It's best not to prefix editorIDs with numbers, as the GECK's compiler has issues finding them when referenced in a script. By using the GECK's "filter" feature, you can find your own editorIDs so long as they contain a unique string. Otherwise, you can sort by formID to get your forms to the top, and if you must use a prefix just make sure the first character is a letter

 

Cipscis

Link to comment
Share on other sites

  • Recently Browsing   0 members

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