Autohotkey script - spells, normal & power attacks [updated]

Talk about anything related to Legend of Grimrock 2 here.
Post Reply
Koriel
Posts: 1
Joined: Sat Oct 18, 2014 11:16 am

Autohotkey script - spells, normal & power attacks [updated]

Post by Koriel »

So I've managed to get one of the old autohotkey scripts working with Grimrock 2 and the game is much more enjoyable now on hard mode. It seems that the clicks need to be held down for a few miliseconds to register consistently, with no skips.

If anyone's interested, the code is below. It's working for the following setup (though the code is quite explanatory, so should be easy to modify) :
- 1st char: left hand normal and power attack (fighter bonus)
- 2nd char: left and right hand dual attack plus individual power attack for left and right hand (fighter bonus)
- 3rd char: water and earth spells
- 4th char: fire and air spells
(probably need to double the sleep time if you don't have the fighter bonus)

Code: Select all

;Legend of Grimmrock Keyboard controller

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Variables
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

iLastCharX := 1485
iLastCharY := 755
bStartCast := false

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Constants (currently hard-coded for 1920x1080 fullscreen or windowed fullscreen)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;Root position (upper left)  coordinates for the 4 character areas
CHAR1X := 1495
CHAR1Y := 745
CHAR2X := 1700
CHAR2Y := 745
CHAR3X := 1495
CHAR3Y := 945
CHAR4X := 1700
CHAR4Y := 945

;offsets to specific actions
LAttackX := 35
LAttackY := 50
RAttackX := 120
RAttackY := 50

Magic1X := 15
Magic1Y := 10
Magic2X := 60
Magic2Y := 10
Magic3X := 105
Magic3Y := 10
Magic4X := 15
Magic4Y := 45
Magic5X := 60
Magic5Y := 45
Magic6X := 105
Magic6Y := 45
Magic7X := 15
Magic7Y := 85
Magic8X := 60
Magic8Y := 85
Magic9X := 105
Magic9Y := 85
MagicAX := 145 ;abort
MagicAY := 10
MagicCX := 145 ;cast
MagicCY := 45

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; Hotkeys
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

#IfWinActive Legend of Grimrock 2

---- Hand Attacks ----

; left hand normal attack
~1::	Gosub, Char1LHand

; left hand power attack
!~1::	
{
	Gosub, CastPowerStart
	Gosub, Char1LHand
	return
}

; left and right hand dual attack
~2::	
{
	Gosub, Char2LHand
	Sleep, 100
	Gosub, Char2RHand
	return
}

; left hand power attack
!~2::	
{
	Gosub, CastPowerStart
	Gosub, Char2LHand
	return
}

; right hand power attack
+~2::	
{
	Gosub, CastPowerStart
	Gosub, Char2RHand
	return
}


;~3::	Gosub, Char3LHand
;!~3::	Gosub, Char3RHand

;~4::	Gosub, Char4LHand
;!~4::	Gosub, Char4RHand

---- Air Spells ----

; Shock
!~4::
{
	Gosub, Char4LHand
	Sleep, 100
	Gosub, CastPowerStart
	Gosub, TglMagic3
	Gosub, CastPowerStop
	Gosub, CancelMagic
	return
}

; Invisibility
~Numpad0::
{
	Gosub, Char4LHand
	Sleep, 100
	Gosub, CastPowerStart
	Gosub, TglMagic3
	Gosub, TglMagic6
	Gosub, TglMagic5
	Gosub, TglMagic8
	Gosub, CastPowerStop
	Gosub, CancelMagic
	return
}

; Shock Shield
~Numpad2::
{
	Gosub, Char4LHand
	Sleep, 100
	Gosub, CastPowerStart
	Gosub, TglMagic5
	Gosub, TglMagic2
	Gosub, TglMagic3
	Gosub, TglMagic6
	Gosub, TglMagic5
	Gosub, CastPowerStop
	Gosub, CancelMagic
	return
}

; Lightning Bolt
!~5::
{
	Gosub, Char4LHand
	Sleep, 100
	Gosub, CastPowerStart
	Gosub, TglMagic4
	Gosub, TglMagic5
	Gosub, TglMagic2
	Gosub, TglMagic3
	Gosub, CastPowerStop
	Gosub, CancelMagic
	return
}

---- Earth Spells ----

; Poison Cloud
!~3::
{
	Gosub, Char3LHand
	Sleep, 100
	Gosub, CastPowerStart
	Gosub, TglMagic7
	Gosub, CastPowerStop
	Gosub, CancelMagic
	return
}

; Poison Bolt
!~6::
{
	Gosub, Char3LHand
	Sleep, 100
	Gosub, CastPowerStart
	Gosub, TglMagic7
	Gosub, TglMagic8
	Gosub, TglMagic9
	Gosub, TglMagic6
	Gosub, TglMagic3
	Gosub, CastPowerStop
	Gosub, CancelMagic
	return
}

; Poison Shield
~Numpad3::
{
	Gosub, Char3LHand
	Sleep, 100
	Gosub, CastPowerStart
	Gosub, TglMagic5
	Gosub, TglMagic8
	Gosub, TglMagic7
	Gosub, TglMagic4
	Gosub, TglMagic5
	Gosub, CastPowerStop
	Gosub, CancelMagic
	return
}

---- Fire Spells ----

; Fireburst
~4::
{
	Gosub, Char4LHand
	Sleep, 100
	Gosub, CastPowerStart
	Gosub, TglMagic1
	Gosub, CastPowerStop
	Gosub, CancelMagic
	return
}

; Fireball
~5::
{
	Gosub, Char4LHand
	Sleep, 100
	Gosub, CastPowerStart
	Gosub, TglMagic1
	Gosub, TglMagic2
	Gosub, TglMagic3
	Gosub, TglMagic6
	Gosub, CastPowerStop
	Gosub, CancelMagic
	return
}

; Fire Shield
~Numpad1::
{
	Gosub, Char4LHand
	Sleep, 100
	Gosub, CastPowerStart
	Gosub, TglMagic5
	Gosub, TglMagic2
	Gosub, TglMagic1
	Gosub, TglMagic4
	Gosub, TglMagic5
	Gosub, CastPowerStop
	Gosub, CancelMagic
	return
}

; Meteor Storm
~7::
{
	Gosub, Char4LHand
	Sleep, 100
	Gosub, CastPowerStart
	Gosub, TglMagic1
	Gosub, TglMagic4
	Gosub, TglMagic5
	Gosub, TglMagic6
	Gosub, TglMagic3
	Gosub, CastPowerStop
	Gosub, CancelMagic
	return
}

---- Water Spells ----

; Ice Shards
~3::
{
	Gosub, Char3LHand
	Sleep, 100
	Gosub, CastPowerStart
	Gosub, TglMagic7
	Gosub, TglMagic8
	Gosub, TglMagic9
	Gosub, CastPowerStop
	Gosub, CancelMagic
	return
}

; Dispel
~f::
{
	Gosub, Char3LHand
	Sleep, 100
	Gosub, CastPowerStart
	Gosub, TglMagic1
	Gosub, TglMagic2
	Gosub, TglMagic3
	Gosub, TglMagic6
	Gosub, TglMagic5
	Gosub, TglMagic4
	Gosub, TglMagic7
	Gosub, TglMagic8
	Gosub, TglMagic9
	Gosub, CastPowerStop
	Gosub, CancelMagic
	return
}

; Frostbolt
~6::
{
	Gosub, Char3LHand
	Sleep, 100
	Gosub, CastPowerStart
	Gosub, TglMagic3
	Gosub, TglMagic6
	Gosub, TglMagic9
	Gosub, CastPowerStop
	Gosub, CancelMagic
	return
}

; Frost Shield
~Numpad4::
{
	Gosub, Char3LHand
	Sleep, 100
	Gosub, CastPowerStart
	Gosub, TglMagic5
	Gosub, TglMagic8
	Gosub, TglMagic9
	Gosub, TglMagic6
	Gosub, TglMagic5
	Gosub, CastPowerStop
	Gosub, CancelMagic
	return
}

---- Utility Spells ----

; Shield
~Numpad5::
{
	Gosub, Char4LHand
	Sleep, 100
	Gosub, CastPowerStart
	Gosub, TglMagic4
	Gosub, TglMagic5
	Gosub, TglMagic6
	Gosub, CastPowerStop
	Gosub, CancelMagic
	return
}

; Darkness
~Numpad8::
{
	Gosub, Char4LHand
	Sleep, 100
	Gosub, CastPowerStart
	Gosub, TglMagic8
	Gosub, TglMagic5
	Gosub, CastPowerStop
	Gosub, CancelMagic
	return
}

; Light
~Numpad7::
{
	Gosub, Char4LHand
	Sleep, 100
	Gosub, CastPowerStart
	Gosub, TglMagic2
	Gosub, TglMagic5
	Gosub, CastPowerStop
	Gosub, CancelMagic
	return
}

; Force Field
~Numpad6::
{
	Gosub, Char4LHand
	Sleep, 100
	Gosub, CastPowerStart
	Gosub, TglMagic1
	Gosub, TglMagic2
	Gosub, TglMagic3
	Gosub, TglMagic6
	Gosub, TglMagic9
	Gosub, TglMagic8
	Gosub, TglMagic7
	Gosub, TglMagic4
	Gosub, TglMagic1
	Gosub, CastPowerStop
	Gosub, CancelMagic
	return
}

; Dark Bolt
~Numpad9::
{
	Gosub, Char4RHand
	Sleep, 100
	Gosub, CastPowerStart
	Gosub, TglMagic8
	Gosub, TglMagic5
	Gosub, TglMagic4
	Gosub, CastPowerStop
	Gosub, CancelMagic
	return
}

---- Debug ----

; rune system (4th char)
^z::
{
	Gosub, Char4LHand
	Sleep, 1000
	Gosub, TglMagic1
	Sleep, 1000
	Gosub, TglMagic2
	Sleep, 1000
	Gosub, TglMagic3
	Sleep, 1000
	Gosub, TglMagic4
	Sleep, 1000
	Gosub, TglMagic5
	Sleep, 1000
	Gosub, TglMagic6
	Sleep, 1000
	Gosub, TglMagic7
	Sleep, 1000
	Gosub, TglMagic8
	Sleep, 1000
	Gosub, TglMagic9
	Sleep, 1000
	Gosub, CastMagic
	Sleep, 1000
	Gosub, CancelMagic
	return
}


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; Functions
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

UseLHand:
OffsetX := iLastCharX + LAttackX
OffsetY := iLastCharY + LAttackY
Click Down Right %OffsetX%, %OffsetY%
if (bStartCast=true)
{
	Sleep, 1000
	bStartCast := false
}
else
{
	Sleep, 10
}
Click Up Right
return

UseRHand:
OffsetX := iLastCharX + RAttackX
OffsetY := iLastCharY + RAttackY
Click Down Right %OffsetX%, %OffsetY%
if (bStartCast=true)
{
	Sleep, 1000
	bStartCast := false
}
else
{
	Sleep, 10
}
Click Up Right
return

TglMagic1:
OffsetX := iLastCharX + Magic1X
OffsetY := iLastCharY + Magic1Y
if (bStartCast=true) 
{
	Click Down Right %OffsetX%, %OffsetY%
	bStartCast := false
	return
}
else 
{
	MouseMove, %OffsetX%, %OffsetY%
	return
}
return

TglMagic2:
OffsetX := iLastCharX + Magic2X
OffsetY := iLastCharY + Magic2Y
if (bStartCast=true) 
{
	Click Down Right %OffsetX%, %OffsetY%
	bStartCast := false
	return
}
else
{
	MouseMove, %OffsetX%, %OffsetY%
	return
}
return

TglMagic3:
OffsetX := iLastCharX + Magic3X
OffsetY := iLastCharY + Magic3Y
if (bStartCast=true) 
{
	Click Down Right %OffsetX%, %OffsetY%
	bStartCast := false
	return
}
else 
{
	MouseMove, %OffsetX%, %OffsetY%
	return
}
return

TglMagic4:
OffsetX := iLastCharX + Magic4X
OffsetY := iLastCharY + Magic4Y
if (bStartCast=true) 
{
	Click Down Right %OffsetX%, %OffsetY%
	bStartCast := false
	return
}
else 
{
	MouseMove, %OffsetX%, %OffsetY%
	return
}
return

TglMagic5:
OffsetX := iLastCharX + Magic5X
OffsetY := iLastCharY + Magic5Y
if (bStartCast=true) 
{
	Click Down Right %OffsetX%, %OffsetY%
	bStartCast := false
	return
}
else 
{
	MouseMove, %OffsetX%, %OffsetY%
	return
}
return

TglMagic6:
OffsetX := iLastCharX + Magic6X
OffsetY := iLastCharY + Magic6Y
if (bStartCast=true) 
{
	Click Down Right %OffsetX%, %OffsetY%
	bStartCast := false
	return
}
else 
{
	MouseMove, %OffsetX%, %OffsetY%
	return
}
return

TglMagic7:
OffsetX := iLastCharX + Magic7X
OffsetY := iLastCharY + Magic7Y
if (bStartCast=true) 
{
	Click Down Right %OffsetX%, %OffsetY%
	bStartCast := false
	return
}
else 
{
	MouseMove, %OffsetX%, %OffsetY%
	return
}
return

TglMagic8:
OffsetX := iLastCharX + Magic8X
OffsetY := iLastCharY + Magic8Y
if (bStartCast=true) 
{
	Click Down Right %OffsetX%, %OffsetY%
	bStartCast := false
	return
}
else 
{
	MouseMove, %OffsetX%, %OffsetY%
	return
}
return

TglMagic9:
OffsetX := iLastCharX + Magic9X
OffsetY := iLastCharY + Magic9Y
if (bStartCast=true) 
{
	Click Down Right %OffsetX%, %OffsetY%
	bStartCast := false
	return
}
else 
{
	MouseMove, %OffsetX%, %OffsetY%
	return
}
return

CastMagic:
OffsetX := iLastCharX + MagicCX
OffsetY := iLastCharY + MagicCY
Click Down Right %OffsetX%, %OffsetY%
Sleep, 10
Click Up Right %OffsetX%, %OffsetY% 
return

CancelMagic:
OffsetX := iLastCharX + MagicAX
OffsetY := iLastCharY + MagicAY
Click Down Right %OffsetX%, %OffsetY%
Sleep, 10
Click Up Right %OffsetX%, %OffsetY% 
return

CastPowerStart:
bStartCast := true
return

CastPowerStop:
Click Up Right
return

Char1LHand:
iLastCharX := CHAR1X
iLastCharY := CHAR1Y
Gosub UseLHand
return

Char1RHand:
iLastCharX := CHAR1X
iLastCharY := CHAR1Y
Gosub UseRHand
return

Char2LHand:
iLastCharX := CHAR2X
iLastCharY := CHAR2Y
Gosub UseLHand
return

Char2RHand:
iLastCharX := CHAR2X
iLastCharY := CHAR2Y
Gosub UseRHand
return

Char3LHand:
iLastCharX := CHAR3X
iLastCharY := CHAR3Y
Gosub UseLHand
return

Char3RHand:
iLastCharX := CHAR3X
iLastCharY := CHAR3Y
Gosub UseRHand
return

Char4LHand:
iLastCharX := CHAR4X
iLastCharY := CHAR4Y
Gosub UseLHand
return

Char4RHand:
iLastCharX := CHAR4X
iLastCharY := CHAR4Y
Gosub UseRHand
return
Script modified and adapted from here: viewtopic.php?f=3&t=6760
RobidyBobidy
Posts: 5
Joined: Mon Oct 14, 2024 12:53 am

Re: Autohotkey script - spells, normal & power attacks [updated]

Post by RobidyBobidy »

Hey, I tried using this script and I'm getting a lot of awkward "hold right click and look around at the ground" action happening.

To be fair, I also tried getting some simple "move mouse to coordinate, right click" scripts but had a lot of trouble with my characters randomly decided to move, even though WASD wasn't in the script.

Would you happen to know what my game/autohotkey might be doing? I'm not sure what's causing all the extra movement and free-looking. :(
Post Reply