Using AutoHotkey to gain a Mortal Kombat achievement
24 December 2013
When it comes to browser games, they are usually 100% no-brainer repetitive and can be automated to full extent. It was fun in the beginning, not so much anymore.
I've enjoyed playing Mortal Kombat series since childhood, always was good at it. Last thing competitive on PC was Mortal Kombat 4, first 3D game in MK series, with weird characters like Fujin instead of Kung Lao, Jarek, Tanya.
Good ol' MK4 times, collecting glitches was my hobby
Mortal Kombat 4, Raiden was like the most powerful character
When Mortal Kombat Komplete Edition was released on Steam for PC, I've bought it immediately. This post is not place to say how bad MKKE for PC is, to say it short, it's the worst piece of software I have ever seen. But the game is still great and it was possible to play.
MKKE put glitches on entire new level!
After I was able to consistently beat all of my friends with most imbalanced character I was able to find (that's Kenshi, friends; he is good and easy), it was time to get some achievements. Some of them was fun and challenging (flawlessly beat Shang Tsung twice in a row?), but some of them was really boring. Look at this: "Luck Be A Lady: Get all MK Dragons in Test Your Luck".
Working on Luck Be A Lady achievement. Test Your Luck mode.
To get this achievement, you must get three gold coins in a row. Row doesn't even always have a coin in it! It would take a lot of time to do it manually.
Welcome AutoHotkey. It is a tool with it's own easy programming language, it's easy to automate routine tasks with it, it is built to work nicely with Windows UI, have native methods to work with mouse, keyboard, windows, hard disk, etc. Here is the script I have used to get Luck Be A Lady achievement:
#EscapeChar \
#CommentFlag //
//
// Settings
//
SetTitleMatchMode, 2
SetCapslockState AlwaysOff
// Enable game cheat loop.
^!F10::
{
Tooltip Starting!
Sleep 1000
Loop
{
if(GetKeyState("F10", "P"))
{
Tooltip Stopped.
Sleep 1000
Tooltip
break
}
Loop4xTimes()
RestartMatch()
}
}
Loop4xTimes()
{
Loop, 30
{
if(GetKeyState("F10", "P"))
{
break
}
Tooltip Sending input...
Send {Numpad4 down}
Sleep 10
Send {Numpad4 up}
Sleep 1000
}
}
RestartMatch()
{
if(GetKeyState("F10", "P"))
{
return
}
Send {Numpad4 down}
Sleep 10
Send {Numpad4 up}
Sleep 100
Send {Numpad2 down}
Sleep 10
Send {Numpad2 up}
Sleep 100
Send {Down down}
Sleep 10
Send {Down up}
Sleep 100
Send {Numpad4 down}
Sleep 10
Send {Numpad4 up}
Sleep 100
Send {Numpad4 down}
Sleep 10
Send {Numpad4 up}
Sleep 100
}
As you can see, endless loop is being enabled with Ctrl+Alt+F10, disabled with F10. It will attempt to start roulette in method Loop4xTimes(), and then after enough time, it will start new Test Your Luck game using RestartMatch(). This might be not the best code, but it works, I've started it, went to sleep, achievement was completed when I woke up :)
For the later MKKE automations I have made helper methods, mk9-common.ahk:
Down()
{
Send {s down}
Sleep 10
Send {s up}
return
}
Up()
{
Send {w down}
Sleep 10
Send {w up}
return
}
Left()
{
Send {a down}
Sleep 10
Send {a up}
return
}
Right()
{
Send {d down}
Sleep 10
Send {d up}
return
}
Num4()
{
Send {Numpad4 down}
Sleep 10
Send {Numpad4 up}
return
}
Num5()
{
Send {Numpad5 down}
Sleep 10
Send {Numpad5 up}
return
}
Num6()
{
Send {Numpad6 down}
Sleep 10
Send {Numpad6 up}
return
}
Num7()
{
Send {Numpad7 down}
Sleep 10
Send {Numpad7 up}
return
}
Num8()
{
Send {Numpad8 down}
Sleep 10
Send {Numpad8 up}
return
}
Num9()
{
Send {Numpad9 down}
Sleep 10
Send {Numpad9 up}
return
}
Now AutoHotkey code for MKKE looks like this:
F::
{
Left()
Right()
Num6()
Right()
Left()
Num6()
Sleep 10
return
}
I encourage you to meet AutoHotkey and discover it, as it's pretty powerful and important tool for any programmer-at-heart.