this as simple as possible while still making it a complete working
script.
It was tested in my own machine as it stands now. Any changes you make
will be your responsibility to fix. Like any good programming practice
make sure you save your code before you make any permanent changes.
That way you can go back to your previous working version if the new
version craps out. Everything you need for a basic fight routine is
in there.
Spoiler
/* ...................................................................... THIS IS SIMPLY AN EXAMPLE OF HOW AN MMO FIGHT ROUTINE MIGHT BE BUILT. IT IS TESTED BUT NOT SUPPORTED. IF YOU ALTER THIS SCRIPT TO FIT YOUR OWN NEEDS YOU WILL ALSO BE RESPONSIBLE FOR DEBUGGING IT AND CORRECTING YOUR OWN MISTAKES. IT IS DESIGNED SOLELY AS A LEARNING TOOL FOR THE CONSTRUCTION OF YOUR OWN FIGHT ROUTINES. WHAT IT DOES IN IT'S ORIGINAL FORM IS OUTLINED BELOW. ...................................................................... Here is a simple MMO RPG style fight routine. It does several different things. It allows you to select the window you are going to be sending keys to. It posts a tooltip message at the top of the screen to let you know it's working. It stops sending whenever the game or target window loses focus so you don't send stuff to the wrong window. It runs through a series of send/skill commands assumed to be on keys 1 through 4 with a 1/2 second delay between the sends. It allows the sends to be toggled on and off with the same mouse button. (in this case the middle mouse button) It turns off any standard movement keys that may interfere with the fight routine while you are fighting just in case you get stuck moving after the fight is over. It allows you to send a prefight sequence as well as a postfight sequence to the game window so you could, technically, use it to pre-buff your character and pick up loot after a fight. It centers the mouse on the screen each time the fight routine is entered so you don't have the mouse running drastically all over the screen. It contains some debugging keys to allow you to see script variables, keys and to control different aspects of your script's run. this is strictly an example of how it can be done for a single character in a single mmo game. for more flexibility you could put the prefight, fight, and postfight sequences in an ini file and read them in at the beginning of the script. By adding different sections to an ini file you could set up fight sequences for different characters in the same game using the IniRead command (not shown here). Other things that could be added are a game login that loads your game and fills in any user id and password a timer that checks your game window periodically and shuts down the script when the game window no longer exists. an Anti-Afk that moves your character after some specific time with no keyboard or mouse input. the variations are limited only by your imagination. */ ;==================================================================== ; Standard Setup stuff ;-------------------------------------------------------------------- #NoEnv #singleInstance, Force #MaxThreads, 100 #MaxThreadsPerHotkey, 2 #Persistent SetBatchLines, -1 DetectHiddenWindows, On CoordMode, Mouse, Screen CoordMode, Pixel, Screen CoordMode, Tooltip, Screen SetTitleMatchMode, 2 SetKeyDelay, 30,50 SetMouseDelay 10 SendMode Event #InstallKeybdHook #InstallMouseHook #UseHook, On ;-------------------------------------------------------------------- ; I put the main script and all game ini files in the same directory SplitPath, A_ScriptFullPath, ofname, ofdir, ofext, ofnamene, odrv SetWorkingDir, %ofdir% ; set up the game window's ahk_id gosub WinGetId ; this is to prevent sending to a diff window by accident. ; that little bug can get really messy really fast. return ;==================================================================== #If (WinActive(vWinID)) ; forces the following hotkeys to work only ; for the given window id. ;==================================================================== ; Fight block exerciser. ; Works for both prefight and postfight the format for keyblock is ; key1,cast1|key2,cast2|...|keyX,castX ; this can also be used for healing skills as well ; call this one time for the prefight as shown in the main fight routine ; call repeatedly til fight is finished ; call this with postfight block one time to clean up after a fight ; This routine tries to maximize speed by eliminating any skill cooldowns ;-------------------------------------------------------------------- fnDoFightBlock(KeyBlock) { global vWinID If (KeyBlock = "None") { return } StringSplit, KBAry,KeyBlock,| retval = 1 Loop %KBAry0% { If (GetKeyState("MButton","p")) ; don't send if mbutton pressed { retval = 0 break } ; this keeps you from sending to the wrong window If (!winActive(vWinID)) ; don't send if the window goes dead { retval = 0 break } x := KBAry%A_Index% StringSplit,KAry,x,`, If (GetKeyState("MButton","p")) ; don't send if mbutton pressed { retval = 0 break } Send, %KAry1% Sleep, %KAry2% } return (retval) } ;==================================================================== ; main fight routine ; fight routine sends the fight keys until stopped using the middle ; mouse button. It does not attempt to qualify or select the target(s) ; for the fight. That part is up to you to pick the target you want ; to fight before hitting the middle mouse button. ;.................................................................... MButton:: ;<-- start/end fight routine Suspend, On ;<-- blocks other hotkey interference. keywait, MButton ; turn off movement keys If (WinActive(vWinID)) { send, {s up} send, {w up} send, {e up} send, {q up} send, {a up} send, {d up} } ; put mouse in center of screen. this assumes you are running ; your game in windowed full screen mode. CenterX := (A_Screenwidth // 2) CenterY := (A_ScreenHeight // 2) MouseMove,%CenterX%,%CenterY% ;looping flag set when fighting off when not fighting LoopSending := !LoopSending ; display fight runtime status tooltip near the top center of ;the screen. At least on my screen it does. ttx = 300 tty1 = 0 Tooltip, LoopSending=%LoopSending%, %ttx%, %tty1%, 1 ; do prefight actions prefight = None ;<-- buffs and stuff can go in here fnDoFightBlock(PreFight) ;-------------------------------------------- ; main fight loop ;-------------------------------------------- While (LoopSending) ; enters the main fight loop { Suspend, On ;---------------------------------------- ; clear spurious movement flags sometimes keys ; stick while moving and fighting ;---------------------------------------- If (WinActive(vWinID)) { send, {s up} send, {w up} send, {e up} send, {q up} send, {a up} send, {d up} } ;---------------------------------------- ; pick a key to send and continue fighting ; change the fight keys to whatever works for ; your game. you could even have fight keys ; for differnt game characters. ;---------------------------------------- fightkeys = 1,500|2,500|3,500|4,500 loopsending := fnDoFightBlock(fightkeys) } ;<-- end fight loop when loopsending off ; Do PostFight Actions postfight = None ;looting, self healing etc can go here fnDoFightBlock(PostFight) ; turn off messages and exit fight routine Tooltip,,,,1 ;<-- turn off the loop status tooltip Suspend Off Return ;==================================================================== ; Get Game Window ID ;==================================================================== ^!w:: ;<-- Setup window id WinGetID: Suspend On but = MButton While (!GetKeyState(but,"P")) { ToolTip, Left Click on your game window and press %but% to grab the window id } KeyWait, %but% WinGet, vWinID,ID,A ToolTip vWinID = ahk_id %vWinID% Suspend, Off Return ;==================================================================== #if ;==================================================================== ;DebugStuff ;-------------------------------------------------------------------- !Esc: Suspend Permit ExitApp !z:: ;<-- Task manager debugging for screwy lockups Run, Taskmgr.exe Return !F5::Suspend !F6:: ;<--show files ShowFile: FileSelectFile, infile, , , , (*.txt;*.ini) Run, Notepad %infile% Return !F7::KeyHistory !F8::ListHotkeys pause::pause !F9::Pause, Toggle !F10::ListVars !F11::ListLines !F12::Reload ;-------------------------------------------------------------------- ; Support Stuff this is my include file. you can add your own or ; eliminate this line if you want #Include *i %A_ScriptDir%\StonerSupportV2.ahk ;general support stuff ; contains stuff like reading the screen getting pixel colors, Snippingtool, ; reading the game ini file, grabbing images and stuff like that.