The FULL guide to making your own Bots/Macros...PART1

12/13/2007 06:49 Hiyoal#1
Part 1


Hi all,

As you have read in the thread title, this is a FULL guide for creating your own Bots and Macros. I will be teaching you some of the basic fundamentals in programming and also some advanced fundamentals which will include creating GUI's for your Bots and Macros. Advanced fundamentals will be in the 2nd Part of this tutorial.

Contents:
1. What we are using
2. Introduction to the AutoIt language
3. Declarations
4. Functions
5. If, Then, ElseIf and Else
6. Timers
7. Loops
8. Setting hotkeys
9. [Part 2]



1. What we are using

In this tutorial, I will be teaching you how to write code in [Only registered and activated users can see links. Click Here To Register...]

What is AutoIt??
[Only registered and activated users can see links. Click Here To Register...] is a multifunctional script writing tool which enables you to create simple to advanced programs. In part 1 of this tutorial I will be teaching you the very basics of script writing in [Only registered and activated users can see links. Click Here To Register...]. The script writer used for writing AutoIt code is called SciTE. This writer helps you write code more effectively and more efficiently while also giving the script an organised view.


2. Introduction to the AutoIt language

As I have explained above, AutoIt is a multifunctional script writing too which enables you to create simple to advanced programs. This means that script language should be understandable but at the same time, simple and easy to use. If you look at some Visual Basic coding examples, they can be understood but they contain lots of complicated coding in declarations and in the way in which one coding example may identify a process. AutoIt can use language to identify a process simply by using: ProcessExists().

See how AutoIt is much simpler?!

3. Declarations

Declarations an instruction or statement that defines data (fields, variables, arrays, etc.) and resources, but does not create executable code. This means that if I declare “ProcessExists(“[Conquer 2.0]”)” then I would write “$ANYTHINGHERE=ProcessExists(“[Conquer 2.0]”)”.
The use of $ or Dim in AutoIt will define data used in the program. I will explain this concept in more detail when we start writing some code.

4. Functions

Functions can be used to organise data and create different points for the program to read. If you create a Function which stores data about the function of pressing “F1” then you can set “Call” functions in other parts of your script to read and process the above function.

Eg.

Quote:
Originally Posted by Hiyoal
Start() ;Calls the Function named "Start"

Func Start()
$msgbox=Msgbox(4, “Start”, “4+1=6….Press yes if you think this equation is correct. Press no if you think it is incorrect”)

If $msgbox=6 then ;asks the program whether “Yes” was pressed. If it wasn’t then it skips this If statement
Incorrect() ;this calls the Function “Incorrect”
EndIf

If $msgbox=7then ;asks the program whether “No” was pressed
correct() ;this calls the Function “Correct”
EndIf
EndFunc

Func incorrect()
Msgbox(0, “Incorrect”, “You were incorrect”)
Exit
EndFunc

Func correct()
Msgbox(0, “Correct”, “You were correct”)
Exit
EndFunc
5. If, Then, ElseIf and Else

If, Then and Else commands are used in many scripting languages. What they do is ask the program a question. I have written some codes above which demonstrate how the If and Then statement work.

Eg. This Example will demonstrate If, Then and ElseIf and Else.

Quote:
Originally Posted by Hiyoal
If $var >= 0 Then ;asks the program if $var is equal to more than 0, and if it is then it continues through code lines.
MsgBox(4096,"", "Value is positive.") ;displays a messagebox
ElseIf $var <= 0 Then ;if the above
MsgBox(4096,"", "Value is negative.")
Else
If StringIsXDigit ($var) Then
MsgBox(4096,"", "Value might be hexadecimal!")
Else
MsgBox(4096,"", "Value is either a string or is zero.")
EndIf
EndIf
6. Timers and Send

Timers and Send Functions are one of the most important lines of code written for Bots and Macros. What a timer does is tell the program when to “stall” for a period of time. This can be used when using Sit functions in Conquer 2.0 when levelling a stamina skill. You will have to program your AutoIt script to “Sleep” for an amount of time to allow regeneration stamina time.
What the Send Function does is presses a button on your keyboard without you physically pressing it. This

