Nighteyez Posted January 15, 2006 Share Posted January 15, 2006 (edited) Bah, I timed out on my first post, so hopefully I remember the right info. I'm having a hard time figuring out where my loop should go and what type of loop I should use. This is the what I want the script to do: Run a few little things, nothing big Start the apply_lure function (that part is fine) Have the cast_pole and find_float run a set amount of times, then run the apply_lure function again and continue from there 1) Where should I put this loop information? 2) Am I currently using the right type of loop? 3) Can I use a loop with this and have it work correctly? My loop code is currently on lines 124 to 131. code is below expandcollapse popup; **************************************************************************************************** **** ; FishBOT by Me242 - adapted from Foobie script which was adapted from Pantless Krab's example ; Version 1.2 ; Globals $title = "WoW FishBOT" ; Title of game window. $win_title = "World of Warcraft" $top_border_height = 23 $left_border_width = 4 ; How many pixels to move to the right each time. $move_left = 10 ; How many pixels to move down for each run. $move_down = 25 ; Pixels to move back LEFT when bobber is found. ; Note, if the cursor moves TOO far to the left when found, lower this value and vice versa. $found_move_left = 10 ; Pixels to move DOWN when bobber is found. ; Note, if the cursor moves TOO far down when found, lower this value and vice versa. $found_move_down = 5 ; Button to hit for fishing skill. $fishing_pole = 1 ; Set to 0 if you do NOT use the QuickLoot addon from ; [url=http://www.curse-gaming.com/mod.php?addid=132]http://www.curse-gaming.com/mod.php?addid=132[/url] ; If you ARE using quickloot, set it to 1 ;$using_quickloot = 1 ; Your resolution. Only 1024x786 & 800x600 supported with without personal modification. $screen_width = 1024 $screen_height = 768 ; Waiting time between throws. $time_to_wait = 30050 ; Display what its doing in traytips.. useful for debugging and/or fun. 1 = on, 0 = off $traytips = 1 dim $start_time ; **************************************************************************************************** **** ; Hot Keys HotKeySet("{PAUSE}", "request_end") ; **************************************************************************************************** **** if not WinExists($win_title, "") then msg($win_title & " window must be open.") Exit endif WinActivate($win_title, "") WinSetOnTop($win_title, "", 0) Sleep(500) check_window() ;AutoItSetOption ( "PixelCoordMode", 0 ) $win_pos = WinGetPos($win_title, "") $win_x = $win_pos[0] + $left_border_width $win_y = $win_pos[1] + $top_border_height $top = $win_y + (.25 * $screen_height) $bottom = $top + (.35 * $screen_height) - 1 $left = $win_x + (.15 * $screen_width) $right = $left + $screen_width - (.15 * 2.0 * $screen_width) - 1 ; Here we set the values for the different resolutions. ; I've added a dummy one in the last 'elseif' you can play with ; if you need to, without damaging the default ones. ; If you run 1024 x 768 or 800 x 600, you should not need to modify this. ; For 1024x768 if $screen_width = 1024 and $screen_height = 768 then ; Cordinates to look for the yellow "Fishing Bobber" text. $bobber_text_location_x1 = 458 $bobber_text_location_x2 = 555 $bobber_text_location_y1 = 17 $bobber_text_location_y2 = 18 ; location on the character screeen of the fishing pole $pole_location_x = 136 $pole_location_y = 510 else MsgBox(0, "Resolution Error", "Only 1024x768 and 800x600 are supported without personal modification") Exit endif ; Show a visual confirmation by making the mouse draw the area on the screen ; that will be used to scan for the bobber. traytp("Drawing search area") MouseMove($left, $top, 0) MouseMove($right, $top, 10) MouseMove($right, $bottom, 10) MouseMove($left, $bottom, 10) MouseMove($left, $top, 10) Send ("/dnd I'm fishing. . .a lot") Sleep (50) Send ("{ENTER}") ;sets you to "Do Not Disturb" Sleep (500) Send ("w") ;makes sure that you are not sitting, when run running the bot Sleep (500) ; string for the loop that will re-apply the lure $i = 0 apply_lure() Do cast_pole() find_float() $i = $i + 1 Until $i = 3 apply_lure ; **************************************************************************************************** **** func find_float() while 1 ; Reset the $pos back to 0. $pos = 0 if TimerDiff($start_time) >= $time_to_wait then traytp("Resting.. waited long enough") cast_pole() endif sleep(30) ; Move cursor to starting position. MouseMove($top, $left, 1) ; Get its location. Put it in $mousepos_left_next and $mousepos_top_next since those needs to be set ; for the first run. $mousepos = MouseGetPos() $mousepos_left_next = $left $mousepos_top_next = $top ; Loop this until we found the bobber ($pos isnt 0 when found). while $pos = 0 ; Run the move_left function that moves the mouse to the right and looks for it. $pos = move_left($mousepos_left_next, $mousepos_top_next, $top) ; If $pos isnt 0, we found the bobber. if $pos <> 0 then ; Get current cursor position $pos = MouseGetPos() ; Calculate the positions to move the cursor back to. $move_left_to = $pos[0] - $found_move_left $move_top_to = $pos[1] + $found_move_down ; Move the cursor back the number of pixels. MouseMove($move_left_to, $move_top_to, 0) ; We should be close to the bobber now. Start looking for the splash at these coords. traytp("Found bobber at x:" & $move_left_to & " y:" & $move_top_to & " - Waiting for splash") find_splash($move_left_to, $move_top_to) endif ; Bobber wasnt found. Move down the number of defined pixels. $mousepos_top_next = $mousepos_top_next + $move_down ; Check if were at the bottom right border. Bobber wasnt found if so. Restart from beginning. if $mousepos_left_next <= $right then if $mousepos_top_next >= $bottom then $start_time = $time_to_wait exitloop endif endif ; Relax a little. Sleep(20) wend ; Relax a little. Sleep(10) wend endfunc ; Function to move the mouse to the right and looking for the bobber color. func move_left($mousepos_left_next, $mousepos_top_next, $top) traytp("Looking for bobber, at x:" & $mousepos_left_next & " to x:" & $right & " at y:" & $mousepos_top_next) ; Loop until we found the right border. while $mousepos_left_next <= $right ; Search for the bobber text using high tolerance (50) since its still fading in. $pos = PixelSearch($bobber_text_location_x1, $bobber_text_location_y1, $bobber_text_location_x2, $bobber_text_location_y2, 0xFFD200, 50, 1) if @error then ; Not found. Keep going. SetError(0) else ; Found it ! Wait a second to allow it to fade in. traytp("Looks promising at: x:" & $pos[0] & " y:" & $pos[1] & " - examine location.") sleep(1000) ; Search for the bobber text again using less tolerance (5). $pos = PixelSearch($bobber_text_location_x1, $bobber_text_location_y1, $bobber_text_location_x2, $bobber_text_location_y2, 0xFFD200, 5, 1) if @error then ; Hm, not here. Keep looking. False alarm from first search. SetError(0) else ; Found the bobber. Return its position traytp("Found ""Fishing Bobber"" text at: x:" & $pos[0] & " y:" & $pos[1]) return $pos endif endif ; Calculate where to move the mouse to next. $mousepos_left_next = $mousepos_left_next + $move_left ; Move the cursor to the right, using aboves coordinates. MouseMove($mousepos_left_next, $mousepos_top_next, 0) wend ; Nada found. Return $pos 0 so it moves down a bit and restarts the search. return 0 endfunc ; **************************************************************************************************** **** func find_splash($float_x, $float_y) $search_left = $float_x - 32 $search_right = $search_left + 62 $search_top = $float_y - 32 $search_bottom = $search_top + 64 ; Usually you do not have to modify the search color for the splash, as the pixels ; have a very distinctive, bright color. $splash_color = 0xF6F6F6 ; Sometimes 30 tolerance works well, sometimes 20 is better in lit areas to avoid catching highlights ; in other things. $splash_tolerance = 20 ; The search step can be pretty small here (1 to 3) without worries because the search area is ; so small once it has been narrowed down - speed isn't much of an issue. $splash_search_step = 2 ; Search for splash while TimerDiff($start_time) < $time_to_wait $pos = PixelSearch($search_left, $search_top, $search_right, $search_bottom, $splash_color, $splash_tolerance, $splash_search_step) if @error then SetError(0) else ; Click on the splash traytp("Got splash at x:" & $pos[0] & " y:" & $pos[1] & " - Loot it.") ;This is old loot method ;MouseClick("right", $pos[0], $pos[1], 1, 2) Send ("{ShiftDown}") MouseClick ("right") Sleep (50) Send ("{ShiftUp}") Sleep(1100) MouseMove($left, $bottom, 2) ExitLoop endif Sleep(10) wend ; Cast pole and start all over again. cast_pole() endfunc ; **************************************************************************************************** **** func cast_pole() $start_time = TimerInit() traytp("Pressing " & $fishing_pole & " to cast pole") Send($fishing_pole) Sleep(1000) endfunc ; **************************************************************************************************** **** func check_window() $dimensions = WinGetClientSize($win_title, "") if $dimensions[0] <> $screen_width or $dimensions[1] <> $screen_height then msg("Invalid window size. You must use " & $screen_width & "x" & $screen_height & " resolution in window mode.") Exit endif endfunc ; **************************************************************************************************** **** func msg($text) MsgBox(0, $title, $text) endfunc func traytp($text) if $traytips = 1 then TrayTip ($title, $text, 3, 16) endif endfunc ; **************************************************************************************************** **** func request_end() Send ("/dnd") Send ("{ENTER}") $MB_YESNO = 4 $MB_YES = 6 if MsgBox($MB_YESNO, $title, "End script?") == $MB_YES then Exit endif endfunc ; **************************************************************************************************** **** func drain_timer() Msg("Restart") $start_time = $start_time - $time_to_wait endfunc ; **************************************************************************************************** **** func apply_lure() Send ("c") sleep (2000) Send ("{ShiftDown}") Send ("l") Send ("{ShiftUp}") ; move the mouse to the weapon one slot on the character screen MouseMove($pole_location_x, $pole_location_y) MouseClick ("left") sleep (7000) send ("c") sleep (100) cast_pole() endfunc Edited January 15, 2006 by Nighteyez Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted January 15, 2006 Moderators Share Posted January 15, 2006 Try reposting that using either [ code] (without the space infront of the c) and [ /code] without the space infront of the /. (Code tags) or even [ codebox] [ /codebox] [ code] Script posting [ /code] Without spaces Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Nighteyez Posted January 15, 2006 Author Share Posted January 15, 2006 Try reposting that using either [ code] (without the space infront of the c) and [ /code] without the space infront of the /. (Code tags) or even [ codebox] [ /codebox] [ code] Script posting [ /code] Without spaces will do, sorry about that, i'll just edit the first post Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted January 15, 2006 Moderators Share Posted January 15, 2006 I don't know what a fish bot is... but you might want consider gettting Client or Window Coords so you don't have to worry about what the screen resolution is... may save you alot of coding errors/situations down the road. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Nighteyez Posted January 15, 2006 Author Share Posted January 15, 2006 The stuff with the resolution hasn't caused me any issues. Been using a slightly different version of the script for many months now. I'm just having issues with the loop regarding those functions from the first post. Do you have any ideas regarding the loop? If you need any clarification, I can provide it. Also, Fishbot is just the name of the utility, I'm just using the autoit code to mainly mimic keystrokes and mouse movements. Link to comment Share on other sites More sharing options...
GrungeRocker Posted January 15, 2006 Share Posted January 15, 2006 what about just posting the relevant code? id don't want to read the full code -.- in germany it is 05:22 am [font="Verdana"]In work:[list=1][*]InstallIt[*]New version of SpaceWar[/list] [/font] Link to comment Share on other sites More sharing options...
Valuater Posted January 15, 2006 Share Posted January 15, 2006 have you checked this in SciTE ... just for errors???? i see this one traytp("Found bobber at x:" & $....... traytip???? 8) Link to comment Share on other sites More sharing options...
GrungeRocker Posted January 15, 2006 Share Posted January 15, 2006 have you checked this in SciTE ... just for errors???? i see this one traytp("Found bobber at x:" & $....... traytip???? 8)traytp is a defined function in this script XD is think this shoul be working: expandcollapse popup; **************************************************************************************************** ; FishBOT by Me242 - adapted from Foobie script which was adapted from Pantless Krab's example ; Version 1.2 ; Globals $title = "WoW FishBOT" ; Title of game window. $win_title = "World of Warcraft" $top_border_height = 23 $left_border_width = 4 ; How many pixels to move to the right each time. $move_left = 10 ; How many pixels to move down for each run. $move_down = 25 ; Pixels to move back LEFT when bobber is found. ; Note, if the cursor moves TOO far to the left when found, lower this value and vice versa. $found_move_left = 10 ; Pixels to move DOWN when bobber is found. ; Note, if the cursor moves TOO far down when found, lower this value and vice versa. $found_move_down = 5 ; Button to hit for fishing skill. $fishing_pole = 1 ; Set to 0 if you do NOT use the QuickLoot addon from ; [url=http://www.curse-gaming.com/mod.php?addid=132]http://www.curse-gaming.com/mod.php?addid=132[/url] ; If you ARE using quickloot, set it to 1 ;$using_quickloot = 1 ; Your resolution. Only 1024x786 & 800x600 supported with without personal modification. $screen_width = 1024 $screen_height = 768 ; Waiting time between throws. $time_to_wait = 30050 ; Display what its doing in traytips.. useful for debugging and/or fun. 1 = on, 0 = off $traytips = 1 dim $start_time ; **************************************************************************************************** ; Hot Keys HotKeySet("{PAUSE}", "request_end") ; **************************************************************************************************** if not WinExists($win_title, "") then msg($win_title & " window must be open.") Exit endif WinActivate($win_title, "") WinSetOnTop($win_title, "", 0) Sleep(500) check_window() ;AutoItSetOption ( "PixelCoordMode", 0 ) $win_pos = WinGetPos($win_title, "") $win_x = $win_pos[0] + $left_border_width $win_y = $win_pos[1] + $top_border_height $top = $win_y + (.25 * $screen_height) $bottom = $top + (.35 * $screen_height) - 1 $left = $win_x + (.15 * $screen_width) $right = $left + $screen_width - (.15 * 2.0 * $screen_width) - 1 ; Here we set the values for the different resolutions. ; I've added a dummy one in the last 'elseif' you can play with ; if you need to, without damaging the default ones. ; If you run 1024 x 768 or 800 x 600, you should not need to modify this. ; For 1024x768 if $screen_width = 1024 and $screen_height = 768 then ; Cordinates to look for the yellow "Fishing Bobber" text. $bobber_text_location_x1 = 458 $bobber_text_location_x2 = 555 $bobber_text_location_y1 = 17 $bobber_text_location_y2 = 18 ; location on the character screeen of the fishing pole $pole_location_x = 136 $pole_location_y = 510 else MsgBox(0, "Resolution Error", "Only 1024x768 and 800x600 are supported without personal modification") Exit endif ; Show a visual confirmation by making the mouse draw the area on the screen ; that will be used to scan for the bobber. traytp("Drawing search area") MouseMove($left, $top, 0) MouseMove($right, $top, 10) MouseMove($right, $bottom, 10) MouseMove($left, $bottom, 10) MouseMove($left, $top, 10) Send ("/dnd I'm fishing. . .a lot") Sleep (50) Send ("{ENTER}") ;sets you to "Do Not Disturb" Sleep (500) Send ("w") ;makes sure that you are not sitting, when run running the bot Sleep (500) ; string for the loop that will re-apply the lure $i = 0 apply_lure() Do cast_pole() find_float() $i = $i + 1 Until $i = 3 apply_lure() ; **************************************************************************************************** func find_float() while 1 ; Reset the $pos back to 0. $pos = 0 if TimerDiff($start_time) >= $time_to_wait then traytp("Resting.. waited long enough") cast_pole() endif sleep(30) ; Move cursor to starting position. MouseMove($top, $left, 1) ; Get its location. Put it in $mousepos_left_next and $mousepos_top_next since those needs to be set ; for the first run. $mousepos = MouseGetPos() $mousepos_left_next = $left $mousepos_top_next = $top ; Loop this until we found the bobber ($pos isnt 0 when found). while $pos = 0 ; Run the move_left function that moves the mouse to the right and looks for it. $pos = move_left($mousepos_left_next, $mousepos_top_next, $top) ; If $pos isnt 0, we found the bobber. if $pos <> 0 then ; Get current cursor position $pos = MouseGetPos() ; Calculate the positions to move the cursor back to. $move_left_to = $pos[0] - $found_move_left $move_top_to = $pos[1] + $found_move_down ; Move the cursor back the number of pixels. MouseMove($move_left_to, $move_top_to, 0) ; We should be close to the bobber now. Start looking for the splash at these coords. traytp("Found bobber at x:" & $move_left_to & " y:" & $move_top_to & " - Waiting for splash") find_splash($move_left_to, $move_top_to) endif ; Bobber wasnt found. Move down the number of defined pixels. $mousepos_top_next = $mousepos_top_next + $move_down ; Check if were at the bottom right border. Bobber wasnt found if so. Restart from beginning. if $mousepos_left_next <= $right then if $mousepos_top_next >= $bottom then $start_time = $time_to_wait exitloop endif endif ; Relax a little. Sleep(20) wend ; Relax a little. Sleep(10) wend endfunc ; Function to move the mouse to the right and looking for the bobber color. func move_left($mousepos_left_next, $mousepos_top_next, $top) traytp("Looking for bobber, at x:" & $mousepos_left_next & " to x:" & $right & " at y:" & $mousepos_top_next) ; Loop until we found the right border. while $mousepos_left_next <= $right ; Search for the bobber text using high tolerance (50) since its still fading in. $pos = PixelSearch($bobber_text_location_x1, $bobber_text_location_y1, $bobber_text_location_x2, $bobber_text_location_y2, 0xFFD200, 50, 1) if @error then ; Not found. Keep going. SetError(0) else ; Found it ! Wait a second to allow it to fade in. traytp("Looks promising at: x:" & $pos[0] & " y:" & $pos[1] & " - examine location.") sleep(1000) ; Search for the bobber text again using less tolerance (5). $pos = PixelSearch($bobber_text_location_x1, $bobber_text_location_y1, $bobber_text_location_x2, $bobber_text_location_y2, 0xFFD200, 5, 1) if @error then ; Hm, not here. Keep looking. False alarm from first search. SetError(0) else ; Found the bobber. Return its position traytp("Found ""Fishing Bobber"" text at: x:" & $pos[0] & " y:" & $pos[1]) return $pos endif endif ; Calculate where to move the mouse to next. $mousepos_left_next = $mousepos_left_next + $move_left ; Move the cursor to the right, using aboves coordinates. MouseMove($mousepos_left_next, $mousepos_top_next, 0) wend ; Nada found. Return $pos 0 so it moves down a bit and restarts the search. return 0 endfunc ; **************************************************************************************************** func find_splash($float_x, $float_y) $search_left = $float_x - 32 $search_right = $search_left + 62 $search_top = $float_y - 32 $search_bottom = $search_top + 64 ; Usually you do not have to modify the search color for the splash, as the pixels ; have a very distinctive, bright color. $splash_color = 0xF6F6F6 ; Sometimes 30 tolerance works well, sometimes 20 is better in lit areas to avoid catching highlights ; in other things. $splash_tolerance = 20 ; The search step can be pretty small here (1 to 3) without worries because the search area is ; so small once it has been narrowed down - speed isn't much of an issue. $splash_search_step = 2 ; Search for splash while TimerDiff($start_time) < $time_to_wait $pos = PixelSearch($search_left, $search_top, $search_right, $search_bottom, $splash_color, $splash_tolerance, $splash_search_step) if @error then SetError(0) else ; Click on the splash traytp("Got splash at x:" & $pos[0] & " y:" & $pos[1] & " - Loot it.") ;This is old loot method ;MouseClick("right", $pos[0], $pos[1], 1, 2) Send ("{ShiftDown}") MouseClick ("right") Sleep (50) Send ("{ShiftUp}") Sleep(1100) MouseMove($left, $bottom, 2) ExitLoop endif Sleep(10) wend ; Cast pole and start all over again. cast_pole() endfunc ; **************************************************************************************************** func cast_pole() $start_time = TimerInit() traytp("Pressing " & $fishing_pole & " to cast pole") Send($fishing_pole) Sleep(1000) endfunc ; **************************************************************************************************** func check_window() $dimensions = WinGetClientSize($win_title, "") if $dimensions[0] <> $screen_width or $dimensions[1] <> $screen_height then msg("Invalid window size. You must use " & $screen_width & "x" & $screen_height & " resolution in window mode.") Exit endif endfunc ; **************************************************************************************************** func msg($text) MsgBox(0, $title, $text) endfunc func traytp($text) if $traytips = 1 then TrayTip ($title, $text, 3, 16) endif endfunc ; **************************************************************************************************** func request_end() Send ("/dnd") Send ("{ENTER}") $MB_YESNO = 4 $MB_YES = 6 if MsgBox($MB_YESNO, $title, "End script?") == $MB_YES then Exit endif endfunc ; **************************************************************************************************** func drain_timer() Msg("Restart") $start_time = $start_time - $time_to_wait endfunc ; **************************************************************************************************** func apply_lure() Send ("c") sleep (2000) Send ("{ShiftDown}") Send ("l") Send ("{ShiftUp}") ; move the mouse to the weapon one slot on the character screen MouseMove($pole_location_x, $pole_location_y) MouseClick ("left") sleep (7000) send ("c") sleep (100) cast_pole() endfunc [font="Verdana"]In work:[list=1][*]InstallIt[*]New version of SpaceWar[/list] [/font] Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now