Sign in to follow this  
Followers 0
XZ3R0

Cant get timer to work

3 posts in this topic

#1 ·  Posted (edited)

I have a script. I dont want anything to happen till you press "s" then i want it to draw a red box on the screen for 5 seconds, after i want the box to end and then continue with the rest of the script.

Earlier i had the box working but it wouldn't move on, and so now i tried like 20 things and im all confused

#include <GDIPlus.au3>
#include <ScreenCapture.au3>
#include <WinAPI.au3>
HotKeySet("s", "ToggleTick"); s key starts and stops
HotKeySet("q", "Quit"); q key shuts down the script


Dim $start[2]
    $start[0] = 475
    $start[1] = 280
Dim $current[2]
    $current[0] = 1030
    $current[1] = 630
Dim $TickTimer = "false"
AdlibEnable("ToggleTick", 60000)

Dim $box = "false"
sleep(1000)
$endbox=TimerInit()
    If TimerDiff($endbox)<5000 Then
        $box = "true"
    Else
        $box = "false"
    EndIf

While 1=1
If $box = "true" then
    targetframe($start,$current,$box)
    sleep(5010)
Else
    WinActivate("Gamevance"); browser title here
    MouseClick( "left", 760, 440, 1, 0); auto start
    Sleep(500)
    While 1
    While $TickTimer = "True"
           $coor = PixelSearch( 475, 280, 1030, 630, 0xfcfcfc, 5, 8 )
            While Not @error
                MouseClick ( "left", ($Coor[0]), ($Coor[1]), 1, 3 )
                $coor = PixelSearch( 475, 280, 1030, 630, 0xfcfcfc, 5, 8 )
            WEnd
    WEnd
WEnd    
EndIf
WEnd



Func ToggleTick()
    If $TickTimer = "True" Then
        $TickTimer = "False"
        AdlibDisable()
    Else
            $TickTimer = "True"
            AdlibDisable()
            AdlibEnable("Toggletick", 60000)
    EndIf
EndFunc


Func Quit()
    Exit
EndFunc


Func targetframe($start,$current,$box)
    While $box = "true"
    $hd = DllCall("user32.dll", "int", "GetDC", "hwnd",0 )
    $pen = DllCall("gdi32.dll", "int", "CreatePen", "int", 0, "int", 2, "int", 0x0000ff)
    DllCall("gdi32.dll", "int", "SelectObject", "int", $hd[0], "int", $pen[0])
    DllCall("GDI32.dll", "int", "MoveToEx", "hwnd", $hd[0], "int",$start[0], "int", $start[1], "int", 0)
    DllCall("GDI32.dll", "int", "LineTo", "hwnd", $hd[0], "int", $start[0], "int", $current[1])
   ;DllCall("GDI32.dll", "int", "LineTo", "hwnd", $hd[0], "int", $current[0], "int", $start[1])
   
    DllCall("GDI32.dll", "int", "MoveToEx", "hwnd", $hd[0], "int",$current[0], "int", $start[1], "int", 0)
    DllCall("GDI32.dll", "int", "LineTo", "hwnd", $hd[0], "int", $current[0], "int", $current[1])
   ;DllCall("GDI32.dll", "int", "LineTo", "hwnd", $hd[0], "int", $start[0], "int", $start[1])
   
    DllCall("GDI32.dll", "int", "MoveToEx", "hwnd", $hd[0], "int",$current[0], "int", $current[1], "int", 0)
    DllCall("GDI32.dll", "int", "LineTo", "hwnd", $hd[0], "int", $start[0], "int", $current[1])
   
    DllCall("GDI32.dll", "int", "MoveToEx", "hwnd", $hd[0], "int",$start[0], "int", $start[1], "int", 0)
    DllCall("GDI32.dll", "int", "LineTo", "hwnd", $hd[0], "int", $current[0], "int", $start[1])

    DllCall("user32.dll", "int", "ReleaseDC", "hwnd", 0, "int", $hd[0])
    WEnd
EndFunc

any suggestions on how i should do a timed function (start/stop it after certain amount of time)? anything else wrong with this script? any ways to compress this scripted? thx in advance

edit: almost got it, i cant get it to exit out of making a box and switch into running the rest of the script though. what am i doing wrong?

