Sign in to follow this  
Followers 0
Metarf

Little help for my stupi bot

2 posts in this topic

how work my stupid bot (wow 2.4) :

- read position and rotation from memory

- generate random number for destination coord. x, y , z

- calculate new rotation and distance (polar system) from coord. destination

- move to new point checking distance (until distance < 2.0)

- restart....

#include <NomadMemory.au3>
#include <GUIConstants.au3>
#include <String.au3>
#include <Date.au3>
#include <array.au3>
#Include <Misc.au3>
#include <MemoryConstants.au3>

;~ X = 0x00E18DF4 (FLOAT)
;~ Y = 0x00E18DF8 (FLOAT)
;~ Z = 0x00E18DFC (FLOAT)
;~ Rotation = 0x00E18E24 (FLOAT)
;~ MapID = 0x00E18DB4 (SHORT)
;~ Cursor = 0x00CF5750 (SHORT)
;~ Charname = 0x00D43348 (CHAR)
SetPrivilege("SeDebugPrivilege", 1)
$win_title = "World of Warcraft" 
WinActivate($win_title, "")
WinSetOnTop($win_title, "", 0)
Sleep(1000) 
HotKeySet("{ESC}", "Terminate")

#Region Variabili
dim $appname
dim $X = 0x00E18DF4
dim $Y = 0x00E18DF8
dim $Z = 0x00E18DFC
dim $rot = 0x00E18E24
dim $processfound = 0
dim $GotoX
dim $GotoY
dim $GoToRot ;direzione destinazione
dim $NewRot ;direz da prendere per muoversi
dim $FileScr
dim $relX
dim $relY
dim $Ang
dim $Dist
dim $tmpX
dim $tmpY
dim $olddist
dim $a 
dim $TmpValCoo = Random()
dim $CX
dim $CY
dim $CZ

#EndRegion
;
#Region ApriMememoria
Global $ProcessID = WinGetProcess("World of Warcraft","")
Local $DllInformation = _MemoryOpen($ProcessID)
If @Error Then
    MsgBox(4096, "ERROR", "Failed to open memory for process;" & $ProcessID)
    Exit
EndIf
#EndRegion
;
dim $filelog = ("C:\Users\Giacomo\Desktop\bot" & "\log.txt")
dim $fileDB = ("C:\Users\Giacomo\Desktop\bot" & "\DB.txt")
FileOpen ($filelog , 2)
FileOpen ($fileDB , 1)

while 1
    $CurrentLocX = Round(_MemoryRead($X, $DllInformation,'float'),1)
    $CurrentLocZ = Round(_MemoryRead($Z, $DllInformation,'float'),1)
    $CurrentLocY = Round(_MemoryRead($Y, $DllInformation,'float'),1)
    $CurrentRot = _MemoryRead($rot, $DllInformation,'float')
    $a = 0
    ;--Qui cerca l'orientamento......
    ;Leggi()
    
    CooRandom()
    
    ;msgbox(1,"",$TmpValCoo)
    ;msgbox(1,"",$CurrentRot)
    do
        CalcRot()
    until $CurrentRot = $Ang
    ;FileWriteLine($filelog, @HOUR & ":" & @MIN & ":" & @SEC & " -->" & " Ang: " & $Ang & "---" & $CurrentRot)
    Do
        Cammina()
            if $Dist > $olddist Then
                do
                    CalcRot()
                until $CurrentRot = $Ang
            EndIf
    FileWriteLine($filelog, @HOUR & ":" & @MIN & ":" & @SEC & " -->" & " Dist: " & $Dist & " - Ang: " & $Ang & @CRLF & "X: " & $CX & " - Y: " & $CY & " - Z: " & $CZ & @CRLF & "---------------------")
    until $Dist < 2.0      ;---E' arrivato nel raggio di 2.0 unità dalle coordinate di arrivo......:)
    
    FileWriteLine($filelog, @HOUR & ":" & @MIN & ":" & @SEC & " -->" & " Coo: " & $GotoX & "/" & $CurrentLocX & " --- " & $GoToY & "/" & $CurrentLocY & @CRLF & "--------------------------")
    ;exit 0
    sleep(150)
    
wend

Func Scrivi()
    dim $FileScr ="C:\Users\Giacomo\Desktop\bot\path.txt"
    FileOpen ($FileScr,2)
    FileWriteLine($FileScr, $CurrentLocX)
    FileWriteLine($FileScr, $CurrentLocY)
    FileWriteLine($FileScr, $CurrentRot)
    ;Beep()
    sleep (1500)
endfunc

Func CooRandom()
;   Calcolo un valore random da aggiungere alle coord. di destinazione ed in base al risultato aggiungo o detraggo 
;   alla nuova destinaz....
     
    if $TmpValCoo < 0.25 then
        $GotoX = Round($CurrentLocX + Random(15,35),1) 
        $GotoY = Round($CurrentLocY + Random(15,35),1)
    ElseIf $TmpValCoo >= 0.75 then
        $GotoX = Round($CurrentLocX - Random(15,35),1) 
        $GotoY = Round($CurrentLocY - Random(15,35),1)
    Elseif $TmpValCoo >= 0.25 And $TmpValCoo < 0.50 Then
        $GotoX = Round($CurrentLocX - Random(15,35),1) 
        $GotoY = Round($CurrentLocY + Random(15,35),1)
    Elseif $TmpValCoo >= 0.50 And $TmpValCoo < 0.75 Then
        $GotoX = Round($CurrentLocX + Random(15,35),1) 
        $GotoY = Round($CurrentLocY - Random(15,35),1)  
    EndIf
    FileWriteLine($filelog, @HOUR & ":" & @MIN & ":" & @SEC & " -->" & " X: " & $GotoX & " - Y: " & $GoToY & " -rnd: " & $TmpValCoo)