Eg. This Example is a snippet of code from a personal Spiritual Healing Bot I have made.

Quote:
Originally Posted by Hiyoal
Func StartHeal()
$number=IniRead(@systemdir & “\coolies\hello.ini”, “Hi”, “Sup”, “”) ;reads the value from an Ini file.

If $number=1 then
While $number=1
Sleep(12000) ;number is how many milliseconds to sleep for 12seconds
Send(“{F1}”) ;presses the F1 key
Wend
EndIf

If $number=2 then
Exit
EndIf
EndFunc
For this coding to work, you would have to write values to the file hello.ini in @SystemDir\coolies\ for this line of code to work. Otherwise the program could not determine the value of $number and it would receive “”.

7. Loops

Loops are what they are. They cycle through code until the program tells them to stop or else the program quits. They can also cycle forever. This is very helpful when writing codes such as Auto Hunters because you might want the program to read certain user inputted data (SH “F” key. Eg. SH=F3) to cycle through steps until…say…the “Stop” hotkey is pressed.
Loops use the coding:
While
Wend

While tells the program when to start (If While is written using “While 1” then the program will loop forever until the program exits)

Eg. This example will loop through msg boxes until the declared statement $i adds up to 10 or above.

Quote:
Originally Posted by Hiyoal
$i = 0 ; i is declared as equal to 0

While $i <= 10 ;While i’s value is below 10, Loop through below code

MsgBox(0, "Value of $i is:", $i) ;msg boxes the value of i

$i = $i + 1 ;rewrites i again but adds 1 to it so that i is equal to 1 more value to i then the last time.

WEnd
9. Setting Hotkeys

Hotkeys are used in Bots and Macros for the initiation of functions. They are usually used to start, pause, speed up, prompt or stop a program. They are very useful because they are easy to use and they are quick response. They are also easy to code :p .

Eg. This Example shows how to integrate hotkeys into a simple msgbox program.

Quote:
Originally Posted by Hiyoal

While 1
HotKeySet(“{INSERT}”,”Start”) ;Calls the function "Start" when INSERT is pressed
HotKeySet(“{END}”,”Exit”) ;Calls the function "Exit" when END is pressed
Wend

Func Start()
Msgbox(0, “Start”, “You have pressed the key INSERT and it has prompted this message!”)
EndFunc

Func Exit()
Msgbox(0, “Start”, “You have pressed the key END and it has prompted this message and will exit after you press OK”)
Exit
EndFunc
8. Setting Hotkeys

Hotkeys are used in Bots and Macros for the initiation of functions. They are usually used to start, pause, speed up, prompt or stop a program. They are very useful because they are easy to use and they are quick response. They are also easy to code :p .

Eg. This Example shows how to integrate hotkeys into a simple msgbox program.

Quote:
Originally Posted by Hiyoal

While 1
HotKeySet(“{INSERT}”,”Start”) ;Calls the Function "Start"
HotKeySet(“{END}”,”Exit”) ;Calls the Function "Exit"
Wend

Func Start()
Msgbox(0, “Start”, “You have pressed the key INSERT and it has prompted this message!”)
EndFunc

Func Exit()
Msgbox(0, “Start”, “You have pressed the key END and it has prompted this message and will exit after you press OK”)
Exit
EndFunc
9. Part 2

[Only registered and activated users can see links. Click Here To Register...]

I hope that everyone can benefit from this Guide on creating Bots and Macros for themselves and for the community.

Written by Hiyoal
For Elitepvpers

Hiyoal :cool:
12/13/2007 23:56 biertje!#2
Since I am really deep into autohotkey I have a question about autoit

Could autoit manage to send a key i.e. F1 too a inactive co window or id.

:D
12/14/2007 00:02 swords#3
Very good, as an AutoIt coder myself it explains a lot...

But why start off the bat with functions? I made an awesome macro/bot with just mouseclicks...

May try starting them off with mouseclicks to be a bit more simpler?

But still a good guide
12/14/2007 00:36 Hiyoal#4
@biertje!:
Autoit can manage to send keys to inactive Conquer Windows or ids. That is going to be posted in either my second guide or 3rd