Edited by XZ3R0

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Check out the TimerInit() and TimerDiff() functions in the Helpfile. They are exactly what you need. :) Also, if you're ever in the need of checking idle time there's a great func here.

edit: whoops I see you already know of them since they are in your script.

Edited by spudw2k

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

grr im so close heres the newest one i got.

edit: i figured it out! the problem was that the targerframe kept looping with while 1=1. not allowing the first loop to end. changed to while TimerDiff($endbox)<5000. works fine now!

#include <GDIPlus.au3>
#include <ScreenCapture.au3>
#include <WinAPI.au3>
HotKeySet("s", "ToggleTick"); s key starts and stops
HotKeySet("q", "Quit"); q key shuts down the script

Dim $start[2]
    $start[0] = 470
    $start[1] = 470
Dim $current[2]
    $current[0] = 1020
    $current[1] = 815
Dim $TickTimer = "false"
AdlibEnable("ToggleTick", 60000)
Dim $box = "false"

sleep(1000)

WinActivate("Gamevance"); browser title here
$endbox=TimerInit()
While 1
If TimerDiff($endbox)<5000 Then
    $box = "true"
    while 1
        If $box = "true" then
            targetframe($start,$current,$box)
            ExitLoop
        EndIf
    WEnd
Else
    $box = "false"
    WinActivate("Gamevance"); browser title here
    Sleep(500)
    MouseClick( "left", ($start[0]+(($current[0]-$start[0])/2)), ($start[1]+(($current[1]-$start[1])/2)), 1, 0); auto start
    Sleep(100)
    While 1
        While $TickTimer = "True"
            $coor = PixelSearch( $start[0], $start[1], [$current[0], $current[1], 0xfcfcfc, 5, 8 )
                While Not @error
                    MouseClick ( "left", ($Coor[0]), ($Coor[1]), 1, 3 )
                    $coor = PixelSearch( $start[0], $start[1], [$current[0], $current[1], 0xfcfcfc, 5, 8 )
                WEnd
        WEnd
    WEnd    
EndIf
WEnd



Func ToggleTick()
    If $TickTimer = "True" Then
        $TickTimer = "False"
        AdlibDisable()
    Else
            $TickTimer = "True"
            AdlibDisable()
            AdlibEnable("Toggletick", 60000)
    EndIf
EndFunc


Func Quit()
    Exit
EndFunc


Func targetframe($start,$current,$box)
    While TimerDiff($endbox)<5000
    $hd = DllCall("user32.dll", "int", "GetDC", "hwnd",0 )
    $pen = DllCall("gdi32.dll", "int", "CreatePen", "int", 0, "int", 2, "int", 0x0000ff)
    DllCall("gdi32.dll", "int", "SelectObject", "int", $hd[0], "int", $pen[0])
    DllCall("GDI32.dll", "int", "MoveToEx", "hwnd", $hd[0], "int",$start[0], "int", $start[1], "int", 0)
    DllCall("GDI32.dll", "int", "LineTo", "hwnd", $hd[0], "int", $start[0], "int", $current[1])
   ;DllCall("GDI32.dll", "int", "LineTo", "hwnd", $hd[0], "int", $current[0], "int", $start[1])
   
    DllCall("GDI32.dll", "int", "MoveToEx", "hwnd", $hd[0], "int",$current[0], "int", $start[1], "int", 0)
    DllCall("GDI32.dll", "int", "LineTo", "hwnd", $hd[0], "int", $current[0], "int", $current[1])
   ;DllCall("GDI32.dll", "int", "LineTo", "hwnd", $hd[0], "int", $start[0], "int", $start[1])
   
    DllCall("GDI32.dll", "int", "MoveToEx", "hwnd", $hd[0], "int",$current[0], "int", $current[1], "int", 0)
    DllCall("GDI32.dll", "int", "LineTo", "hwnd", $hd[0], "int", $start[0], "int", $current[1])
   
    DllCall("GDI32.dll", "int", "MoveToEx", "hwnd", $hd[0], "int",$start[0], "int", $start[1], "int", 0)
    DllCall("GDI32.dll", "int", "LineTo", "hwnd", $hd[0], "int", $current[0], "int", $start[1])

    DllCall("user32.dll", "int", "ReleaseDC", "hwnd", 0, "int", $hd[0])
    WEnd
EndFunc
Edited by XZ3R0

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