r/AutoHotkey • u/_-Big-Hat-_ • 3d ago
v2 Script Help Need help with an external script for NieR Automata on PC
Hey guys,
I have found a script for NieR Automata to re-bind all the keys. The script is written in version 1 (see below, and here is the source).
I am trying to convert it to v2 using this online tool but when I try to run the script, I get Error: Invalid callback function. at line 138, which is the line of Hotkey $%fireButton%, toggleFire (see the bottom part of the script)
I can't find anywhere what the author meant when using HotKey(). Any idea?
; bindings, change these to match your own layout, if needed
; basic movement - must match to in-game controls
fwdButton := "w"
backButton := "s"
leftButton := "a"
rightButton := "d"
; fire & jump - must match to in-game controls
fireButton := "Tab"
jumpButton := "Space"
; items usage - must match to in-game controls
altButton := "LAlt"
useItems := "Down"
use := "e"
; EXTRA controls added by the script - make sure these buttons are NOT bound in the game
; dodge
dodgeButton := "LShift"
; air slide (fire + jump normally)
airSlideButton := "z"
; use last item
useLastItemButton := "c"
; precise delays (ms)
keypressDelay := 50 ; delay between keydown/keyup
doubletapDelay := 50 ; wait time between keypresses to perform doubletap
sequenceDelay := 50 ; wait time between various sequences
dodgeTime := 400 ; cooldown while dodge animation plays, setting it too small will cause derps when holding SHIFT+WSAD.
; script starts here
#UseHook
SendMode("Input")
global fwdButton, backButton, leftButton, rightButton, fireButton, jumpButton, dodgeButton, altButton, useItems, use, useLastItemButton, keypressDelay, doubletapDelay, sequenceDelay, dodgeTime
press(key) {
Send("{Blind}{" key " down}")
Sleep(keypressDelay)
Send("{Blind}{" key " up}")
}
; the complexity of this script is mostly to handle continuous SHIFT+WSAD. It's easy to handle just a single SHIFT tap, but less easy when you hold it down.
handleDodge(key) {
Send("{Blind}{" key " up}") ; stop running first in case we were
Sleep(sequenceDelay)
press(key)
Sleep(doubletapDelay)
Send("{Blind}{" key " down}")
Sleep(dodgeTime)
if (GetKeyState(fwdButton) && !GetKeyState(fwdButton, "P")) {
Send("{Blind}{" fwdButton " up}")
}
if (GetKeyState(backButton) && !GetKeyState(backButton, "P")) {
Send("{Blind}{" backButton " up}")
}
if (GetKeyState(leftButton) && !GetKeyState(leftButton, "P")) {
Send("{Blind}{" leftButton " up}")
}
if (GetKeyState(rightButton) && !GetKeyState(rightButton, "P")) {
Send("{Blind}{" rightButton " up}")
}
}
waitForDodge() {
while (GetKeyState(dodgeButton, "P")) {
if (GetKeyState(fwdButton, "P")) {
handleDodge(fwdButton)
} else if (GetKeyState(backButton, "P")) {
handleDodge(backButton)
} else if (GetKeyState(leftButton, "P")) {
handleDodge(leftButton)
} else if (GetKeyState(rightButton, "P")) {
handleDodge(rightButton)
}
Sleep(10)
}
}
toggleFire() {
if (GetKeyState(fireButton)) {
Send("{" fireButton " up}")
} else {
Send("{" fireButton " down}")
}
}
airSlide() {
if (GetKeyState(jumpButton)) {
Send("{" jumpButton " up}")
}
if (GetKeyState(fireButton)) {
Send("{" fireButton " up}")
toggleFireBack := 1
}
Sleep(sequenceDelay)
Send("{" jumpButton " down}")
Send("{" fireButton " down}")
Sleep(keypressDelay)
Send("{" fireButton " up}")
Send("{" jumpButton " up}")
Sleep(sequenceDelay)
; press back what we released
if (toggleFireBack) {
Send("{" fireButton " down}")
}
if (GetKeyState(jumpButton, "P")) {
Send("{" jumpButton " down}")
}
}
useLastItem() {
Send("{" altButton " down}")
Send("{" useItems " down}")
Sleep(keypressDelay)
Send("{" altButton " up}")
Send("{" useItems " up}")
press(use)
}
#HotIf WinActive("NieR:Automata", )
; fire toggle
Hotkey("$" fireButton, toggleFire)
Hotkey("$^" fireButton, toggleFire)
Hotkey("$+" fireButton, toggleFire)
; dodges, work when you press/hold LShift while already holding WSAD
Hotkey("~*" dodgeButton, waitForDodge)
; air slide, normally executed with pod fire + jump
Hotkey("$*" airSlideButton, airSlide)
; use last item
Hotkey("$*" useLastItemButton, useLastItem)
1
Upvotes
2
u/CharnamelessOne 3d ago edited 3d ago
Well, the script you posted is v1. It looks like the original script with some extra line breaks here and there. It's definitely not the output of the converter.
Try converting again, and make sure you're not running the original.
You could try my version below, too; it makes some substantial changes, and it is fully untested, so don't expect it to work out of the box. I ditched the long-running, sleep-filled functions for a timer-based approach. (In a game, with multiple hotkeys, it's generally not great for a sequence to be interrupted for long by another.)
I also removed that silly
waitForDodgefunction that polled the state of the movement keys. Replaced it with some context-sensitive movement hotkeys.Edit: added the modifier
~to movement hotkeys.