[HELP] AutoIT BOT need assistance

03/24/2012 11:42 yttuncel#1
Hello everybody,

First of all I need to say I am new to AutoIT language. I know Java and C++, but read all over the net that these are not ideal for mmorpg botting, and to top it all, also read that AutoIT has some cool features which makes life easier.

So long story short, I need your assistance for this very basic bot program, which just stands still, selects mobs, attack and then check Hp/Mp then loot and so on. The game is Rode Online btw, I'll post the screenshots for the pixels to make myself clear.

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

These are my Functions, all in one class.

Quote:
Func checkHpMp();1
If isHpLow() Then
useSkill( 1) ;use hp potion
EndIf

If isMpLow() Then
useSkill( 2) ;use mana potion
EndIf
EndFunc

Func isMobDead();2
If Hex(PixelGetColor( 898, 74), 6) == "3B815A" Then
Return False
Else
Return True
EndIf
EndFunc

Func isMobSelected();3
If Hex(PixelGetColor( 898, 74), 6) == "3B815A" Then
Return True
Else
Return False
EndIf
EndFunc

Func isHpLow();4
If Hex(PixelGetColor( 863, 1011), 6) <> "151E34" Then
Return True
Else
Return False
EndIf
EndFunc

Func isMpLow();5
If Hex(PixelGetColor( 1053, 1011), 6) <> "125386" Then
Return True
Else
Return False
EndIf
EndFunc

Func isHpMid();6
If Hex(PixelGetColor( 869, 982), 6) <> "BD526C" Then
Return True
Else
Return False
EndIf
EndFunc

Func targetMob();7
Send("{TAB}")
Sleep(200)
EndFunc

Func useSkill( $skillNo);8
Send($skillNo)
Sleep(200)
EndFunc
1. For the checkHpMp function, can I use other functions that are declared by me in a function declared by me? checkHpMp includes isHpLow and isMpLow, thats why Im asking.

2 & 3. Well isMobDead and isMobSelected are in fact the same functions. I check the same pixel to decide true or false. And since I call isMobSelected earlier than the other one, I think it will work.

This is the location I look at:
[Only registered and activated users can see links. Click Here To Register...]

4, 5 & 6. isHpLow, isHpMid and isMpLow looks at the Hp and Mana bars ofc :D I selected the pixels to correspond to portions of Hp and Mp according to my resolution

7. targetMob uses the TAB button on the keyboard to select the nearest mob.

8. useSkill takes in some parameter and then sends the game that button.

This is the Main class I wrote. exit and pause options are not yet implemented I know, this is kinda an outline. But it doesnt work for some reason :/

Quote:
#include <Color.au3>
#include "myFunctions.au3"

$exit = False
$paused = False
;Global $resting = false
$skillNumber = 3 ; Since hp and mp potions are 1 & 2

Sleep(4000)

While NOT $exit
If Not $paused Then
Sleep (100)
If isHpMid() Then
Send("{Z}") ; This is the rest button in the game
Sleep(20000)
EndIf

targetMob()

While isMobSelected()
checkHpMp() ; checks hp/mp before combat and uses pots if needed
useSkill( $skillNumber) ; spams 3-4-5-6-7, the mob would be dead by then
Sleep(500)

$skillNumber = $skillNumber + 1

