A incomplete AHK Bot menu

User Tag List

Results 1 to 2 of 2
  1. #1
    roevhaal's Avatar Member
    Reputation
    2
    Join Date
    Mar 2008
    Posts
    48
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    A incomplete AHK Bot

    This is by no means anything done by me, all credits go to "Gumbot" for hes work.

    I found this on AHK forums. Someone has tried and come far into making a space mission and tradeskill bot from AHK. The code is free and anyone with AHK knowledge can complete and make it work.

    Just wanted to share.

    Posted: Tue Jan 10, 2012 11:38 pm Post subject: SWTOR Tradeskill & Spacebot
    I spent some time working on this for fun but I have lost interest with SWTOR and this bot. This is my first AHK script ever, so don't judge too harshly.

    Disclaimer: I attempted to write a few mouse/key recorders, but they were always a bit inaccurate. After failing a few times, I tried to look into some of the scripts that already exist on this forum. I failed to get any of them to work properly after implementing parts of their code into my script, probably due to my lack of understanding AHK.

    This version is using code from: Mouse & Keyboard Recorder v1.02

    If I were to attempt to work on a bot again, I would code it entirely differently now that I have a better understanding of AHK. The reason I am posting this is because it was a fun learning experience. I learned a lot just from viewing scripts on this site, so I hope others can learn from my experience.

    Lastly, if you are just interested in a SWTOR bot, this is not what you are looking for. It is incomplete and will require a bit of AHK knowledge to operate. On top of that, you will probably be banned for using this extensively. Sorry!

    Features:

    - Tradeskill gathering
    - Spacebot recording/playback
    - Pixel color verification to ensure bot is running properly.

    How it works:

    - Window resolution/position: 1024x768 resolution (top left). If you go fullscreen and then windowed, it will set it to the right position.

    - Spacebot starting position: sit in the captain chair, press ESC to exit the galaxy window, and then scroll out a bit. Make sure you are not in the chair (move slightly) so the chair is clickable. After that, just make sure the script is in the tray and press numpad1 to start the bot.

    - If you wish to record instead of play a mission script, press Numpad4 before pressing numpad1. As soon as you get into the space mission, it will start recording it. You have to press Numpad6 to manually save the recording. If you get recordings to work, you can have it auto save at the end of the space mission by detecting the reward window via the hasMissionComplete() function.

    - To kill the script, press Numpad0.

    What's broken:

    - In some cases, the x,y pixel colors will be a few pixels off so you will have to change it. I think this is related to the windows theme since it is grabbing relative position from the window, not the actual game. You will need basic understanding of AHK to update the color hexes.

    - The send input is a bit finicky due to implementing the Mouse & Keyboard recorder for the spacebot mission playback. I'm not entirely sure what broke it, but you will have to play around with the settings at the top until mouse clicks will work again for everything except the spacebot.

    - Other than the send input issue above and making sure the colors are correct, the tradeskills work flawlessly. I was able to run this for a few days with no interruptions.

    - The timing for runBot() is off when playing the .torbot scripts back. It's probably due to implementing the code incorrectly. This is the only reason why the spacebot fails to work. I managed to get a few scripts to run back flawlessly with the original script, but not after saving the recording and attempting to play it back. I believe this is the same issue that I am having after implementing it into my script.

    Stuff:

    Script: [Autohotkey] #NoEnv #SingleInstance force #MaxThreadsBuffer On #MaxHotkeysPerInterval 1000 - Pastebin.com

    Readme: '||''|. ..|''|| '|. '|' ..|'''.| '||''|. ..|''|| |''||''| || - Pastebin.com (Take it with a grain of salt, I never got around to implementing some of the features such as the external settings.txt config file. It'll give you an idea of what the settings are and how they work though.

    A incomplete AHK Bot
  2. #2
    Randomizer's Avatar Contributor
    Reputation
    120
    Join Date
    Jun 2008
    Posts
    188
    Thanks G/R
    6/0
    Trade Feedback
    1 (100%)
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Code:
    #NoEnv
    #SingleInstance force
    #MaxThreadsBuffer On
    #MaxHotkeysPerInterval 1000000
    #HotkeyInterval 60000
    
    CoordMode, Mouse, Screen
    SendMode, Input
    SetKeyDelay, -1
    SetMouseDelay, -1
    
    ;--------------------------------------------------
    ; Settings
    ;--------------------------------------------------
    
    ; Space Combat Bot
    spaceEnabled = 1 ; use space combat bot?
    missionId = 1 ; space combat mission
    runCount = 1 ; how many times to run the mission
    
    ; Tradeskill Bot
    tradeskillEnabled = 0 ; use tradeskill bot?
    tradeskillBind = n ; key binding to open companion window
    ; tradeskill (0 = disabled, 1 = enabled)
    ; tradeskill tier (0 = default, 1 = 10-16, ... , 6 = 49-50)
    tradeskill = 1:0,0:0,0:0
    companion = 1,1,0 ; 0 = disabled, 1 = enabled (top to bottom)
    style = 1 ; 0 = pick tradeskill randomly, 1 = loop single tradeskill, 2 = do tradeskills in order (requires more than 1)
    diplomacyFaction = 0 ; only picks diplomacy missions based on faction (0 = disabled/any, 1 = republic, 2 = empire)
    
    ; Record Bot
    auto_save = 1 ; automatically save recordings
    record_path = scripts ; the script save/load location
    inPlay = 0 ; internal script variable to determine if bot is currently playing a script
    inRecord = 0 ; internal script variable to determine if bot is currently recording a script
    recording = ; internal script variable to store the recorded script
    
    ;--------------------------------------------------
    ; Bot Functions
    ;--------------------------------------------------
    
    ; Some code from:
    ; http://www.autohotkey.com/forum/viewtopic.php?t=53196
    
    ; Records the next space combat mission
    recordBot() {
    	global
    	; Double check the bot is not active
    	if(inPlay) {
    		return
    	}
    	if(inRecord=2) {
    		ttHandler("Space mission is now being recorded", 3000)
    		RecordCount := 0
    		Sleep, 100
    		; Timers 
    		TimeMouseMove := A_TickCount
    		SetTimer, RecordMouseKey, 1
    		return
    	}
    }
    
    ; Gets mouse movement for recording
    GetMouseMove(ByRef TimeMouseMove) {
    	LButton:=GetKeyState("LButton", "P")
    	RButton:=GetKeyState("RButton", "P")
    	MButton:=GetKeyState("MButton", "P")
    	MouseGetPos, x1, y1
    	TimeMouseMove:= A_TickCount
    	return, % x1 "|" y1 "|" LButton "|" RButton "|" MButton
    }
    
    ; Saves the current recording memory to a .torbot script
    saveRecording() {
    	global
    	; set recording status to off
    	SetTimer,RecordMouseKey,Off
    	InRecord := 0
    	Loop, % RecordCount
    	{
    		DataMouseKey .= MouseData_%A_Index%
    		DataMouseKey .= "`n"
    	}
    	if(!DataMouseKey) {
    		ttHandler("Error, there is no recording to save", 5000)
    		return
    	}
    	; todo: generate random name based on mission id
    	script = %record_path%/mission%missionId%.torbot
    	; save to .torbot file
    	FileDelete, %script%
    	FileAppend, %DataMouseKey%, %script%
    	ttHandler("Saved recording: (%script%)", 5000)
    	; clear the recording
    	DataMouseKey =
    	return
    }
    
    ; Handles loading, parsing, and running .torbot recordings
    
    runBot(script) {
    	; Check if bot is currently active
    	if(inPlay=1 || inRecord>0) {
    		return
    	}
    	; Start the bot script
    	inPlay = 1
    	; Set the default file position to 0
    	static Position = 0
    	; Read the bot file
    	file = scripts/%script%.torbot
    	FileRead, BotScript, %file%
    	; Loop the bot file
    	loop, Parse, BotScript, `n
    	{
    		Data_%A_index%:= A_LoopField
    		Count := A_Index
    	}
    	loop, % Count
    	{
    		MoveNow := A_TickCount
    		CCount := A_index
    		; Mouse click down
    		StringSplit, MouseKeyInfo, Data_%CCount% , |
    		Mousemove, MouseKeyInfo1, MouseKeyInfo2, 0
    		; Left mouse
    		if (MouseKeyInfo3 && Not WaitLMouseUp) {
    			MouseClick, Left, MouseKeyInfo1, MouseKeyInfo2, , 0, D
    			WaitLMouseUp=1
    			SetTimer, Left, 1
    		}
    		; Right mouse
    		else if (MouseKeyInfo4 && Not WaitRMouseUp) {
    			MouseClick, right, MouseKeyInfo1, MouseKeyInfo2, , 0, D
    			WaitRMouseUp=1
    			SetTimer, Right, 1
    		}
    		; Middle mouse
    	    else if (MouseKeyInfo5 && Not WaitMMouseUp) {
    			MouseClick, Middle, MouseKeyInfo1, MouseKeyInfo2, , 0, D
    			WaitMMouseUp=1
    			SetTimer, Mid, 1
    		}
    		While ( A_TickCount - MoveNow  < MouseKeyInfo6) {
    			continue
    		}
    	}
    	; Timer for left mouse
    	Left:
    		if (MouseKeyInfo3) {
    			Return
    		}
    		WaitLMouseUp:=0
    		MouseClick, Left, MouseKeyInfo1, MouseKeyInfo2, , 0, U
    		SetTimer, Left, Off
    	return
    	; Timer for right mouse
    	Right:
    		if (MouseKeyInfo4) {
    			Return
    		}
    		WaitRMouseUp:=0
    		MouseClick, right, MouseKeyInfo1, MouseKeyInfo2, , 0, U
    		SetTimer, Right, Off
    	return
    	; Timer for middle mouse
    	Mid:
    		if (MouseKeyInfo5) {
    			Return
    		}
    		WaitMMouseUp:=0
    		MouseClick, m, MouseKeyInfo1, MouseKeyInfo2, , 0, U
    		SetTimer, Mid, Off
    	return
    }
    
    ;--------------------------------------------------
    ; Tradeskill Functions
    ;--------------------------------------------------
    
    ; Handles the entire tradeskill process
    
    tradeskillHandler() {
    	global
    	; Turn config variables into arrays
    	StringSplit, arrCompanion, companion, `,
    	StringSplit, arrTradeskill, tradeskill, `,
    	; Make sure there are no pending rewards
    	hasMissionComplete()
    	; Loop companions
    	Loop, %arrCompanion0% {
    		tempCID=%a_index%
    		tempC:=arrCompanion%a_index%
    		; If companion is enabled
    		if(tempC=1 AND hasActiveMission(tempCID)=false) {
    			Loop, %arrTradeskill0% {
    				tempTSID=%a_index%
    				tempTS:=arrTradeskill%a_index%
    				StringReplace, tempTS, tempTS, :, `,, All
    				StringSplit, currTradeskill, tempTS, `,
    				if((currTradeskill1=1 AND style=0) || (currTradeskill1=1 AND style=1) || (currTradeskill1=1 AND style=2 AND tempTSID != last_tradeskill)) {
    					; Open the appropriate tradeskill based on array index
    					openTradeskill(a_index, tempCID)
    					; Select a mission tier if above 0
    					if(%currTradeskill2%<0) {
    						selectMissionTier(currTradeskill2)
    					}
    					; Run the mission
    					startMission(1)
    					; Check if it matches correct diplomacy faction if enabled
    					if(diplomacyFaction<0 AND diplomacyCheck()!=diplomacyFaction) {
    						; We don't want this, drop it and send it through the loop again
    						dropMission(tempCID) ; send the companion id
    						continue
    					}
    					break
    				}
    			}
    			; set the last tradeskill
    			if(style = 2) {
    				last_tradeskill = %tempTSID%
    			}
    		}
    		; Make sure there are no pending rewards
    		hasMissionComplete()
    	}
    }
    
    ; Checks the faction for diplomacy mission 
    
    diplomacyCheck() {
    	global
    	; Check the faction icon of the first quest mission
    	PixelGetColor, color, 693, 263
    	; empire
    	if(color = "0x020182" AND diplomacyFaction = 2) {
    		return 2
    	; republic
    	}else if(color = "0xF8CD97" AND diplomacyFaction = 1) {
    		return 1
    	; non-diplomacy error
    	}else{
    		return 0
    	}
    }
    
    ; Opens or closes the crew management window based on whether
    ; it is currently open or not.
    
    crewManageToggle(toggle) {
    	global
    	PixelGetColor, color, 325, 374 ; crew management scroll bar
    	if(toggle = "on" AND color != "0xD8B455") {
    		SendInput, {%tradeskillBind%}
    		Sleep, 1000
    	}else if(toggle = "off" AND color = "0xD8B455") {
    		SendInput, {%tradeskillBind%}
    		Sleep, 1000
    	}
    }
    
    ; Open the tradeskill window based specified tradeskill id
    ; and companion id
    
    openTradeskill(id, companion) {
    	; Open crew management window
    	crewManageToggle("on")
    	; Determine x based on tradeskill id
    	if (id = 1) {
    		xPos = 117
    	}else if(id = 2) {
    		xPos = 154
    	}else if(id = 3) {
    		xPos = 196
    	}
    	; Determine y based on companion id
    	if (companion = 1) {
    		yPos = 360
    	}else if (companion = 2) {
    		yPos = 422
    	}else if (companion = 3) {
    		yPos = 491
    	}
    	; Open tradeskill window
    	MouseClick, left,  xPos,  yPos
    	Sleep, 1000
    }
    
    ; Selects a mission level tier based on the
    ; specified mission tier id. See data.txt for
    ; more information.
    
    selectMissionTier(id) {
    	; Open Drop Down
    	MouseClick, left,  882, 241
    	Sleep, 1000
    	; set the x position
    	xPos = 882
    	if (id = 1) {
    		yPos = 259
    	}else if (id = 2) {
    		yPos = 270
    	}else if (id = 3) {
    		yPos = 283
    	}else if (id = 4) {
    		yPos = 295
    	}else if (id = 5) {
    		yPos = 309
    	}else if (id = 6) {
    		yPos = 322
    	}
    	; Select mission tier
    	MouseClick, left,  xPos,  yPos
    	Sleep, 1000
    }
    
    ; Drops the current mission based on companion
    ; id
    
    dropMission(id) {
    	; set mouse xPos
    	xPos = 279
    	; get yPos by companion id
    	if (id = 1) {
    		yPos = 350
    	}else if (id = 2) {
    		yPos = 414
    	}else if (id = 3) {
    		yPos = 478
    	}
    	; drop the mission
    	MouseClick, left,  xPos,  yPos
    	Sleep, 1000
    }
    
    ; Starts the companions mission based on
    ; specified mission id
    
    startMission(id) {
    	; Select mission
    	xPos = 808
    	if(id == 1) {
    		yPos = 289
    	}else if (id == 2) {
    		yPos = 303
    	}else if (id == 3) {
    		yPos = 471
    	}else if(id = 4) {
    		yPos = 535
    	}
    	; Select mission
    	MouseClick, left,  xPos,  yPos
    	Sleep, 1000
    	; Send companion
    	MouseClick, left,  923,  621
    	Sleep, 1000
    	; Close window
    	crewManageToggle("off")
    }
    
    ; Checks if there is less than a minute left on tradeskills. The
    ; bot uses this to determine if it should wait before going on the
    ; next space combat mission.
    
    getMissionTimer() {
    	; todo
    }
    
    ; Checks if the specified companion id is currently on a tradeskill
    ; mission or not
    
    hasActiveMission(id) {
    	; set mouse xPos
    	xPos = 279
    	; get yPos by companion id
    	if (id = 1) {
    		yPos = 350
    	}else if (id = 2) {
    		yPos = 414
    	}else if (id = 3) {
    		yPos = 478
    	}
    	; Make sure Crew Management window is open
    	crewManageToggle("on")
    	; check companion
    	PixelGetColor, color, xPos, yPos ; crew management companion [X] ("cancel current task")
    	; Make sure Crew Management window is closed
    	crewManageToggle("off")
    	; check if mission is active
    	if (id = 1 AND color="0xC0A669") {
    		return true
    	}else if (id = 2 AND color="0xD5BD83") {
    		return true
    	}else if (id = 3 AND color="0xDDC184") {
    		return true
    	}else{
    		return false
    	}
    }
    
    ; Checks for pending reward windows (quest, end of space combat mission, 
    ; tradeskill completion, tradeskill failure, etc). If it detects one on the
    ; left or right side of the screen it will close them.
    
    hasMissionComplete() {
    	Loop {
    		; Attempt to open pending data in case it's closed
    		MouseClick, left, 964, 37 ; Pending Rewards
    		Sleep, 1000
    		; Grab pixel color magic
    		PixelGetColor, color_left, 207, 401
    		PixelGetColor, color_right, 819, 400
    		; Check if there is a pending reward on the left
    		if (color_right="0x000000") {
    			; Click the accept button for rewards
    			MouseClick, left, 933, 573 ; Accept reward
    			Sleep, 1000
    			; Click the accept button for failures (just in case)
    			MouseClick, left, 933, 536 ; Accept reward
    			Sleep, 1000
    			continue
    		}
    		; Check if there is a pending reward on the right
    		if (color_left="0x000000") {
    			; Click the accept button for rewards
    			MouseClick, left, 227, 580 ; Accept reward
    			Sleep, 1000
    			; Click the accept button for failures (just in case)
    			MouseClick, left, 227, 543 ; Accept reward
    			Sleep, 1000
    			continue
    		}
    		break
    	}
    }
    
    ;--------------------------------------------------
    ; Spacebot Functions
    ;--------------------------------------------------
    
    ; Handles the process for the space combat bot
    
    spaceHandler() {
    	global
    	; set the play status
    	inPlay:=1
    	; start the combat mission
    	startMissionBot(1)
    	; leave the mission
    	hasMissionComplete()
    	; fix the camera after you get out
    	fixCamera()
    }
    
    ; Moves you out of your command chair in order
    ; to enable bot to loop space missions
    
    fixCamera() {
    	; Send "W" key to move out of chair
    	SendInput, {w}
    	Sleep, 1000
    	; Right click the chair
    	; MouseClick, left,  519,  528
    	; Sleep, 1000
    }
    
    ; Right clicks the galaxy map or chair
    ; to open the galaxy map. See data.txt for
    ; more information.
    
    openGalaxyMap() {
    	; MouseClick, right,  502,  444
    	; Sleep, 2000
    	MouseClick, right,  519,  528
    	Sleep, 2000
    }
    
    ; Opens the appropriate galaxy from the
    ; galaxy map based on specificed mission or
    ; galaxy id. See data.txt for more information.
    
    openGalaxy(id) {
    	; Hutt Space
    	if (id = 1) {
    		MouseClick, left,  701,  352
    		Sleep, 2000
    		MouseClick, left,  466,  336
    		Sleep, 2000
    	}
    }
    
    ; Starts the mission from the galaxy map
    ; if in the correct galaxy. Make sure it is
    ; called after openGalaxy(). See data.txt for
    ; more information.
    
    openMission(id) {
    	; Saluecami Fleet Action
    	if (id = 1) {
    		; open the missions galaxy
    		openGalaxy(1)
    		; open the mission
    		MouseClick, left,  863,  669
    		Sleep, 2000
    		MouseClick, left,  480,  441
    		Sleep, 2000
    	}
    }
    
    ; Start running the .torbot script for the
    ; specified mission id 
    
    startMissionBot(id) {
    	; start the bot
    	; script = spacecombat%id%
    	script = mission%id%
    	ttHandler("Started %script%.torbot", 1000)
    	runBot(script)
    }
    
    ; begin the main bot that handles space combat
    ; and tradeskills
    
    startBot() {
    	global
    	; Make SWTOR the active window
    	WinWait, Star Wars: The Old Republic, 
    	IfWinNotActive, Star Wars: The Old Republic, , WinActivate, Star Wars: The Old Republic, 
    	WinWaitActive, Star Wars: The Old Republic, 
    	; loop space missions
    	; tradeskills inbetween missions if enabled
    	if(spaceEnabled) {
    		Loop %runCount% {
    			openGalaxyMap() ; open the galaxy map
    			openMission(missionId) ; open the mission's galaxy and mission
    			; loop until we detect mission start
    			Loop {
    				PixelGetColor, color, 1004, 757
    				if(color = "0x084584") {
    					; are we going to record?
    					if(inRecord = 1) {
    						inRecord:=2 ; set the status to recording
    						recordBot() ; start the recording
    					; start the space combat mission handler
    					}else if(inRecord=0 AND inPlay=0) {
    						spaceHandler()
    					}
    				}
    			}
    			; run tradeskills after the mission
    			if(tradeskillEnabled) {
    				tradeskillHandler()
    			}
    		}
    	}
    	; space disabled and tradeskills enabled
    	; loop tradeskills checking every 30 seconds
    	if(spaceEnabled = false AND tradeskillEnabled = true) {
    		Loop {
    			tradeskillHandler()
    			Sleep 30000
    		}
    	}
    }
    
    ttHandler(msg, timer=2000) {
    	ToolTip, %msg%
    	SetTimer, RemoveToolTip, %timer%
    }
    
    ;--------------------------------------------------
    ; Timers
    ;--------------------------------------------------
    
    ; timer for removing tooltips
    RemoveToolTip:
    	SetTimer, RemoveToolTip, Off
    	ToolTip
    return
    
    ; timer for mouse movement recording
    RecordMouseKey:
    	TimeMouseMove_Old := TimeMouseMove
    	MouseData := GetMouseMove(TimeMouseMove_Old)
    	if (MouseData_old = MouseData) {
    		return
    	}
    	MouseData_old := MouseData
    	RecordCount++
    	MouseData_%RecordCount% := MouseData "|" TimeMouseMove_Old - TimeMouseMove 
    	TimeMouseMove := A_TickCount
    return
    
    ;--------------------------------------------------
    ; Key Binds
    ;--------------------------------------------------
    
    ; Kill the bot
    
    Numpad0::
    	ExitApp
    return
    
    ; Start the bot
    
    Numpad1::
    	startBot()
    return
    
    ; Start new recording. Press this before
    ; you enter the space mission using Numpad1.
    ; It will begin recording as soon as the mission starts.
    
    Numpad4::
    	; Make sure it is not running a torbot script already
    	if(inPlay = 1) {
    		ttHandler("Recording disabled during torbot scripts", 1000)
    		return
    	}
    	; Make sure it is not currently recording
    	if(inRecord = 0) {
    		ttHandler("Recording has been started `nWaiting for space mission to load", 5000)
    		inRecord:=1 ; set state to recording
    	}
    return
    
    ; Saves the bot manually. Normally it saves the
    ; bot recording automatically.
    
    Numpad6::
    	saveRecording() ; 
    return
    
    ; Get x/y and color at mouse position
    
    Numpad7::
    	MouseGetPos, xPos, yPos
    	PixelGetColor, color, xPos, yPos
    	MsgBox %color% at %xPos%, %yPos%
    return
    
    ; Get color at specific x,y pos
    
    Numpad8::
    	PixelGetColor, color, 693, 263
    	MsgBox %color%
    return

Similar Threads

  1. [Release] Undetected Runescape AHK Bot.
    By Zantomato in forum Runescape
    Replies: 207
    Last Post: 06-26-2019, 12:35 AM
  2. [Tutorial] questions about the Korean bot AHK
    By azxsdc1 in forum Overwatch Exploits|Hacks
    Replies: 1
    Last Post: 08-18-2016, 01:54 AM
  3. [Bot] WTB AutoIT or AHK Aim assist bot
    By Darksun22 in forum Overwatch Exploits|Hacks
    Replies: 25
    Last Post: 08-05-2016, 05:38 AM
  4. [Request] Lt.Vachem Bot AutoIt or AHK
    By Ponoir in forum Diablo 3 Bots Questions & Requests
    Replies: 1
    Last Post: 07-13-2012, 07:33 AM
  5. [Request] Lt.Vachem Bot AutoIt or AHK
    By Ponoir in forum D3 Leveling profiles
    Replies: 7
    Last Post: 07-09-2012, 10:43 PM
All times are GMT -5. The time now is 06:35 PM. Powered by vBulletin® Version 4.2.3
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search