Code:
;
; Automated Garrison Resource Farming
; @Author: Sklug
; Beginning of WOW Window Detection for Key Sending
Sleep 1000
IfWinNotExist, World of Warcraft ; Disables program if Warcraft Not Detected
{
SplashTextOn, 320, , No Warcraft Instance Detected. Shutting Down
Sleep 4000
SplashTextOff
ExitApp
}
; WinGet returns all instances of World of Warcraft into a List, id1, id2, etc...
WinGet, id, list, World of Warcraft
count:= 0
Loop, %id%
{
count++
}
If (count > 1) ; If more than one WOW window is open
{
SplashTextOn, 200, , Multiple Warcraft Instances Detected!
Loop %count% ; This loop minimizes all WOW windows for easier selection
{
window := id%A_Index%
WinMinimize, ahk_id %window%
}
Sleep 2000
SplashTextOff
Loop %count% ; This activates each window one by one until the correct one is selected
{
window2 := id%a_index%
WinActivate, ahk_id %window2%
Sleep 250
MsgBox, 4,, Is This the Desired WOW Instance to Send Commands? (Press Yes or No)
IfMsgBox Yes
{
idMain = %window2%
break
}
else
{
WinMinimize, ahk_id %window2%
}
}
}
else
{
idMain = %id1%
WinActivate, ahk_id %idMain%
}
; End of Multi-Window Identification.
; Global Variables
; Misc Record Keeping Variable
timeLeft := ; For managing more exact timing on the 10 min delay
; Installing Picture and Sound File for GUI
FileInstall, Sklug.gif,Sklug.gif, 1
; End of Global Variable Decelerations
; All the Functions of Program to be Called upon
; Function "Rand(Float,Float);
; Custom Random number generator to actually make a random number. This is good for rand timer on
; Keyboard input to mimic human behaviour. The reason this is necessary is
; because computers aren't really random. They fool you into thinking it is random
; by using a complex math equations usually based off the date down to the millisecond
; to create a "seed" behind the scenes to bounce the randomization algorithm off of.
; However, if the seed never changes, like a random number generator within a loop,
; the number never changes. This solves that issue in a unique way.
Rand( a=0.0, b=1 )
{
IfEqual,a,,Random,,% r := b = 1 ? Rand(0,0xFFFFFFFF) : b
Else Random,r,a,b
Return r
}
; Function "SleepTimer(String)"
; Calculates the 2 different delays... the random input timer when withdrawing the resources
; and the 10 minute(ish) delay between next resource loot
SleepTimer(timerName)
{
; Need to call global variable from within the function before
; I can use those numbers. I can declare a new variable here, but if I wish to expand this program further
; I am just keeping it consistent.
global sleepTimerDelay
; Setting the SleepTimer delays for inbetween various functions
If (timerName = "randomized")
{
sleepTimerRandom := Rand(2450,3500) ; Randomized Delay between actions.
sleep, %sleepTimerRandom% ;
}
else
{
sleep, 2000 ; negligible time will not be used.
}
}
; Function MainAlgorithm()
; This takes all the tools created and puts them together into a sequence of steps that get the
; 10 minute job done. The looping will be handled at the end of the GUI
MainAlgorithm()
{
global timeLeft
global idMain
ControlSend,, 1, ahk_id %idMain% ; "Smuggling Run!" spell (place it on action bar position 1)
timerCount := A_TickCount ; This will be keeping track of elapsed time to subtract from the 10 minute timer.
SleepTimer("randomized")
ControlSend,, 2, ahk_id %idMain% ; Macro on Key 2, " /tar Honest Jim "
sleep, 1000
ControlSend,, {F7}, ahk_id %idMain% ; Character interact Key is usually F7
SleepTimer("randomized")
ControlSend,, 3, ahk_id %idMain% ; macro on Key Position 3, " /run SelectGossipOption(1) "
SleepTimer("randomized")
ControlSend,, 4, ahk_id %idMain% ; macro on Key Position 4, Check Ownedcore Post for the long macro.
SleepTimer("randomized")
ControlSend,, 5, ahk_id %idMain% ; macro on Key Position 5, " /use Crate of Stolen Resources "
elapsedTime := (A_TickCount - timerCount) ; This keeps track of the elapsed time so random timers can be added for more exact timing on 10 minutes.
timeLeft := (600000 - elapsedTime) + 5000 ; 600k ms = 600 seconds = 10 minutes -- the extra 5 seconds added is just a slight error cushion.
}
; Function GarrisonFarmingGUI()
; The purpose of this is to put the GUI into function form to be easily called to and rebuilt as necessary
; with a simple "Return" call, thus I don't need to "Reload" the whole program inefficiently, just this function.
GarrisonFarmingGUI()
{
global timeLeft
Gui, Add, Tab, x-8 y-1 w520 h280 +center, Automated Garrison Resources|The Power Tool
Gui, Tab, Automated Garrison Resources
Gui, Font, S8 CDefault, Verdana
Gui, Add, Text, x52 y109 w390 h20 cRed +Center, Inspired By "Horst" at Ownedcore.com
Gui, Font, S12 Bold, Verdana
Gui, Add, Text, x52 y79 w390 h20 +Center, Version 1.0
Gui, Font, S18 W700, Verdana
Gui, Add, Text, x52 y39 w390 h30 cTeal +Center, Garrison Resources
Gui, Add, Picture, x92 y159 w330 h110 , Sklug.gif
Gui, Font, S8 CDefault, Verdana
Gui, Add, Text, x62 y139 w150 h20 , Created By:
Gui, Tab, The Power Tool
Gui, Add, Button, x152 y99 w200 h120 , BEGIN
Gui, Font, S11 Bold, Verdana
Gui, Add, Text, x62 y39 w390 h40 cRed +Center, Press 'F10' at Any Time to Reset Program or 'Pause' to pause
Gui, Show, x127 y87 h277 w510, Automated Garrison Resources
Return
; Actions to be taken after BEGIN button is pressed.
ButtonBEGIN:
Gui, submit, NoHide
SplashTextOn, 450, , "Interact with Target" Keybind Must Be F7 -- Pause Now if Needed
Sleep 3500
SplashTextOff
Loop
{
MainAlgorithm()
sleep, %timeLeft%
}
GuiClose:
ExitApp
}
; End GUI Function
;Enabling GUI
GarrisonFarmingGUI()
; Hotkeys
Pause::Pause ; Just Pauses the Script, does not interrupt
$F10:: Reload ; Reloads whole program
^q::ExitApp ; Completely Exits program at any time