@swords:
Im starting Mouse clicks and GUI's in the second guide. I will try to explain everything in detail but i used Functions first because it sets a base for a more organised and better macro, even when using mouse clicks.

Hiyoal :D
12/14/2007 03:05 HackforLive#5
TY! by the way i sended u a PM
12/15/2007 08:43 DaSpy#6
Wow, great guide. I can't wait for the next parts. I decided to start playing around with the program and made this script based on your guide.

------------------------------------------------------------------

Begin() ;calls the 'Begin' Function

$running = 1
$started = 0

;--------Actual instructions--------
While $running = 1

While $started = 1 ;While macro is active, it...
Send("{F2}") ;presses the F2 key
Sleep(11000) ;waits for 11000 ms/11 sec
Send("{F1}") ;presses the F1 key
Wend

Wend

;--------Functions below---------
Func Begin()
$msgbox=Msgbox(0,"How to use","Press HOME to start." & @CRLF & "Press END to stop." & @CRLF & "Press ESC to terminate the program." & @CRLF & "" & @CRLF & "Set the skill on F1, and sit on F2")
HotKeySet("{HOME}", "Start") ;Sets it so that when {HOME} is pressed, function 'Start' is called
HotKeySet("{END}", "Stop") ;Sets it so that when {END} is pressed, function 'Stop is called
HotKeySet("{ESC}", "Terminate") ;Sets it so that when {ESC} is pressed, function 'Terminate' is called
EndFunc

Func Start()
Msgbox(0,"Started","Macro started!")
$started = 1 ;'Started' equals 1, the macro loop will activate
EndFunc

Func Stop()
Msgbox(0,"Stopped","Macro stopped!")
$started = 0 ;'Started' equals 0, the macro loop will deactivate
EndFunc

Func Terminate()
Msgbox(0,"Exited","Macro has been exited!")
Exit ;Exits the program
EndFunc

------------------------------------------------------

Basically, its a Guard/Meditate/SH leveler. It's not hooked to ConquerOnline yet, but I hope that can be explained later on. Whoever wants to use this script can, just don't claim it as your own.

Again, I thank you for this guide and cannot wait for its next parts.
12/16/2007 01:21 Hiyoal#7
Nice. Im glad people understand this guide.

Ty for all your appreciation :)

Hiyoal
12/18/2007 18:23 TekiJinn#8
Wow man I used to be a 100% Auto Hot Key scripter now I have some AutoIt scripting to learn! and its even EASIER then Auto Hot Key, Thanks for the tutorial man +thanks.
12/20/2007 21:09 a1blaster#9
Hey just to let you know I changed the title of this thread to reflect on the title of PART2 that you released. :D
01/17/2008 02:46 aydem22#10
hey man im new at this and wanted to ask some questions:
  • what do you do with the code when it is finished
  • is there like a test or run button for the script?
  • how do people make their bots into downloadable windows?

that is all
plz answer, thanks
01/19/2008 02:11 Scottbee#11
great thnx
01/19/2008 21:48 Hiyoal#12
Sorry for not answering your question earlier aydem22.

1. When the code is finished, you can test run it by staying in the editors window and pressing "F5". This will start your program and you will see an icon in your tasktray which is an autoit icon. This means it is running.
You can also run it by finding your file as if you were going to open it, right mouse click on it, and select "Run Script".

P.S. You will not see an icon if your script contains the code "#notrayincon"

2. People make downloadable EXE files by "Compiling" their script. To do this, you can either:

1. Right mouse click on your file and select "Compile Script"
2. Goto your \Autoit3\aut2exe\ folder (default install location is c:\program files\autoit3\aut2exe). Find "Aut2exe.exe" and run it. You should then be able to figure out the rest.

Hiyoal :D
03/13/2008 18:00 kashman7000#13
u know i took a computer science class this year cause of u..but my stupid teacher is doing visual basic lol
03/13/2008 18:21 plaa#14
Really nice , good for noobs *not anymore those requests ! >:D*
03/13/2008 22:58 AcidTrix#15
Sorry to say this....but...I love you.....

This has been a awesome thread in my eyes. Helped me alot in many ways.

+K for sureeee

Yours truely, ACID