Jump to content

Please Help: Simple Loop Script


Recommended Posts

Objective: Have a script that WAITS till I press NUMPAD1 and runs, than will run AGAIN when I press NUMPAD1

What it will do: Drag an item to a spot release it, and input 2 then press Enter. Drag another item into a spot release it, and input 1 then press Enter. Then goto a specific button and press it. This procedure will be repeated 45 times.

This is what I have so far, obviously it's not working at the moment :lmao:

HotKeySet ("{NUMPAD1}","Craft")

HotKeySet ("{NUMPAD2}","Stop")

Func Craft ()

Opt ("MouseCoordMode",1)

Opt ("MouseClickDragDelay",100)

For $i = 1 to 45

MouseClickDrag ("left",105,400,145,215,3)

Send ("2{Enter}")

MouseClickDrag ("left",160,400,145,215,3)

Send ("1{Enter}")

MouseClick ("left",325,260,1,3)

Sleep (500)

Next

EndFunc

Func Stop ()

Sleep (100)

EndFunc

While 1

Sleep (1000)

Wend

Exit

Edited by biggaroupa
Link to comment
Share on other sites

This is probably a stupid question but u do have a main code body right? The code you have there will not actually execute anything it's just a bunch of definitions.

If this is all u have try running this.

HotKeySet ("{NUMPAD1}","Craft")

Func Craft ()

For $i = 1 to 45 Step +1

MouseClickDrag ("left",150,690,144,356)

Send ("2{Enter}")

Sleep (100)

MouseClickDrag ("left",246,688,144,356)

Send ("1{Enter}")

Sleep (100)

MouseClick ("left",524,362,1)

Sleep (100)

Next

EndFunc

While 1

Sleep(200)

wend

Link to comment
Share on other sites

Why do I need to add the While statement?

Furthermore, if I convert this script to a EXE, if I press "1" will the script run only once and shutdown, or can I press "1" anytime I want to have the script run again?

If this is all u have try running this.

HotKeySet ("{NUMPAD1}","Craft")

Func Craft ()

For $i = 1 to 45 Step +1

MouseClickDrag ("left",150,690,144,356)

Send ("2{Enter}")

Sleep (100)

MouseClickDrag ("left",246,688,144,356)

Send ("1{Enter}")

Sleep (100)

MouseClick ("left",524,362,1)

Sleep (100)

Next

EndFunc

While 1

Sleep(200)

wend

Link to comment
Share on other sites

I think you misunderstand the use of the hotkey function. It's purpose is to allow you to link a hotkey to a function within a script while the script is running. If you want to have a hotkey run your script once and then exit you need to link a global hotkey to run your script.

There are many programs that will do this, but I recommend hoekey (google it) it's ultra minilist and does what it does well. It'll allow you to link a hotkey to run your script.

Depending on how often u intend to be using this script though it might be a better option to have an autoitscript running in the background all the time, the cpu time used up by a while loop with a sleep(200) command is pretty minimal and you wouldn't have to wait for the autoit command interpreter to load whenever u press your hotkey.

Link to comment
Share on other sites

How would I have the script running at all times, and having it call my Func when I press a hot key?

I think you misunderstand the use of the hotkey function.  It's purpose is to allow you to link a hotkey to a function within a script while the script is running.  If you want to have a hotkey run your script once and then exit you need to link a global hotkey to run your script.

There are many programs that will do this, but I recommend hoekey (google it) it's ultra minilist and does what it does well.  It'll allow you to link a hotkey to run your script. 

Depending on how often u intend to be using this script though it might be a better option to have an autoitscript running in the background all the time, the cpu time used up by a while loop with a sleep(200) command is pretty minimal and you wouldn't have to wait for the autoit command interpreter to load whenever u press your hotkey.

<{POST_SNAPBACK}>

Link to comment
Share on other sites

That's what the while loop is for...

While 1
    Sleep(1)
WEnd

In AutoIT 1 = true, so the While loop will loop until 1 isn't true. Which is never :lmao:

"I thoroughly disapprove of duels. If a man should challenge me, I would take him kindly and forgivingly by the hand and lead him to a quiet place and kill him." - Mark TwainPatient: "It hurts when I do $var_"Doctor: "Don't do $var_" - Lar.
Link to comment
Share on other sites

So far this is what I have, done some more testing/tweaking.

Problems so far:

1)Can't have the script stop, while running through the loop. (my stop func not being called)

2)When I try to run this script in a game, the mouse doesn't seem to be following the cords I'm using, even though they should be correct.

HotKeySet ("{NUMPAD1}","Craft")

