Skip to content

Instantly share code, notes, and snippets.

@dmerrick
Created July 18, 2009 16:35
Show Gist options
  • Save dmerrick/149610 to your computer and use it in GitHub Desktop.
Save dmerrick/149610 to your computer and use it in GitHub Desktop.
The short version of my anti-afk bot. Tweak to taste.
-- Anti AFK Bot
-- Warrior edition
-- 12/1/08
-- This program will keep you from AFKing in a WoW battleground.
-- (c) Dana Merrick 2008
-- Released under the MIT License.
log "Starting program"
beep
try
display dialog "Welcome to Dana's Anti-AFK Bot!"
-- FIXME: Better button labels, custom icon?
-- buttons("Quit", "Run")
-- default button 0 cancel button 1
-- with icon iconHere
on error number -128
log "User cancelled (splash)"
return
end try
-- Check if it's running
if appIsNotRunning() then
log "Launching WoW"
launch application "World of Warcraft"
try
display dialog "Please log in and enter a battleground first."
on error number -128
log "User cancelled (launch)"
return
end try
end if
-- Main loop
log "Entering loop"
repeat 60 times
tell application "System Events"
log "Moving"
(* Move a bit *)
tell application "World of Warcraft" to activate
key code 34 (* i *)
(* Leap in the middle *)
delay (random number from 0 to 2)
tell application "World of Warcraft" to activate
key code 49 (* space *)
delay (random number from 0 to 2)
tell application "World of Warcraft" to activate
key code 34 (* i *)
(* Target nearest and start attack *)
tell application "World of Warcraft" to activate
key code 48 (* tab *)
tell application "World of Warcraft" to activate
key code 18 (* 1 *)
(* Try charging *)
log "Charging..."
tell application "World of Warcraft" to activate
key code 48 (* tab *)
tell application "World of Warcraft" to activate
key code 21 (* 4 *)
delay (random number from 1 to 2)
log "...done"
end tell
delay (random number from 200 to 299)
end repeat
log "Loop over"
beep 4
display alert "Shutting down." giving up after 30
return
-- Checks if WoW is running.
on appIsNotRunning()
tell application "System Events" to (name of processes) does not contain "World of Warcraft"
end appIsNotRunning
-- FIXME: Broken keyPress function.
on keyPress(keyCode)
tell application "System Events"
tell application "World of Warcraft" to activate
key code keyCode
end tell
end keyPress
-- Sends a message to chat.
-- Not tested, also be sure to add "/s " or whatever.
on sendMessage(msg)
tell application "System Events"
tell application "World of Warcraft" to activate
key code 36 (* enter *)
tell application "World of Warcraft" to activate
keystroke msg
tell application "World of Warcraft" to activate
key code 36 (* enter *)
end tell
end sendMessage
-- Helper function
on minutesToTimes(num)
return (num * 60) / 150
end minutesToTimes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment