Help with a MoveFunc for VQBot

05/17/2024 19:11 TheKuM1Ko#1
We are working on the VQ Bot but we are encountering some problem to make an appropriate func when the bot die and has to move again.

We created this func but atm the bot instead of going to the nearest array he try to go back to the array where he died.

Code:
Func MoveandAggroVQ($aWaypoints)
	$DeadOnTheRun = 0
	
    If $DeadOnTheRun = 1 Then
        
		Sleep (16000)
        Local $currentX = GetCurrentX()
        Local $currentY = GetCurrentY()
        Local $closestIndex = -1
        Local inDistance = 1e10 

        For $i = 0 To UBound($aWaypoints) - 1
            Local $waypointX = $aWaypoints[$i][0]
            Local $waypointY = $aWaypoints[$i][1]
            Local $distance = Sqrt(($waypointX - $currentX)^2 + ($waypointY - $currentY)^2)

            If $distance < $minDistance Then
                $minDistance = $distance
                $closestIndex = $i
            EndIf
        Next

        
        For $Index = $closestIndex To UBound($aWaypoints) - 1
            AggroMoveTo($aWaypoints[$Index][0], $aWaypoints[$Index][1], $aWaypoints[$Index][2] & $ActionCounter, $aWaypoints[$Index][3])
            $ActionCounter += 1

           
            If $aWaypoints[$Index][0] = $waypointX And $aWaypoints[$Index][1] = $waypointY Then
                $DeadOnTheRun = 0 ; Imposta il personaggio come vivo
                ExitLoop
            EndIf
        Next
    ElseIf $DeadOnTheRun = 0 Then
        
        For $Index = 0 To UBound($aWaypoints) - 1
            AggroMoveTo($aWaypoints[$Index][0], $aWaypoints[$Index][1], $aWaypoints[$Index][2] & $ActionCounter, $aWaypoints[$Index][3])
            $ActionCounter += 1
        Next
    EndIf
EndFunc$m
Anyone has a solution or can find where we are at fault there?
Thank you for the help
05/17/2024 22:39 Underavelvetmoon#2
Quote:
Originally Posted by TheKuM1Ko View Post
We are working on the VQ Bot but we are encountering some problem to make an appropriate func when the bot die and has to move again.

We created this func but atm the bot instead of going to the nearest array he try to go back to the array where he died.

Code:
Func MoveandAggroVQ($aWaypoints)
	$DeadOnTheRun = 0
	
    If $DeadOnTheRun = 1 Then
        
		Sleep (16000)
        Local $currentX = GetCurrentX()
        Local $currentY = GetCurrentY()
        Local $closestIndex = -1
        Local inDistance = 1e10 

        For $i = 0 To UBound($aWaypoints) - 1
            Local $waypointX = $aWaypoints[$i][0]
            Local $waypointY = $aWaypoints[$i][1]
            Local $distance = Sqrt(($waypointX - $currentX)^2 + ($waypointY - $currentY)^2)

            If $distance < $minDistance Then
                $minDistance = $distance
                $closestIndex = $i
            EndIf
        Next

        
        For $Index = $closestIndex To UBound($aWaypoints) - 1
            AggroMoveTo($aWaypoints[$Index][0], $aWaypoints[$Index][1], $aWaypoints[$Index][2] & $ActionCounter, $aWaypoints[$Index][3])
            $ActionCounter += 1

           
            If $aWaypoints[$Index][0] = $waypointX And $aWaypoints[$Index][1] = $waypointY Then
                $DeadOnTheRun = 0 ; Imposta il personaggio come vivo
                ExitLoop
            EndIf
        Next
    ElseIf $DeadOnTheRun = 0 Then
        
        For $Index = 0 To UBound($aWaypoints) - 1
            AggroMoveTo($aWaypoints[$Index][0], $aWaypoints[$Index][1], $aWaypoints[$Index][2] & $ActionCounter, $aWaypoints[$Index][3])
            $ActionCounter += 1
        Next
    EndIf
EndFunc$m
Anyone has a solution or can find where we are at fault there?
Thank you for the help
I think its because no matter what within the function you have to loop through and execute the whole array, so it will always return to the last element within an array.

I am not sure if this will work because I just Googled it, but you could add a function within the array to check whether the next co-ords are within X amount of distance from the current co-ords, as long as the majority of your co-ords are within a certain distance it shouldnt impact the running of the bot, but you may have to edit some co-ords.

I imagine it would look something like this:

Code:
Global $WayPoints = [["0000, 0000", WayPoint 1, IsNearestCoord()]]

Func IsNearestCoord()
Local $lDistance = 500 ;Coords need to be within this distance to continue to the next one
Code to return true or false
EndFunc

;Check for this to be true or false during the UBound portion of code
For reference, this is the example I found, so even if the above doesnt work I imagine adding something similar to the array is the way forward, rather than trying to edit the Move function.

Code:
#include <MsgBoxConstants.au3>
#include <Array.au3>

HotKeySet("{ESC}", "_Exit")

Global $Array[5] = ["5", "4", _Function2, "2", "1"]

While 1
    _Function1()
WEnd

Func _Function1 ()
   For $i=1 to 5
      $element = IsFunc($Array[$i])
      If $element = 0 Then
         MsgBox ($MB_OK, "", $Array[$i])
      Else
         Call($Array[$i])
      EndIf
   Next
EndFunc   ;==>_Function1

Func _Function2()
    MsgBox ($MB_OK, "", "Function was executed")
EndFunc

Func _Exit()
    Exit
EndFunc
Hope it helps!
05/18/2024 00:20 TheKuM1Ko#3
Quote:
Originally Posted by Underavelvetmoon View Post
I think its because no matter what within the function you have to loop through and execute the whole array, so it will always return to the last element within an array.

I am not sure if this will work because I just Googled it, but you could add a function within the array to check whether the next co-ords are within X amount of distance from the current co-ords, as long as the majority of your co-ords are within a certain distance it shouldnt impact the running of the bot, but you may have to edit some co-ords.

I imagine it would look something like this:

Code:
Global $WayPoints = [["0000, 0000", WayPoint 1, IsNearestCoord()]]

Func IsNearestCoord()
Local $lDistance = 500 ;Coords need to be within this distance to continue to the next one
Code to return true or false
EndFunc

;Check for this to be true or false during the UBound portion of code
For reference, this is the example I found, so even if the above doesnt work I imagine adding something similar to the array is the way forward, rather than trying to edit the Move function.

Code:
#include <MsgBoxConstants.au3>
#include <Array.au3>

HotKeySet("{ESC}", "_Exit")

Global $Array[5] = ["5", "4", _Function2, "2", "1"]

While 1
    _Function1()
WEnd

Func _Function1 ()
   For $i=1 to 5
      $element = IsFunc($Array[$i])
      If $element = 0 Then
         MsgBox ($MB_OK, "", $Array[$i])
      Else
         Call($Array[$i])
      EndIf
   Next
EndFunc   ;==>_Function1

Func _Function2()
    MsgBox ($MB_OK, "", "Function was executed")
EndFunc

Func _Exit()
    Exit
EndFunc
Hope it helps!
If I understood your reasoning correctly, by incorporating what you said into the script, the bot searches for an array at the maximum distance from x and will move towards that one instead of the array where it died?

Is this the logic you would try to implement?
05/18/2024 09:43 wombatandrzej#4
You assign 0 to $DeadOnTheRun every time you execute the function, so the first If will never be executed. Either pass this as parameter or check the status in the function.
05/18/2024 11:22 TheKuM1Ko#5
Quote:
Originally Posted by wombatandrzej View Post
You assign 0 to $DeadOnTheRun every time you execute the function, so the first If will never be executed. Either pass this as parameter or check the status in the function.
Code:
Func Death()
    If DllStructGetData(GetAgentByID(-2), "Effects") = 0x0010 Then
        Return 1
    Else
        Return 0
    EndIf
EndFunc ;==>Death

Func MoveandAggroVQ($aWaypoints)
    $DeadOnTheRun = Death()

    If $DeadOnTheRun = 1 Then
        Sleep(16000)
        Local $currentX = GetCurrentX()
        Local $currentY = GetCurrentY()
        Local $closestIndex = -1
        Local $minDistance = 1e10 

        For $i = 0 To UBound($aWaypoints) - 1
            Local $waypointX = $aWaypoints[$i][0]
            Local $waypointY = $aWaypoints[$i][1]
            Local $distance = Sqrt(($waypointX - $currentX)^2 + ($waypointY - $currentY)^2)

            If $distance < $minDistance Then
                $minDistance = $distance
                $closestIndex = $i
            EndIf
        Next

        For $Index = $closestIndex To UBound($aWaypoints) - 1
            AggroMoveTo($aWaypoints[$Index][0], $aWaypoints[$Index][1], $aWaypoints[$Index][2] & $ActionCounter, $aWaypoints[$Index][3])
            $ActionCounter += 1

            If $aWaypoints[$Index][0] = $waypointX And $aWaypoints[$Index][1] = $waypointY Then
                $DeadOnTheRun = 0
                ExitLoop
            EndIf
        Next
    ElseIf $DeadOnTheRun = 0 Then
        For $Index = 0 To UBound($aWaypoints) - 1
            AggroMoveTo($aWaypoints[$Index][0], $aWaypoints[$Index][1], $aWaypoints[$Index][2] & $ActionCounter, $aWaypoints[$Index][3])
            $ActionCounter += 1
        Next
    EndIf
EndFunc
Sorry but im totally new to coding, i checked my GWA and found this Dead func, i should integrate it like that?

Also i think i should add a while to execute dead check every for ex 30 sec?

Code:
While 1
      
        If TimerDiff($timer) >= 30000 Then
            $DeadOnTheRun = Death()
            $timer = TimerInit() ;

        EndIf
Something like that?