Jump to content

advice on making these loops more accuate?


Recommended Posts

tried to cut down code by calling repeating functions... and in the end its giving wildly random results >.<

in a nutshell... i have a script that constantly checks five color boxes... if one goes orange... it should detect which then call the function to react (heal) on that particular one....

atm i can't see if my logic is simply flawed... its running too fast to ever match correctly or what

;ModDps...
#AutoIt3Wrapper_run_debug_mode=Y
sleep(5000)
$time_for_color = 500

; Hot Keys 
HotKeySet("{PAUSE}", "request_end") 

func request_end()
    Exit
EndFunc
    
While 1 ; main forever loop...
    $HealthNum = HealthCheck()
    
    While $HealthNum = 5
        ; as long as health / mana ok... call normal dps fun
        $HealthNum = HealthCheck()
        ToolTip("Health is Green: " & $HealthNum)
        sleep(100)
    WEnd
    
    Tooltip("Party " & $HealthNum & " member is hurt")
    if $HealthNum < 5 Then
        HealParty($HealthNum)
    EndIf
    
    sleep(100)
    
WEnd


Func HealthCheck()
    ; will return the first match of a person that needs a heal
    ; returns num 0-4 for which party member to target
    ; returns num 5 if all health is ok and good to continue dps
    $i = 0
    $Color_Matched = 0
    While $i < 5 and $Color_Matched = 0
        if $i = 0 Then
            $Color_Matched = ColorCheck(60, 510, "0xFF4000")
            ; MouseMove(60, 510)
             ;ToolTip("Color_Matched is: " & $Color_Matched)
        ElseIf $i = 1 Then
            $Color_Matched = ColorCheck(60, 540, "0xFF4000")
            ; MouseMove(60, 540)
            ; ToolTip("Color_Matched is: " & $Color_Matched)
        ElseIf $i = 2 Then
            $Color_Matched = ColorCheck(60, 570, "0xFF4000")
            ; MouseMove(60, 570)
            ; ToolTip("Color_Matched is: " & $Color_Matched)
        ElseIf $i = 3 Then
            $Color_Matched = ColorCheck(60, 600, "0xFF4000")
            ; MouseMove(60, 600)
            ; ToolTip("Color_Matched is: " & $Color_Matched)
        ElseIf $i = 4 Then
            $Color_Matched = ColorCheck(60, 630, "0xFF4000")
            ; MouseMove(60, 630)
            ; ToolTip("Color_Matched is: " & $Color_Matched)
        EndIf
        $i = $i + 1
    WEnd
    return $i
EndFunc

Func ManaCheck()
    ; checks if anyone needs to drink
    ; returns 0-1 no / yes if yes attempt to break combat
    ; returns 3 if all mana ok and good to continue dps
EndFunc

func HealParty($HealthNum)
    if $HealthNum = 0 then
        send("{F1}")
    elseif $HealthNum = 1 then
        send("{F2}")
    elseif $HealthNum = 2 then
        send("{F3}")
    elseif $HealthNum = 3 then
        send("{F4}")
    elseif $HealthNum = 4 then
        send("{F5}")
    else
        ; do nothing...
    EndIf
    
    sleep(1500) ; lag for alt clients to get assist
    send("-")
    Sleep(2000) ; wait for healing wave to finish casting
EndFunc

Func ColorCheck($x, $y, $color)
    $search_color_time = TimerInit()
    While TimerDiff($search_color_time) < $time_for_color
        $pos = PixelSearch($x, $y, $x, $y, $color, 10, 1)
            If @error Then
                SetError(0)
            Else
                $Color_Matched = 1
                return $Color_Matched
            EndIf
                            
    WEnd
EndFunc

Don't let that status fool you, I am no advanced memeber!

Link to comment
Share on other sites

tried to cut down code by calling repeating functions... and in the end its giving wildly random results >.<

in a nutshell... i have a script that constantly checks five color boxes... if one goes orange... it should detect which then call the function to react (heal) on that particular one....

atm i can't see if my logic is simply flawed... its running too fast to ever match correctly or what

;ModDps...
#AutoIt3Wrapper_run_debug_mode=Y
sleep(5000)
$time_for_color = 500

; Hot Keys 
HotKeySet("{PAUSE}", "request_end") 

func request_end()
    Exit
EndFunc
    
While 1 ; main forever loop...
    $HealthNum = HealthCheck()
    
    While $HealthNum = 5
        ; as long as health / mana ok... call normal dps fun
        $HealthNum = HealthCheck()
        ToolTip("Health is Green: " & $HealthNum)
        sleep(100)
    WEnd
    
    Tooltip("Party " & $HealthNum & " member is hurt")
    if $HealthNum < 5 Then
        HealParty($HealthNum)
    EndIf
    
    sleep(100)
    
WEnd


