|
You last visited: Today at 00:43
Advertisement
Can someone help me optimize my script
Discussion on Can someone help me optimize my script within the AutoIt forum part of the Coders Den category.
10/29/2017, 15:07
|
#1
|
elite*gold: 0
Join Date: Aug 2012
Posts: 20
Received Thanks: 5
|
Can someone help me optimize my script
Well, this is my first bot made in autoit .. so I'm very nooob I've asked for a lot of help here to make it work hahaha ... and well up to now I've achieved a lot of verdd .. but I see that my bot sometimes gets a little heavy: / or every time he works slower or with problems: / ... when using func pause I have to give him several times to grab him and things like that ... sometimes he starts to make my keyboard deconfigure and write in pure capital letters while they are deactivated ... someone could help me optimize it a bit ... And thank you very much
#include <NomadMemory.au3>
#include <Array.au3>
#RequireAdmin
SetPrivilege("SeDebugPrivilege", 1)
AutoItSetOption ( "SendKeyDownDelay", 100)
Local $MID, $PROCESSNAME, $PID, $Enemy_X, $Enemy_Y, $Player_X, $Player_Y, $MapX, $MapY, $Monster
Global $Name, $HpMax, $StatusADDR, $MapADDR,$baseADDR
; Variables importantes
;
HotKeySet("{F5}", "_exit")
Global $MonsterBase = 0xCC6E7C ; >> Monster 1 o 0 +4 = X +8 = Y
Global $Monsteroffx = dec("a4")
Global $Monsteroffy = dec("8")
Global $PlayerBase = 0xCC7568 ; >> Nombre + F4
Global $Playeroffx = dec("15")
Global $Playeroffy = dec("16")
Global $MapBase = 0x8DB678
Global $MapXOffset[5] = [dec("B6"), dec("4"), dec("31"), dec("7"), dec("AC")]
Global $MapYOffset[5] = [dec("B1"), dec("4"), dec("31"), dec("7"), dec("aC")]
Global $Status = 0x8C6DEC
Global $NameOffset[4] = [dec("10"), dec("12"), dec("1D"), dec("20")]
Global $HpMaxOffset[2] = [dec("1"), dec("45")]
Global $HpOffset[2] = [dec("5a"), dec("3")]
Func _exit()
Exit 0
EndFunc ;==>_exit
Func _Pause()
Global $Paused
$Paused = NOT $Paused
While $Paused
sleep(500)
ToolTip('Bot is "Paused"',0,0)
WEnd
ToolTip("")
_GetCharacter()
if $Name <> "" and $HpMax <> 00000000 Then
_Farm()
Else
_Start()
EndIf
EndFunc
_Start()
Func _init($processname)
$PROCESSNAME = $processname
WinWait($PROCESSNAME)
WinGetProcess($PROCESSNAME)
WinActivate($PROCESSNAME)
SendKeepActive($PROCESSNAME)
$processName2 = "Game.exe"
$PID = ProcessExists($processName2)
$MID = _MEMORYOPEN($PID)
$baseADDR = _MemoryModuleGetBaseAddress($PID,$processName2)
$MapADDR = _MEMORYREAD($baseADDR + $MapBase, $MID)
$StatusADDR = _MEMORYREAD($baseADDR + $Status, $MID)
EndFunc
Func _Start()
_init("Game")
Sleep(500)
ToolTip("Starting Bot",0,0)
Sleep(1000)
ToolTip("",0,0)
While 1
HotKeySet("{F1}")
HotKeySet("{F2}")
ToolTip("BOT LOADED",0,0)
Sleep(2500)
_GetCharacter()
Global $HpMaxOri
$HpMaxOri = _MEMORYREAD( "0x" & Hex (_MEMORYREAD($StatusADDR + $HpMaxOffset[0], $MID) + $HpMaxOffset[1],8), $MID)
While $Name <> "" and $HpMax <> 00000000
HotKeySet("{F1}", "_Farm")
HotKeySet("{F2}", "_Pause")
ToolTip("Pj: " & $Name & " HpMax: " & $HpMax,0,0)
_GetCharacter()
Sleep(500)
WEnd
WEnd
EndFunc
Func _Farm()
ToolTip("",0,0)
While 1
ToolTip("HP: " & $HpMax,0,0)
If $HpMax > $HpMaxOri * 1.7 Then
EndIf
Send("{TAB}")
Sleep(150)
_Address()
While $Monster
If _Transfor() = 1 Then
_Melee()
Sleep(250)
EndIf
If _Distanc() > 8 and _Distanc() < 24 Then
If _Distanc() < 20 Then
Send("{3}")
Sleep(500)
Send("{4}")
Sleep(500)
_Address()
Send("{5}")
Sleep(150)
_Address()
EndIf
If _Distanc() > 20 Then
Send("{4}")
Sleep(500)
Send("{5}")
Sleep(500)
_Address()
EndIf
EndIf
If _Distanc() < 3.55 Then ;4.7 Then ;< 3.55 Then
Send("{1}")
Sleep(1500)
Send("{2}")
Sleep(2000)
_Address()
EndIf
If _Distanc() < 8 or _Distanc() > 24 Then
$Monster = 0
EndIf
WEnd
WEnd
EndFunc
Func _Test()
While 1
_Address()
Sleep(150)
ToolTip("Distancia " & _Distanc(),0,0)
Sleep(500)
WEnd
EndFunc
Func _Address()
$Monster = _MEMORYREAD($MonsterBase, $MID)
if $Monster = 1 Then
_Transfor()
$Enemy_X= _MEMORYREAD($MonsterBase + $Monsteroffx, $MID, "float")
$Enemy_Y= _MEMORYREAD($MonsterBase + $Monsteroffy, $MID, "float")
$Player_X= _MEMORYREAD("0x" & Hex(_MEMORYREAD($PlayerBase + 4, $MID) + $Playeroffx), $MID, "float")
$Player_Y= _MEMORYREAD("0x" & Hex(_MEMORYREAD($PlayerBase + 4, $MID) + $Playeroffy), $MID, "float")
$MapX = "0x" & Hex(_MEMORYREAD(_MEMORYREAD(_MEMORYREAD(_MEMORYREA D($MapADDR + $MapXOffset[0], $MID) + $MapXOffset[1], $MID) + $MapXOffset[2], $MID) + $MapXOffset[3], $MID) + $MapXOffset[4],8)
$MapY = "0x" & Hex(_MEMORYREAD(_MEMORYREAD(_MEMORYREAD(_MEMORYREA D($MapADDR + $MapYOffset[0], $MID) + $MapYOffset[1], $MID) + $MapYOffset[2], $MID) + $MapYOffset[3], $MID) + $MapYOffset[4],8)
EndIf
EndFunc
Func _GetCharacter()
$StatusADDR = _MEMORYREAD($baseADDR + $Status, $MID)
$Name = _MEMORYREAD( "0x" & Hex (_MEMORYREAD(_MEMORYREAD(_MEMORYREAD($StatusADDR + $NameOffset[0], $MID) + $NameOffset[1], $MID) + $NameOffset[2], $MID) + $NameOffset[3],8), $MID, "Char[16]")
$HpMax = _MEMORYREAD( "0x" & Hex (_MEMORYREAD($StatusADDR + $HpMaxOffset[0], $MID) + $HpMaxOffset[1],8), $MID)
EndFunc
Func _Transfor()
Local $IsTransfor
$HpMax = _MEMORYREAD( "0x" & Hex (_MEMORYREAD($StatusADDR + $HpMaxOffset[0], $MID) + $HpMaxOffset[1],8), $MID)
If $HpMax > $HpMaxOri * 1.7 Then
$IsTransfor = 1
Else
$IsTransfor = 0
EndIf
Return $IsTransfor
EndFunc
Func _Melee()
While _Transfor() = 1
Send("{TAB}")
Sleep(150)
_Address()
If _Distanc() < 3.55 Then ;4.7 Then ;< 3.55 Then
Send("{1}")
Sleep(1500)
Send("{2}")
Sleep(2000)
_Address()
EndIf
If _Distanc() < 8 or _Distanc() > 24 Then
$Monster = 0
EndIf
WEnd
_Farm()
EndFunc
Func _Distanc()
$dy = $Enemy_Y - $Player_Y
$dx = $Enemy_X - $Player_X
return sqrt($dx*$dx + $dy*$dy)
EndFunc
pliss and ty again to all !!
|
|
|
10/29/2017, 21:14
|
#2
|
elite*gold: 0
Join Date: Apr 2011
Posts: 363
Received Thanks: 167
|
I won't give u all the code because u won't learn anything, but i will give u some tips to start.
Vars u use in all your code should be global, those variables can be accessed and changed in any function, local ones will only be accesible inside a function
Code:
;Example
Global $x = 10
function changeX()
local $x = 5
endFunc
function realChangeX()
$x = 15 ;No declaration, global variable change
endFunc
;Global x
msgbox(0,"x value",$x);print 10
changeX()
msgbox(0,"x value",$x);print 10 because changed x is local to that function
realChangeX()
msgbox(0,"x value",$x);print 15
So correct way will be:
global $MID, $PROCESSNAME, $PID, $Enemy_X, $Enemy_Y, $Player_X, $Player_Y, $MapX, $MapY, $Monster
Caution with those while loops, you are overusing them, and you can't pause the bot anymore.
Code:
Func _Start()
...
While 1 ; Loop #1
;HotKeySet("{F1}") wrong sintax and should't be in here should be at top of script
;HotKeySet("{F2}")
...
While $Name <> "" and $HpMax <> 00000000 ;Loop #2
;HotKeySet("{F1}", "_Farm")
;HotKeySet("{F2}", "_Pause") TOP TOP NO INSIDE LOOP
...
WEnd
WEnd
EndFunc
;Then you decide to press farm button
;We go inside _farm function
Func _Farm()
...
While 1 ;Loop #3
...
While $Monster ;Loop #4 we find a monster
_Melee() ; ->Another loop in here Loop #5
_Address() ;Check if not a monster anymore
...
WEnd
WEnd
EndFunc
Func _Melee()
While _Transfor() = 1 ;Loop #5
...
If _Distanc() < 8 or _Distanc() > 24 Then
$Monster = 0 ;Ok monster is 0 we should end Loop #4 but we are stuck in here until Loop #5 is false
EndIf
WEnd
;Ok loop 4 is false but why do we call again _Farm(), now we should be stuck in loop #3 or loop #4
;_Farm() Wrong will cause recursive overflow
EndFunc
;So what we got here is we go inside loop #1 Until we find our character
;Once found we Go loop #2 and we wait until _farm is pressed or _pause
;Inside _farm we go inside a never ending loop #3
;We search for a monster and if found go loop #4
;Then if the condition is reached we go inside loop #5 and are stuck there until condition is false
;Finally u can call pause but you still stuck in some of those loops remember?
Here is what should do, instead of 10 loops use flags, u can also make code pretier with some extra functions
Code:
HotKeySet("{F1}", "_start")
HotKeySet("{F2}", "_exit")
global $paused = true
global $running = true
func _start()
$paused= not $paused ; Toggle paused state if true then its false and so on..
endfunc
func _exit()
$running = false;
endfunc
mainLoop()
function mainLoop()
while $running
if not $paused then
//all your logic goes here
//Ex:
//Update monsters data
//Update distance to moob, etc
else
tooltip("Script is paused",0,0)
sleep(20)
endif
wend
endfunc
Example of simple bot script with image search
Code:
Global $paused = True
Global $running = true
HotKeySet("{F1}", "_exit")
HotKeySet("{F2}", "_toggleBot")
Func _toggleBot()
$paused = Not $paused
EndFunc
Func _exit()
$running = False
EndFunc
Func getState() ;In each state u should do what u need inside a function or sth
if _SearchArea("mainWindow.png",1068,606,20,20) Then Return 1
if _SearchArea("exploreWindow.png",496,60,20,20) Then Return 2
if _SearchArea("selectQuest.png",518,60,30,30) Then Return 3
if _SearchArea("coopButton.png",874,603,30,30) Then Return 4
if _SearchArea("joinCoop.png",431,300,30,30) Then Return 5
if _SearchArea("inFight.png",43,173,30,30) Then Return 9
if _SearchArea("coopWindow.png",1063,497,30,30) Then Return 6
if _SearchArea("roomFull.png",558,459,30,30) Then Return 7
if _SearchArea("inRoom.png",1063,69,30,30) Then Return 8
if _SearchArea("repeatWindow.png",792,497,30,30) Then Return 10
if _SearchArea("close.png",564,416,32,32) Then Return 11
Return 0
EndFunc
While $running ;One loop
if Not $paused Then
handleState() ;Multiple states
Else
ToolTip("Paused",0,0)
Sleep(200)
EndIf
WEnd
Func handleState()
$state = getState()
ToolTip($state,100,100)
Switch $state ;this is messy but u can make it look prettier if u want
Case 0
ControlClick($hwnd,"","","left",1,597, 609)
Case 1
ControlClick($hwnd,"","","left",1,1095, 618)
Case 2
ControlClick($hwnd,"","","left",1,1118, 645)
ControlClick($hwnd,"","","left",1,840, 608)
Case 3
ControlClick($hwnd,"","","left",1,821, 277)
Case 4
ControlClick($hwnd,"","","left",1,914, 613)
Case 5
ControlClick($hwnd,"","","left",1,469, 316)
Case 6
ControlClick($hwnd,"","","left",1,501, 205)
Case 7
ControlClick($hwnd,"","","left",1,596, 472)
Case 8
ControlClick($hwnd,"","","left",1,1097, 562)
Case 9
controlClick($hwnd,"","","left",2,909, 612)
Case 10
controlClick($hwnd,"","","left",1,599, 457)
Case 11
controlClick($hwnd,"","","left",1,599, 431)
EndSwitch
EndFunc
|
|
|
10/30/2017, 11:49
|
#3
|
elite*gold: 0
Join Date: Aug 2012
Posts: 20
Received Thanks: 5
|
Thank you brother ... thank you very much for your answer, as I said I am very new making bots and more using autoit ... I understand a little what you tell me but I do not fully understand it if you could leave me a little more explanation you could help even more ... please and I thank you ... and if I also appreciate that you do it in a way that I can learn but I do not understand much of the final how to solve everything hahaha !! Sorry ... and again thanks to everyone who wants to help.
|
|
|
 |
