Sign in to follow this  
Followers 0
Overlord

need help with sleeptimer

8 posts in this topic

Ok, I got problems with my script here.

I want it to automatically press a button at a required time.

I thought this would be logical and simple but he doesn't press his buttons the way I want.

I'm also having problems in my timer-function. How do I tell to ignore that timer if the field is blank in the ini for that specific timer?

example: I have 3 timers here. Timer 1 is set to 10 seconds and timer 3 is set to 8 seconds.

so every 10 seconds I want timer 1 to be executed and every 8 seconds I want timer3 to be executed. Timer 2 should be ignored.

;##################################
; ini-parameters
;##################################
Global $Paused
HotKeySet("{F9}", "Pause")
$timer1 = IniRead( @ScriptDir & "\autocaster.ini", "timers", "timer1", "default"); timer for skill 1
$timer2 = IniRead( @ScriptDir & "\autocaster.ini", "timers", "timer2", "default"); timer for skill 2
$timer3 = IniRead( @ScriptDir & "\autocaster.ini", "timers", "timer3", "default"); timer for skill 3

;##################################
; main script
;##################################
Pause()
While 1
    timer1()
    timer2()
    timer3()
WEnd

;##################################
;main functions
;##################################

Func Pause() ; used to pause the script
    $Paused = Not $Paused
    While $Paused
        ToolTip("PAUSED",0,0)
        Sleep(100)
        ToolTip("")
    WEnd
EndFunc   ;==>TogglePause

Func timer1()
    If $timer1= "" Then 
    Else
    Send("{NUMPAD1}")
    MouseClick("right")
    MouseClick("left")
    Sleep($timer1)
    EndIf
EndFunc

Func timer2()
    If $timer2= "" Then 
    Else
    Send("{NUMPAD2}")
    MouseClick("right")
    MouseClick("left")
    Sleep($timer2)
    EndIf
EndFunc

Func timer3()
    If $timer3= "" Then 
    Else
    Send("{NUMPAD3}")
    MouseClick("right")
    MouseClick("left")
    Sleep($timer3)
    EndIf
EndFunc

Share this post


Link to post
Share on other sites



Something like:

Global $iTimer = TimerInit()
Global $Action1 = 10, $Action2 = 8, $Action1Initiated
AdlibEnable('_AdlibManager', 100)

While 1
    Sleep(1000)
WEnd

Func _AdlibManager()
    Local $iDiff = TimerDiff($iTimer) / 1000
    If $iDiff >= $Action1 Then
        ConsoleWrite(@LF & 'Timer 1 Diff = ' & $iDiff)
        $Action1Initiated = Not $Action1Initiated
        $iTimer = TimerInit()
    ElseIf $iDiff >= $Action2 And $Action1Initiated Then
        ConsoleWrite(@LF & 'Timer 2 Diff = ' & $iDiff)
        $Action1Initiated = Not $Action1Initiated
        $iTimer = TimerInit()
    EndIf
EndFuncoÝ÷ ØêÚºÚ"µÍÛØ[   ÌÍÚU[YH[Y[]

