Thursday, December 18, 2008

How to Build a World of Warcraft Bot using AppleScript in 15 minutes

I was tinkering around with some apple script the other night and was blown away at how much power Apple's System Events program gives you to automate literally anything program that runs on a Mac.

To prove the point here is a simple World of Warcraft bot I created with a few lines of code to start wow , log in , walk from a merchant to a mob area, kill, loot, return and sell all your gray items.

Note to use apple's System Events program you have to enable access for assistive devices.


You're going to need to regular wow macros for this to work.

One to simulate a shift right mouse click to autoloot corpses. Doesn't need to be placed in a slot.




/script SetBinding("l", "TURNORACTION"); SaveBindings(GetCurrentBindingSet()) 




And the other to automatically sell your gray items to any merchant, in this example I placed this macro in slot 4.



/script for bag = 0,4,1 do for slot = 1, GetContainerNumSlots(bag), 1 do local name = GetContainerItemLink(bag,slot); if name and string.find(name,"ff9d9d9d") then DEFAULT_CHAT_FRAME:AddMessage("- Selling "..name); UseContainerItem(bag,slot) end; end;end 




Then just kick this script off in Script Editor and center your mouse on the screen.

    1  # Eigenclass Dec 2008
2 # start the app
3 # or bring it to the front if it's already open
4 tell application "World of Warcraft"
5 activate
6 end tell
7
8 # send messages to the app using System Events.
9 tell application "System Events"
10 tell process "World of Warcraft"
11 #repeat indefinitely
12 repeat
13 # assume you are facing a merchant to begin the flow
14
15 # back up .75 units
16 key down "s"
17 delay 1.56 * 0.75
18 key up "s"
19
20 # strafe left 1 unit
21 key down "q"
22 delay 1
23 key up "q"
24
25 # move forward 3 units
26 key down "w"
27 delay 1 * 3
28 key up "w"
29
30 # target nearest enemy
31 key down tab
32 delay 1
33 key up tab
34
35 # attach it 10 times.
36 # this assumes you have a long range
37 # attack in slot 2 (key code 19).
38 repeat 10 times
39 key code 19
40 delay 2
41 end repeat
42
43 # autoloot the corpse using the macro
44 # we bound to the "l" key
45 keystroke "l" using {shift down}
46
47 # backup 3 units
48 key down "s"
49 delay 1.56 * 3
50 key up "s"
51
52 # strafe right 1 unit
53 key down "e"
54 delay 1
55 key up "e"
56
57 # move forward .75 units
58 key down "w"
59 delay 1 * 0.75
60 key up "w"
61
62 # open the merchant dialog using the macro
63 # we bound to the "l" key
64 keystroke "l" using {command down}
65 delay 2
66
67 # auto sell all gray items using the macro
68 # we bound to the number 4 (key code 21)
69 key code 21
70 delay 2
71
72 end repeat
73
74 end tell
75 end tell
76


Watch the power of GUI scripting in action!

No comments:

Post a Comment