If isMobDead() Then ; checks if the mob is dead
checkHpMp() ; looks again for hp and mp
Sleep(4000)
$skillNumber = 3 ; resets the skillnumber so that it will start from 3 again
Send("{V}"); for looting
EndIf
WEnd
EndIf
WEnd
Well, my indentation is spoiled by e-pvp, I am sorry for that, please try to follow :(

Now the real question:

Bot selects mobs but does not attack them. Is there something wrong with the skill usage ? And any other suggestions critics are appreciated. I know the code is really noobish and sucks but this was my second attempt in AutoIT.

Thank you! :rolleyes:

Update: I edited the bot, and now it seems the checkHpMp thing does not work. When I comment the lines involve it the bot works fine. But I need to check my Hp ofc. Please Help!
03/27/2012 16:55 BotofWar#2
Maybe the follwoing Fragments will help you with your project.
You only have to customize it detailed.

Code:
HotKeySet("^q", "leave")
HotKeySet("{PAUSE}", "Pause") ;HotKeySet Programm Pause

$size = WinGetPos("Game")
$HP=0
$MP=0
While 1
	
	Mobcheck()
	HPMPCheck()
	Attack()
	
WEnd

Func HPMPCheck() ;checking both
	
	$XOffset=789
	
	for $z = 1 to 2
		
		switch $z
		case 1 
			$Pixelcolor = HPColor
			$YOffset = 123
		case 2
			$Pixelcolor = MPColor
			$YOffset = 456
		EndSwitch
	
		for $i = 0 to 100 Step 10 ;replace 100 with length of HP Bar and Step 10 with desired detailment
			$color = pixelgetcolor($size[0]$XOffset+$i,$size[1]+$YOffset)
			if $color <> $Pixelcolor then
				switch $z
				case 1 
					$HP= $i
				case 2
					$MP= $i
				EndSwitch
                                $i = 10000
			EndIf
		Next
	Next
	
	
EndFunc


Func leave() 
	
exit

EndFunc

Func Pause()

ToolTip("Pause- continue with END-Bar",1,10)
While 1
    Sleep ( 300 )
    If _IsPressed("23", $dll) Then; End Taste
	WinActivate("Game")
	WinWaitActive ("Game")
	ExitLoop
	EndIf
WEnd
	
EndFunc

Probably next time you dont want to use Pixelsearch, so you will use Memory.
Here is a (untranslated) Fragment from my own Bot (other RPG) you can use after you've concerned with Memoryread yourself:

Code:
Func HPMPKontrolle()
	

$read1 = _MemoryRead($RAMAktHP, $info);aktuelle HP
$read2 = _MemoryRead($RAMGesHP, $info);gesamt HP

$read3 = _MemoryRead($RAMAktMP, $info);aktuelle MP
$read4 = _MemoryRead($RAMGesMP, $info);gesamt MP

if $read1<($read2*($HP1pottenbeiProzent/100)) Then
	if BereitHP1() = true then
		$SollLeiste=$LeisteHP1
		Leisteaussuchen()
		Send("{" & $TasteHP1 & " DOWN}" )
		sleep(80)
		Send("{" & $TasteHP1 & " UP}" )
		$HP1Timer = $Timer ; Sehr wichtig!
		$hp1gepottet=$hp1gepottet+1
	EndIf
EndIf

if $read1<($read2*($HP2pottenbeiProzent/100)) Then
	if BereitHP2() = true then
		$SollLeiste=$LeisteHP2
		Leisteaussuchen()
		Send("{" & $TasteHP2 & " DOWN}" )
		sleep(80)
		Send("{" & $TasteHP2 & " UP}" )
		$HP2Timer = $Timer ; Sehr wichtig!
		$hp2gepottet=$hp2gepottet+1
	EndIf
EndIf
		
if $read3<($read4*($MPpottenbeiProzent/100)) Then
	if BereitMP() = true then
		$SollLeiste=$LeisteMP
		Leisteaussuchen()
		Send("{" & $TasteMP & " DOWN}" )
		sleep(80)
		Send("{" & $TasteMP & " UP}" )
		$MPTimer = $Timer ; Sehr wichtig!
		$mpgepottet=$mpgepottet+1
	EndIf
EndIf

EndFunc
03/27/2012 17:50 jacky919#3
Quote:
Originally Posted by yttuncel View Post
These are my Functions, all in one class.
Where is the class?
03/28/2012 05:54 yttuncel#4
Quote:
Originally Posted by jacky919 View Post
Where is the class?
What do you mean ?

@BotOfWar

Thanks man I'll definitely be checking your algorithm after I'm done with this thing.

I've updated the bot and now it is useable, and avoids death to some extent.

How can I prevent moving though? Sometimes when the nearby mobs are done, it targets a far mob and automoves when skill is pressed. I checked auto move to target in options menu of the game, but no results. Thanks!
03/28/2012 11:05 BotofWar#5
At the game I was playing the following thing deactivated Skills:

Code:
Func Mobcheck()
	
..............

if $mob = 0 Then
	mouseclick("left",yourselfX,youselfY,5)
EndIf

...........


EndFunc
03/28/2012 15:29 lolkop#6
why don't you work with the memory of that game?
03/28/2012 20:10 yttuncel#7
@lolkop, because I'm brand new at bot coding and dll and memory stuff.
Can you guys give me some tutorial links that are reliable and effective ?

@Botofwar, but in my case it targets the mob, but mob is far away so that it moves towards the mob to get in range(I am a ranger class btw). So I have to at least turn to initial position back after killing that mob, or just cancel if it is out of range. I think I found a solution via pixel search, but I will be concerning with memory stuff as soon as possible
03/28/2012 20:17 jacky919#8
Quote:
Originally Posted by yttuncel View Post
What do you mean ?
>>
Quote:
Originally Posted by yttuncel
These are my Functions, all in one class.
03/28/2012 20:38 lolkop#9
Quote:
Originally Posted by yttuncel View Post
@lolkop, because I'm brand new at bot coding and dll and memory stuff.
Can you guys give me some tutorial links that are reliable and effective ?
well, reversing is kinda complex for beginners. i've just downloaded the game and checked it out, to be able to help you a little.

to start with memory stuff, you can use the winapis. here are some small codeexamples for usefull functions:
Code:
Func OpenProcess($pid)
	Local $mid = DllCall('kernel32.dll', 'int', 'OpenProcess', 'int', 0x1F0FFF, 'int', 1, 'int', $pid)
	Return $mid[0]
EndFunc

Func ReadProcessMemory($process_hwnd, $adress, $type = 'dword')
	Local $struct = DllStructCreate($type)
	DllCall('kernel32.dll', 'int', 'ReadProcessMemory', 'int', $process_hwnd, 'int', $adress, 'ptr', DllStructGetPtr($struct), 'int', DllStructGetSize($struct), 'int', '')
	Return DllStructGetData($struct, 1)
EndFunc

Func CloseHandle($hwnd)
	DllCall('kernel32.dll', 'int', 'CloseHandle', 'int', $hwnd)
EndFunc
a basic example for the current game-version:
Code:
$mid = OpenProcess(ProcessExists('rode.exe'))
While Sleep(100)
	$base = ReadProcessMemory($mid, 0x13D9D8C)
	$currentHp = ReadProcessMemory($mid, $base + 0xC34)
	ToolTip($currentHp)
WEnd
CloseHandle($mid)
the pointer of the character-struct for the current client is located at 0x13D9D8C.

exploring the struct will show you the most important values for the beginning. as you can see, i've added the currentHp offset to the example too.
03/28/2012 23:19 yttuncel#10
@lolkop, thank you very much, I'll be revising these as soon as I find some free time!
I'll be posting my further questions here
04/05/2012 20:30 babooy#11
were you able to get the bot functional?
05/08/2012 19:53 haxereth#12
Quote:
Originally Posted by babooy View Post
were you able to get the bot functional?
Yeah, I am wondering this as well.