Animation Cancellation script i adjusted

TheSponge

Greenhorn
I found a script for AHK that worked well! But as you might know when facing up or down in stardew actions take longer. So i added some simple functionality to adjust to different directions and tools. Mostly the watering can since that takes longer than all the other tools.
Code:
#SingleInstance, Force
#IfWinActive, Stardew Valley
#Persistent
tooladdition := 0
waitframes := 5
; Made for 60 FPS since a tick runs every 1/60 of a second aka 0.016666 in seconds or 16.666 in milliseconds  
SleepForFrames(x) {
    Sleep, x * 16.666
}
; Waitframes for where you are facing, since in stardew actions facing up take longer than sideways
Loop{
    if GetKeyState("S", "P")
            waitframes := 7
        else if GetKeyState("W", "P")
            waitframes := 6
        else if GetKeyState("D", "P")
            waitframes := 5
        else if GetKeyState("A", "P")
            waitframes := 5
}
; What slot you have your watering can in has to set tooladdition to 3 the rest is also up to you
~1::tooladdition := 0
~2::tooladdition := 0
~3::tooladdition := 0
~4::tooladdition := 2
~5::tooladdition := 0
~6::tooladdition := 0
~7::tooladdition := 0
~8::tooladdition := 0
~9::tooladdition := 0
~0::tooladdition := 0
~-::tooladdition := 0
~=::tooladdition := 0
; Change Space to whatever you want the ani cancel key/keys to be
Space::
While GetKeyState("Space", "P") {
    SendEvent, {LButton Down}
    SleepForFrames(1)
    SendEvent, {LButton Up}
    SleepForFrames(waitframes+tooladdition)
    SendEvent, {r Down}{Delete Down}{RShift Down}
    SleepForFrames(1)
    SendEvent, {r Up}{Delete Up}{RShift Up}
}
SleepForFrames(1)
return
The script largely depends on the FPS you are getting. If it seems to cancel the animation earlier than it should. Increase waitframes so that this doesnt happen, remember to do this for every direction!

But sometimes something unpredictable like a tiny lagspike can occur and ruin that action, its only if this happens many times in a row you should change anything.

Edit: Changed
Code:
~W::waitframes := 6
~S::waitframes := 7
~D::waitframes := 5
~A::waitframes := 5
To
Code:
Loop{
    if GetKeyState("S", "P")
            waitframes := 7
        else if GetKeyState("W", "P")
            waitframes := 6
        else if GetKeyState("D", "P")
            waitframes := 5
        else if GetKeyState("A", "P")
            waitframes := 5
}
To get proper prioritising of keys when moving
 
Last edited:
Top