BÛØ[  ÌÍÐXÝ[ÛHH  ÌÍÐXÝ[ÛHL  ÌÍÐXÝ[ÛR[]X]YYX[XJ ÌÎN×ÐYXX[YÙÌÎNËL
BÚ[HBTÛY
L
BÑ[[ÈÐYXX[YÙ
BSØØ[ ÌÍÚQYH[YY    ÌÍÚU[YHÈLRY ÌÍÚQY    ÝÏH   ÌÍÐXÝ[ÛH[Ý    ÌÍÐXÝ[ÛR[]X]Y[BPÛÛÛÛUÜ]J  [È ÌÎNÕ[YHYH    ÌÎNÈ [È ÌÍÚQYBBIÌÍÐXÝ[ÛR[]X]YHÝ    ÌÍÐXÝ[ÛR[]X]YQ[ÙRY    ÌÍÚQY    ÝÏH   ÌÍÐXÝ[Û[BPÛÛÛÛUÜ]J    [È ÌÎNÕ[YYH ÌÎNÈ [È ÌÍÚQYBBIÌÍÚU[YH[Y[]

BBIÌÍÐXÝ[ÛR[]X]YHÝ    ÌÍÐXÝ[ÛR[]X]YQ[Y[[
?

Open SciTe and run in there to see what's going on.


[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

Hi,

hmmh I can only offer this untested version:

;##################################
; ini-parameters
;##################################
Global $Paused
HotKeySet("{F9}", "Pause")
$timer1 = 10000;IniRead( @ScriptDir & "\autocaster.ini", "timers", "timer1", "default"); timer for skill 1
$timer2 = "";IniRead( @ScriptDir & "\autocaster.ini", "timers", "timer2", "default"); timer for skill 2
$timer3 = 8000;IniRead( @ScriptDir & "\autocaster.ini", "timers", "timer3", "default"); timer for skill 3

;##################################
; main script
;##################################
Pause()
While 1
    If Not $Paused Then _timer1()
    Sleep(1000)
WEnd

;##################################
;main functions
;##################################

Func _timer1()
    $start_T1 = TimerInit()
    $start_T2 = TimerInit()
    While 1
        If TimerDiff($start_T1) >= $timer1 Then
            Send("{NUMPAD1}")
            ;MouseClick("right")
            ;MouseClick("left")
            $start_T1 = TimerInit()
        EndIf
        If TimerDiff($start_T2) >= $timer3 Then
            Send("{NUMPAD3}")
            ;MouseClick("right")
            ;MouseClick("left")
            $start_T2 = TimerInit()
        EndIf
    WEnd
EndFunc   ;==>_timer1

Func Pause() ; used to pause the script
    $Paused = Not $Paused
    While $Paused
        ToolTip("PAUSED", 0, 0)
        Sleep(100)
        ToolTip("")
    WEnd
EndFunc   ;==>Pause

So long,

Mega


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites

#Include <Date.au3>
#include <GUIConstants.au3>
Global $Secs, $Mins, $Hour, $Time, $sTime


$My_gui=GUICreate( "Watch", 200, 200, 810, 200, BitOR($WS_CAPTION, $WS_EX_TOPMOST, $WS_POPUPWINDOW))
$Go=GUICtrlCreateButton("Start",150,50,50,50)
$Clock = GUICtrlCreateLabel("", 0, 0, 200, 50)
GUICtrlSetFont(-1, 24)
$timer1 = GUICtrlCreateLabel("", 0, 70, 100, 50)
$timer2 = GUICtrlCreateLabel("", 0, 140, 50, 50)

$spin_1 = GUICtrlCreateInput ("Hr",40,140,40,20)
$updown_s1 = GUICtrlCreateUpdown($spin_1)
GUICtrlSetLimit ( -1, 23, 0 )
$spin_2 = GUICtrlCreateInput ("Min",85,140,40,20)
$updown_s2 = GUICtrlCreateUpdown($spin_2)
GUICtrlSetLimit ( -1, 59, 0 )
$spin_3 = GUICtrlCreateInput ("Sec",125,140,40,20)
$updown_s3 = GUICtrlCreateUpdown($spin_3)
GUICtrlSetLimit ( -1, 59, 0 )


GUISetState()
$Start=0



AdlibEnable("_time", 1000)

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            _Exit()
        case $msg = $Go 
            If GUICtrlRead($go)="Start" Then
            $Hour = GUICtrlRead($spin_1)
            $Mins = GUICtrlRead($spin_2)
            $Secs = GUICtrlRead($spin_3)
            if  $Hour = "Hr" or $Mins= "Min" or  $Secs="Sec" then
            MsgBox(0,"Error!!","Set the clock properly",4)
            Elseif $Hour=0 and $Mins=0 and $Secs<=5 Then
            MsgBox(0,"Error!!","00:00:0"&$Secs&" Not Allowed !!!",4)
            Else
            $Time = _TimeToTicks($Hour, $Mins, $Secs)
            $Start=1
        
        EndIf
            
            
        elseif GUICtrlRead($go)="Running" Then
            $Time=0
            
            EndIf
    EndSelect
WEnd

Func _time()
    If $Time > 0 and $start=1 Then
        GUICtrlSetData($Go,"Running")
        $Time = $Time - 1000
        $sTime = $Time
        _TicksToTime($sTime, $Hour, $Mins, $Secs)
        $sTime = StringFormat("%02i:%02i:%02i", $Hour, $Mins, $Secs)
    Else    
$start=0
    
    GUICtrlSetData($Go,"Start")
EndIf
    Local $sTime2 = $sTime
Local $Time=$Time
    GUICtrlSetData($timer1, $sTime2)
    GUICtrlSetData($timer2, $Time)
    GUICtrlSetData($Clock, _NowTime())
EndFunc  ;==>_time

Func _Exit()
    GUIDelete()
    Exit
EndFunc  ;==>_Exit

Share this post


Link to post
Share on other sites

Hi,

hmmh I can only offer this untested version:

;##################################
; ini-parameters
;##################################
Global $Paused
HotKeySet("{F9}", "Pause")
$timer1 = 10000;IniRead( @ScriptDir & "\autocaster.ini", "timers", "timer1", "default"); timer for skill 1
$timer2 = "";IniRead( @ScriptDir & "\autocaster.ini", "timers", "timer2", "default"); timer for skill 2
$timer3 = 8000;IniRead( @ScriptDir & "\autocaster.ini", "timers", "timer3", "default"); timer for skill 3

;##################################
; main script
;##################################
Pause()
While 1
    If Not $Paused Then _timer1()
    Sleep(1000)
WEnd

;##################################
;main functions
;##################################

Func _timer1()
    $start_T1 = TimerInit()
    $start_T2 = TimerInit()
    While 1
        If TimerDiff($start_T1) >= $timer1 Then
            Send("{NUMPAD1}")
            ;MouseClick("right")
            ;MouseClick("left")
            $start_T1 = TimerInit()
        EndIf
        If TimerDiff($start_T2) >= $timer3 Then
            Send("{NUMPAD3}")
            ;MouseClick("right")
            ;MouseClick("left")
            $start_T2 = TimerInit()
        EndIf
    WEnd
EndFunc   ;==>_timer1

Func Pause() ; used to pause the script
    $Paused = Not $Paused
    While $Paused
        ToolTip("PAUSED", 0, 0)
        Sleep(100)
        ToolTip("")
    WEnd
EndFunc   ;==>Pause

but now he constantly keeps pressing that numpad 2 since that field is blank. Ocasionally he does press the other buttons also in the correct order.

Share this post


Link to post
Share on other sites

Be a smart cow (hmm) and look at my example.


[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

#7 ·  Posted (edited)

Be a smart cow (hmm) and look at my example.

well... there's a code that I completely don't understand :)

and it doesn't runlike it needs to be.

in your script, timer1 should execute every 10 seconds while timer 2 executes every 8 seconds.

In reality, he executes timer1, then goes back to sleep and executes timer2 even if timer1 happens sooner.

I tested it with other numbers.

Timer 1 Diff = 10.0783803528102

Timer 2 Diff = 3.06138377922334

Timer 1 Diff = 10.0219670377101

as you see, timer 2 should have been executed at least 3 times during timer 1

Edited by Overlord

Share this post


Link to post
Share on other sites

well... there's a code that I completely don't understand :)

and it doesn't runlike it needs to be.

in your script, timer1 should execute every 10 seconds while timer 2 executes every 8 seconds.

In reality, he executes timer1, then goes back to sleep and executes timer2 even if timer1 happens sooner.

I tested it with other numbers.

Timer 1 Diff = 10.0783803528102

Timer 2 Diff = 3.06138377922334

Timer 1 Diff = 10.0219670377101

as you see, timer 2 should have been executed at least 3 times during timer 1

I gave 100% of the information you need to disect and manipulate to your needs, must I hold your hand through the entire process as well?

[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

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