Sign in to follow this  
Followers 0
EverChosen

Repeating a Specific Func after a desired time length

13 posts in this topic

Hi all, I was wondering if it was possible for me to get a func to repeat itself after say 30 secs but still have the rest of the script running in the mean time?

Share this post


Link to post
Share on other sites



ok thanks

Share this post


Link to post
Share on other sites

Ummm that didn't work all the well :whistle:. I put it in the script and it worked as though it wasn't in there. This is how i used it:

AdlibEnable("AOE" , 34000)

Func AOE()
    If $AOE = 1 Then
        Send("1")
        Sleep(300)
        MouseMove(510, 420)
        Sleep(100)
        MouseClick("Left")
        Sleep(2000)
        Send("c")
    Else
    EndIf
EndFunc

And as i said it did absolutely nothing apart from do the function over and over again without waiting for the 34 seconds.

This is how they said to use it:

AdlibEnable("myadlib")
;...
Func myadlib()
    If WinActive("Error") Then
       ;...
    EndIf
EndFunc

Anyway if no one has any ideas, could someone help me with a timer, as im not to sure as how to start with those.

Share this post


Link to post
Share on other sites

Ummm that didn't work all the well :whistle:. I put it in the script and it worked as though it wasn't in there. This is how i used it:

AdlibEnable("AOE" , 34000)

Func AOE()
    If $AOE = 1 Then
        Send("1")
        Sleep(300)
        MouseMove(510, 420)
        Sleep(100)
        MouseClick("Left")
        Sleep(2000)
        Send("c")
    Else
    EndIf
EndFunc

And as i said it did absolutely nothing apart from do the function over and over again without waiting for the 34 seconds.

This is how they said to use it:

AdlibEnable("myadlib")
;...
Func myadlib()
    If WinActive("Error") Then
      ;...
    EndIf
EndFunc

Anyway if no one has any ideas, could someone help me with a timer, as im not to sure as how to start with those.

Is $AOE Global and does $AOE = 1? If not, then you never get to the inside of the AdlibEnable condition to do anything.

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

WinActivate("Knight OnLine Client")
WinWaitActive("Knight OnLine Client")

$Death = 0
$AOE = 1
$AOEFrequency = 32000
$SitColour = 0
$SitActual = 0
$DeathColour = 0
$DeathActual = 0
$HPPotKey = 8
$HPBarBlack = 0
$HPBarActual = 0
$MPPotKey = 7
$MPBarBlack = 0
$MPBarActual = 0
$AOEKey = 1
$Repair = 0
$RepairFrequency = 600000

AdlibEnable("Repair" , 600000)

Func Repair()
    If $Repair = 1 Then
        Sleep(100)
        MouseMove(880, 188)
        Sleep(100)
        MouseClick("Left")
        Sleep(100)
        MouseClick("Left")
    Else
    EndIf
EndFunc

Func Death()
    If $Death = 1 Then
        $DeathActual = PixelGetColor(156, 11)
        If $DeathActual = $DeathColour Then
            MouseMove(510, 440)
            Sleep(200)
            MouseDown("Left")
            Sleep(200)
            Mouseup("Left")
        Else
        EndIf
    Else
    EndIf
EndFunc

Func Heal()
    $HPBarActual = PixelGetColor(214, 11)
    If $HPBarBlack = $HPBarActual Then
        Send ($HPPotKey)
        Sleep ($LagDelay)
    Else
    EndIf
EndFunc

Func Mana()
    $MPBarActual = PixelGetColor(214, 27)
    If $MPBarBlack = $MPBarActual Then
        Send ($MPPotKey)
        Sleep ($LagDelay)
    EndIf
EndFunc

AdlibEnable("AOE" , 34000)

Func AOE()
    If $AOE = 1 Then
        Send("1")
        Sleep(300)
        MouseMove(510, 420)
        Sleep(100)
        MouseClick("Left")
        Sleep(2000)
        Send("c")
    Else
    EndIf
EndFunc

Send("{ENTER}")
Sleep(200)
Send("/Block_Trade_Request")
Sleep(200)
Send("{ENTER}")
Sleep(2000)
Send("{ENTER}")
Sleep(200)
Send("/Block_Party")
Sleep(200)
Send("{ENTER}")

While 1 = 1
    Call("Repair")
    Call("AOE")
    Call("Heal")
    Call("Mana")
    Call("Death")
WEnd

Thats the entire script, The $AOE is near the top. I will have to look at any replys tomorrow, i have to go to bed now. Just randomly, would a For...Next statement be any use? I was just looking around the loop statements.

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Try this:

CODE
WinActivate("Knight OnLine Client")
WinWaitActive("Knight OnLine Client")