HotKeySet ("{NUMPAD2}","Stop")

Func Craft ()

Opt ("MouseCoordMode",1)

Opt ("MouseClickDragDelay",100)

For $i = 1 to 3

MouseClickDrag ("left",105,400,145,215,3)

Send ("2{Enter}")

MouseClickDrag ("left",160,400,145,215,3)

Send ("1{Enter}")

MouseClick ("left",325,260,1,3)

Sleep (500)

Next

EndFunc

Func Stop ()

Sleep (100)

EndFunc

While 1

Sleep (1000)

Wend

Exit

Link to comment
Share on other sites

Are u running the game full screen at a different res? Maybe try running it windowed if that is supported. I'm unsure what you're trying to achive with the stop function. If you want it to terminate the script then u just want this.

Func Stop()
Exit
Endfunc

If u want it to just return to waiting for a keypress to run the craft() function again then it's somewhat more complicated, but still doable.

Link to comment
Share on other sites

What I would enjoy seeing is a way of having AutoIt count the number of times it looped and somehow.

<{POST_SNAPBACK}>

Dim $x = 0, $loopcount = 0
HotKeySet("{numpad9}","WhereAmI")
HotKeySet ("{NUMPAD1}","Craft")
HotKeySet ("{NUMPAD2}","Stop")



; primary data loop
While 1
   $loopcount = $loopcount + 1
   Sleep (200)
Wend

Func Craft ()
   Opt ("MouseCoordMode",1)
   Opt ("MouseClickDragDelay",100)
   For $i = 1 to 3
      MouseClickDrag ("left",105,400,145,215,3)
      Send ("2{Enter}")
      MouseClickDrag ("left",160,400,145,215,3)
      Send ("1{Enter}")
      MouseClick ("left",325,260,1,3)
      Sleep (500)
   Next
EndFunc; <==Craft main crafting function

Func Stop ()
   Exit
EndFunc; <==Stop allows you to quit the script at any time

Func WhereAmI()
   MsgBox(0,"Inside Craft Loop","Iteration: " & $x,2)
   MsgBox(0,"Primary Data Loop", "Iteration: " & $loopcount,2)
EndFunc; <==Allows to see where the count is.
Edited by Blue_Drache

Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Link to comment
Share on other sites

It seems I can't get out of my FOR loop, I guess I'll have to use a while loop and maybe catch the "STOP" to end the CRAFT function.

The game is in full screen mode, I tried capturing the mouse coords by using AutoItInfo, but for some reason it keeps giving me different COORDS for the same location after multiple tries =(

Link to comment
Share on other sites

It seems I can't get out of my FOR loop, I guess I'll have to use a while loop and maybe catch the "STOP" to end the CRAFT function.

The game is in full screen mode, I tried capturing the mouse coords by using AutoItInfo, but for some reason it keeps giving me different COORDS for the same location after multiple tries =(

<{POST_SNAPBACK}>

Make sure the info tool is set to give you the coords relative to the window, and not global to the screen.

If you want to use a while loop, you'll have to put in a counter.

Dim $CraftLoopCounter = 0
While 1
   Sleep(10); this is a tiny sleep to make sure that the loop doesn't hog the processor
   $CraftLoopCounter = $CraftLoopCounter + 1
  ; put craft code here
   If $CraftLoopCounter >=48 then ExitLoop
WEnd

Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Link to comment
Share on other sites

So, I set the Coord Mode to "Window"

What exactly is the difference between "window" and "client" mode anyways?

Make sure the info tool is set to give you the coords relative to the window, and not global to the screen. 

If you want to use a while loop, you'll have to put in a counter. 

Dim $CraftLoopCounter = 0
While 1
   Sleep(10); this is a tiny sleep to make sure that the loop doesn't hog the processor
   $CraftLoopCounter = $CraftLoopCounter + 1
  ; put craft code here
   If $CraftLoopCounter >=48 then ExitLoop
WEnd

<{POST_SNAPBACK}>

Link to comment
Share on other sites

There is only "full screen mode" and "window mode" for your game. Unless you are running on DOS.

In "full screen mode", you will not have a window border surrounding your game. Normally, your game client should state the resolution that the game will run in full screen. eg. 800x600 or 1024x768 ...

And in "window mode", you will have a window border surrounding your game. And this will be good for you to determine the real coords for your program in your game.

[font="Arial"]Thanks[/font]
If @error = me Then $sorry
Else
   Do
      $clarifyMe
   Until $meClear
EndIF
MsgBox(0,"Special Message!","Special Thanks to " & $allHadReplied,$Forever)
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...