Similar Threads
|
Anyone can optimize this code ?
11/30/2013 - CO2 Private Server - 17 Replies
Kindly make this code better guys. I want a port refresher that uses less Cpu usage.
static void Port_Refresher()
{
while (true)
{
{
AuthServer.Disable();
AuthServer = null;
|
[Release]Optimize Your GrandChase
01/20/2011 - Grand Chase Hacks, Bots, Cheats & Exploits - 17 Replies
This Program is originally from game booster.
But this is Lite version made by me.
This will make you to run Grand Chase and other programs faster.
Instructions:
1. Download the ff file.
2. Extract using winrar.
|
PLEASE......CAN SOMEONE CAN GIVE ME AN ENGINE THAT CAN'T BE DETECTED...
12/30/2009 - Grand Chase Hacks, Bots, Cheats & Exploits - 3 Replies
...GIVE ME AN ENGINE THAT IS N0T DETECTED..... KAHIT NA PANG 5 DAYS LANG !^^...IF YOU ARE FINISH TO READ YOU CAN CLOSED THIS THREAD....>.<:):):):):)
|
corn to optimize and repair
11/10/2008 - CO2 Private Server - 1 Replies
hello
how make corn to corn to optimize and repair tables every day for more good server without sql problems
???
|
All times are GMT +1. The time now is 00:43.
|
|