Func HealthCheck()
    ; will return the first match of a person that needs a heal
    ; returns num 0-4 for which party member to target
    ; returns num 5 if all health is ok and good to continue dps
    $i = 0
    $Color_Matched = 0
    While $i < 5 and $Color_Matched = 0
        if $i = 0 Then
            $Color_Matched = ColorCheck(60, 510, "0xFF4000")
            ; MouseMove(60, 510)
             ;ToolTip("Color_Matched is: " & $Color_Matched)
        ElseIf $i = 1 Then
            $Color_Matched = ColorCheck(60, 540, "0xFF4000")
            ; MouseMove(60, 540)
            ; ToolTip("Color_Matched is: " & $Color_Matched)
        ElseIf $i = 2 Then
            $Color_Matched = ColorCheck(60, 570, "0xFF4000")
            ; MouseMove(60, 570)
            ; ToolTip("Color_Matched is: " & $Color_Matched)
        ElseIf $i = 3 Then
            $Color_Matched = ColorCheck(60, 600, "0xFF4000")
            ; MouseMove(60, 600)
            ; ToolTip("Color_Matched is: " & $Color_Matched)
        ElseIf $i = 4 Then
            $Color_Matched = ColorCheck(60, 630, "0xFF4000")
            ; MouseMove(60, 630)
            ; ToolTip("Color_Matched is: " & $Color_Matched)
        EndIf
        $i = $i + 1
    WEnd
    return $i
EndFunc

Func ManaCheck()
    ; checks if anyone needs to drink
    ; returns 0-1 no / yes if yes attempt to break combat
    ; returns 3 if all mana ok and good to continue dps
EndFunc

func HealParty($HealthNum)
    if $HealthNum = 0 then
        send("{F1}")
    elseif $HealthNum = 1 then
        send("{F2}")
    elseif $HealthNum = 2 then
        send("{F3}")
    elseif $HealthNum = 3 then
        send("{F4}")
    elseif $HealthNum = 4 then
        send("{F5}")
    else
        ; do nothing...
    EndIf
    
    sleep(1500) ; lag for alt clients to get assist
    send("-")
    Sleep(2000) ; wait for healing wave to finish casting
EndFunc

Func ColorCheck($x, $y, $color)
    $search_color_time = TimerInit()
    While TimerDiff($search_color_time) < $time_for_color
        $pos = PixelSearch($x, $y, $x, $y, $color, 10, 1)
            If @error Then
                SetError(0)
            Else
                $Color_Matched = 1
                return $Color_Matched
            EndIf
                            
    WEnd
EndFunc
How fast is your computer?

instead of having sleep(100) make it sleep(10) - - - or less

[u][font="Century Gothic"]~я α и d γ ĵ . ċ . ѕ қ ϊ и и ε я~- My Programs -auto shutdownSleep funcdisallow programs[/font][/u]
Link to comment
Share on other sites

How fast is your computer?

instead of having sleep(100) make it sleep(10) - - - or less

i wish that was it >.< its not a matter of the color boxes changing so quickly that it missed it being orange... it simply isn't catching it all all - same if its sleep(10) i have noticed if its the first or second box it does seem to catch it more often where if its the last few boxes it doesn't seem to catch it at all

Don't let that status fool you, I am no advanced memeber!

Link to comment
Share on other sites

i wish that was it >.< its not a matter of the color boxes changing so quickly that it missed it being orange... it simply isn't catching it all all - same if its sleep(10) i have noticed if its the first or second box it does seem to catch it more often where if its the last few boxes it doesn't seem to catch it at all

multiple scripts?

[u][font="Century Gothic"]~я α и d γ ĵ . ċ . ѕ қ ϊ и и ε я~- My Programs -auto shutdownSleep funcdisallow programs[/font][/u]
Link to comment
Share on other sites

multiple scripts?

yes but turned the rest off for sanity sake and still same issue... i might just go back to the old crude way of making scripts thousands of repeated lines of code long... at least that way it works for me >.> lol

Don't let that status fool you, I am no advanced memeber!

Link to comment
Share on other sites

found it.... >.< $i was incramenting when it shouldn't have i wanted it to simply stop looping when it hit a match on the search function but it added one extra anyway when droping the while loop... ghetto failed logic ftl

Func HealthCheck()
    ; will return the first match of a person that needs a heal
    ; returns num 0-4 for which party member to target
    ; returns num 5 if all health is ok and good to continue dps
    $i = 0
    $Color_Matched = 0
    While $i < 5 and $Color_Matched = 0
        if $i = 0 Then
            $Color_Matched = ColorCheck(60, 510, "0xFF4000")
            ; MouseMove(60, 510)
            ToolTip("Color_Matched is: " & $Color_Matched)
            sleep(1000)
        ElseIf $i = 1 Then
            $Color_Matched = ColorCheck(60, 540, "0xFF4000")
            ; MouseMove(60, 540)
            ToolTip("Color_Matched is: " & $Color_Matched)
            sleep(1000)
        ElseIf $i = 2 Then
            $Color_Matched = ColorCheck(60, 570, "0xFF4000")
            ; MouseMove(60, 570)
            ToolTip("Color_Matched is: " & $Color_Matched)
            sleep(1000)
        ElseIf $i = 3 Then
            $Color_Matched = ColorCheck(60, 600, "0xFF4000")
            ; MouseMove(60, 600)
            ToolTip("Color_Matched is: " & $Color_Matched)
            sleep(1000)
        ElseIf $i = 4 Then
            $Color_Matched = ColorCheck(60, 630, "0xFF4000")
            ; MouseMove(60, 630)
            ToolTip("Color_Matched is: " & $Color_Matched)
            sleep(1000)
        EndIf
        if $Color_Matched = 0 Then
            $i = $i + 1
        EndIf
    WEnd
    return $i
EndFunc

Don't let that status fool you, I am no advanced memeber!

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...