$Death = 0
$AOE = 1
$AOEFrequency = 32000
$SitColour = 0
$SitActual = 0
$DeathColour = 0
$DeathActual = 0
$HPPotKey = 8
$HPBarBlack = 0
$HPBarActual = 0
$MPPotKey = 7
$MPBarBlack = 0
$MPBarActual = 0
$AOEKey = 1
$Repair = 0
$RepairFrequency = 600000

Func Repair()
    If $Repair = 1 Then
        Sleep(100)
        MouseMove(880, 188)
        Sleep(100)
        MouseClick("Left")
        Sleep(100)
        MouseClick("Left")
    EndIf
EndFunc   ;==>Repair

Func Death()
    If $Death = 1 Then
        $DeathActual = PixelGetColor(156, 11)
        If $DeathActual = $DeathColour Then
            MouseMove(510, 440)
            Sleep(200)
            MouseDown("Left")
            Sleep(200)
            MouseUp("Left")
        EndIf
    EndIf
EndFunc   ;==>Death

Func Heal()
    $HPBarActual = PixelGetColor(214, 11)
    If $HPBarBlack = $HPBarActual Then
        Send($HPPotKey)
        Sleep($LagDelay)
    EndIf
EndFunc   ;==>Heal

Func Mana()
    $MPBarActual = PixelGetColor(214, 27)
    If $MPBarBlack = $MPBarActual Then
        Send($MPPotKey)
        Sleep($LagDelay)
    EndIf
EndFunc   ;==>Mana

Func AOE()
    If $AOE = 1 Then
        Send("1")
        Sleep(300)
        MouseMove(510, 420)
        Sleep(100)
        MouseClick("Left")
        Sleep(2000)
        Send("c")
    EndIf
EndFunc   ;==>AOE

Send("{ENTER}")
Sleep(200)
Send("/Block_Trade_Request")
Sleep(200)
Send("{ENTER}")
Sleep(2000)
Send("{ENTER}")
Sleep(200)
Send("/Block_Party")
Sleep(200)
Send("{ENTER}")

$timer1 = TimerInit()
$timer2 = TimerInit()

While 1
    If TimerDiff($timer1) > 600000 Then
        Repair()
        $timer1 = TimerInit()
    EndIf
    If TimerDiff($timer2) > 34000 Then
        AOE()
        $timer2 = TimerInit()
    EndIf
    Heal()
    CallMana ()
    Death()
    Sleep(50)
WEnd

-removed adlibs (pretty sure you can only do 1 at a time anyway... could be wrong, though)

-removed unnecessary 'else's

-added $timer stuff, in and just before while loop

-stuck a sleep in the while loop so it doesn't kill cpu usage

-removed =1 from while loop. not needed

-removed your 'call' stuff

edit - forgot something :whistle:

I don't see where $repair and $death ever become 1, and I don't see $lagdelay being given a value.

Edited by xcal

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Oh yea i forgot to add the $lagdelay, and $repair and $death become 1 when i make them 1. Not exactly a variable but it works in this instance. Because all i want it to do is if i want it to repair i can just change the 0 for a 1 instead of putting ; infront of the whole func, and with death all i want it to do is when i want, it looks to see if im dead and clicks the ok to respawn, otherwise not.

Oh and i will try that script when i get home from school. And thanks heaps for having a look at it.

Edited by EverChosen

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Hey thanks xcal, that worked great.

Well instead of starting a new topic i will ask my next qeustion here, is it possible to get autoit to recognise a series of letters that have a constantly changing background. Here is an example of the letters ( the background always changes.)

I might aswell also ask if it is possible for the script to recognise the time and at a specified time, shut the computer down.

Example.bmp

Edited by EverChosen

Share this post


Link to post
Share on other sites

Anyone?

Share this post


Link to post
Share on other sites

Anyone?

no idea about the text stuff mate but you might want to do a search on "OCR" as that sounds like what your after...

For the time thingy you could try something like this:

#Include <Date.au3>
$time = _NowTime() ;retrieves the current system time
$shutdowntime = "8:00:00 PM" ;time you want the machine to shutdown
If $time > $shutdowntime Then
    ConsoleWrite("Time to shutdown.. Bye Bye") ;Commands to execute if $time is greater than $shutdowntime
    Shutdown(9) ;shuts the machine down
EndIf

there might be more elegant ways to do this but in theory it should work if you whack it in your AdLib Function somewhere :whistle:

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

hey thanks fu2m8, this is just what i was looking for :whistle: i will give it a go on searching for "OCR."

Or instead of recognising the text is it possible for autoit to read memory adresses?

Edited by EverChosen

Share this post


Link to post
Share on other sites

So is it possible to get AutoIt to read memory adresses?

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