EndFunc

Func Leggi()
    dim $FileLett ="C:\Users\Giacomo\Desktop\bot\path.txt"
    FileOpen ($FileLett,0)
    $a = $a + 1
        $GotoX = Round(FileReadLine($FileLett,$a),1)
    $a = $a + 1
        $GotoY = Round(FileReadLine($FileLett,$a),1)
    $a = $a + 1
        $GotoRot = Round(FileReadLine($FileLett,$a),1)
    ;FileClose($FileLett)
endfunc

Func CalcRot()
;   Legge in memoria la rotazione
        $CurrentRot = Round(_MemoryRead($rot, $DllInformation,'float'),1)
            Send("{a down}")
            sleep (10)
            Send("{a up}")
            Angolo()
;   ---Solo per i log--------------

    $CX = Round(_MemoryRead($X, $DllInformation,'float'),1)
    $CY = Round(_MemoryRead($Y, $DllInformation,'float'),1)
    $CZ = Round(_MemoryRead($Z, $DllInformation,'float'),1)
;-----------------------------------
        ;msgbox(1,"", $Ang & " --- " & $CurrentRot)
endfunc

Func Angolo()
    $CurrentLocX = $GotoX - $CurrentLocX
    $CurrentLocY = $GotoY - $CurrentLocY
;   Calcola l'angolo in funzione della posizione nei quattro quadranti della x e della y locali, l'origine è la posiz attuale
;   (X di arrivo - X di partenza). Vedi Coordinate polari.

    if $CurrentLocX > 0 And $CurrentLocY > 0 Then
            $Ang = Round(ATan($CurrentLocY / $CurrentLocX),1)
    ElseIf $CurrentLocX > 0 And $CurrentLocY < 0 Then
            $Ang = Round((ATan($CurrentLocY / $CurrentLocX) + (2 * 3.14)),1)
    ElseIf $CurrentLocX < 0 Then
            $Ang = Round((ATan($CurrentLocY / $CurrentLocX) + (1 * 3.14)),1)
    ElseIf $CurrentLocX = 0 And $CurrentLocY > 0 Then
            $Ang = Round((3.14 / 2 + (1 * 3.14)),1)
    ElseIf $CurrentLocX = 0 And $CurrentLocY < 0 Then
            $Ang = Round((- 3.14 / 2 + (1 * 3.14)),1)
    EndIf
EndFunc

Func Cammina()
;   Calcola la distanza che lo separa dal punto di arrivo con un semplice teorema di pitagora in cui i cateti sono
;   gli assi x ed y con origine nella posizione attuale.
    $olddist = $Dist
    $CurrentLocX = Round(_MemoryRead($X, $DllInformation,'float'),1)
    $CurrentLocY = Round(_MemoryRead($Y, $DllInformation,'float'),1)
    $CurrentLocZ = Round(_MemoryRead($Z, $DllInformation,'float'),1)
    $tmpX = abs($GotoX) - abs($CurrentLocX)
    $tmpY = abs($GotoY) - abs($CurrentLocY)
    $Dist = round(sqrt( $tmpX ^ 2 + $tmpY ^ 2 ),1)
        Send("{w down}")
        sleep (300) ; valori alti riducono la precisione
        Send("{w up}")
    
        FileWriteLine($fileDB, $CurrentLocX)
        FileWriteLine($fileDB, $CurrentLocY)
        FileWriteLine($fileDB, $CurrentLocZ)
endfunc

Func Terminate()
    FileClose($FileDB)
    FileClose($Filelog)
    _Memoryclose($DllInformation)
    Exit 0
EndFunc

I would want to know like understanding when the robot is stopped on d an obstacle.

Ty

Share this post


Link to post
Share on other sites



Logically thinking the code to detect that would go somewhere around here:

Cammina()

if $Dist > $olddist Then

Cammina() provides movement.

There are 3 possible outcomes after attempting movement:

1. $Dist > $olddist : The new distance to the taget position is now greater, so you recalculate the angle and try again.

2. $Dist < $olddist : The new distance to the taget position is now less, so the movement was successful.

3. $Dist = $olddist : The new distance to the taget position has not changed, so the movement was unsuccessful.

In your code you have only provided an answer to one of the outcomes (#1).

An answer to #2 isn't required. Success is a good thing.

On the surface it appears you need to take #3 (no movement at all) into account.

Although it may be that you will still move but only a fraction of the "normal movement amount" (whatever that may be).

Or possibly keeping track of the success rate (i.e. if you move more than X [a number yet to be determined] times and are still no closer to the target) is the key.

Maybe this will give you a new direction of thought.

I don't think anyone can provide specific coding examples.

I think the key lies in you examining the log file and analyzing what happens when an obstacle is encountered.

Share this post


Link to post
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
Sign in to follow this  
Followers 0