Jump to content
Sign in to follow this  
gui529

Button only pressed once.

Recommended Posts

gui529

I have written this code and this GUI but the buttons can only be pressed once...like...The gui is create but the buttons only work once..for example..if i press START..it works but other two dont work...i have to close script and reopen...and if i press STOP first..the other two dont work..(func dont run)...etc..

Opt("GUIOnEventMode", 1);==TOP <-----------


 blahblah..create GUI..and then at bottom of it i have 
GUICtrlSetOnEvent($Exit, "Terminate")
GUICtrlSetOnEvent($Start, "StartB")
GUICtrlSetOnEvent($Stop, "StopB")
;======Function that starts the bot
Func StartB()
    $Paused = True
    Call("TogglePause")
EndFunc
;====Function that stops the bot
Func StopB()
    $Paused = False
    Call("TogglePause")
EndFunc

;=====FUNCTION THAT EXITS BOT===========
Func Terminate() 
    Exit 0 
EndFunc
Edited by gui529

Share this post


Link to post
Share on other sites
Yeik

Maybe your function calls something that loops or hangs.

Would have to see more code to help.


func get_quote()
   local $quote 
   switch random(1, 3, 1)
    case 1
     $quote = '"' & "A human being should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, " & _
       "design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give " & _
       "orders, cooperate, act alone, solve equations, analyze a new problem, pitch manure, program a computer, cook a tasty meal, " & _
       "fight efficiently, die gallantly. Specialization is for insects." & '"' & " Robert A. Heinlein"
    case 2
     $quote =  '"' & "Within each of us lies the power of our consent to health and sickness, to riches and poverty, to freedom " & _
       "and to slavery. It is we who control these, and not another." & '"' & " Richard Bach (Illusions)"
    case 3
     $quote ='"' & "Don't handicap your children by making their lives easy." & '"' & " Robert A. Heinlein"
   EndSwitch
   MsgBox(0, "Quote for the moment", $quote & @CRLF)
EndFunc

get_quote()

Share this post


Link to post
Share on other sites
gui529

its true my functions all loops...but isnt there a way to force the event...? if button pressed then stop and call the function.

Edited by gui529

Share this post


Link to post
Share on other sites
martin

its true my functions all loops...but isnt there a way to force the event...? if button pressed then stop and call the function.

When an event calls a function in OnEvent mode, no other event will be executed untill that function returns. So you can get round this to some extent by having the first event set a flag and in your main idle loop call the function if the flag is set. A function csalled this way will be halted while another function called by an event is executed.

Opt("GUIOnEventMode", 1);==TOP <-----------


blahblah..create GUI..And Then at bottom of it i have
GUICtrlSetOnEvent($Exit, "Terminate")
GUICtrlSetOnEvent($Start, "StartB")
GUICtrlSetOnEvent($Stop, "StopB")
Global $runb = False
While 1
    Sleep(30)
    If $runb Then
        StartB1();this can be interrupted by an event
        $runb = False
    EndIf


WEnd

Func Startb()
    $runb = True
EndFunc  ;==>Startb

;======Function that starts the bot
Func StartB1()
    $Paused = True
    Call("TogglePause");better to use TogglePause()
EndFunc  ;==>StartB1
;====Function that stops the bot
Func StopB()
    $Paused = False
    Call("TogglePause")
EndFunc  ;==>StopB

;=====FUNCTION THAT EXITS BOT===========
Func Terminate()
    Exit 0
EndFunc  ;==>Terminate

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites
gui529

new code posted below!!

Edited by gui529

Share this post


Link to post
Share on other sites
gui529

I got it to work but only problem is that it takes too long to call the STOP action...the exit key works the moment i press it but the STOP key waits until the whole START script is over for it to stop..how can i make it instant?

basically when STOP is pressed i want it to STOP immidiately

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)
$account = "guilherme09"
$password = "132020as"
$usepotion = False ;==========USE AS POTION? its F8 key!!
$minimized = False
;$prebuffed = False
Local $timer1, $timer2, $timer3, $timerpg, $timerpot, $timeratak, $timerrestart,$prebuffed = false

Global $Paused = True, $UnBuff, $lvlup = True, $usepotion
$runb = False

HotKeySet("{PAUSE}", "TogglePause") 
HotKeySet("{END}", "Terminate")
HotKeySet("{HOME}", "Autobuff")
HotKeySet("^{PGUP}", "Togglelvlup") 
HotKeySet("^{PGDN}", "Togglelvldown")
HotKeySet("^{f8}", "potion")
HotKeySet("{INSERT}", "Options") 
$GameTitle = "Archlord"
;=================================================================
Dim $BuffTimer1   = 648 ;===== cooldown of Buff 1 ===============                  
Dim $BuffTimer2   = 528 ;===== cooldown of Buff 2 ===============                    
Dim $BuffTimer3   = 528 ;===== cooldown of Buff 3 ===============
Dim $Pgtimer      = 5   ;=====Timer of the pageup/down===========
Dim $MonsterKill  = 12  ;===== Seconds It take to kill monster===
Dim $pottimer    = 360 ;===== 360 seconds = 6 minutes ======
;=================================================================
;============USER INTERFACE===================
#Region ### START Koda GUI section ### Form=c:\documents and settings\hp_owner\my documents\my pictures\form1.kxf
$Form1 = GUICreate("Form1", 392, 178, 361, 337)
$Main = GUICtrlCreateTab(0, 0, 391, 145)
GUICtrlSetResizing(-1, $GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)
$TabSheet1 = GUICtrlCreateTabItem("Main")
$TabSheet2 = GUICtrlCreateTabItem("Attack Settings")
$Attack1 = GUICtrlCreateCheckbox("Attack 1", 16, 32, 65, 17)
$Atk1key = GUICtrlCreateInput("", 88, 32, 49, 21)
$Atk2key = GUICtrlCreateInput("", 88, 59, 49, 21)
$Atk3key = GUICtrlCreateInput("", 88, 88, 49, 21)
$Attack2 = GUICtrlCreateCheckbox("Attack 2", 16, 59, 65, 25)
$Attack3 = GUICtrlCreateCheckbox("Attack 3", 16, 88, 65, 25)
$Label1 = GUICtrlCreateLabel("Place the hotkey of the attack in boxes.", 8, 112, 327, 28)
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
$Label2 = GUICtrlCreateLabel("*Recomended only two attacks.", 168, 32, 155, 17)
$TabSheet3 = GUICtrlCreateTabItem("Buffs Settings")
GUICtrlSetState(-1,$GUI_SHOW)
$Buff1 = GUICtrlCreateCheckbox("Buff 1", 14, 35, 65, 17)
$Buff2 = GUICtrlCreateCheckbox("Buff 2", 14, 64, 65, 17)
$Buff4 = GUICtrlCreateCheckbox("Buff 4", 149, 64, 65, 17)
$Buff3 = GUICtrlCreateCheckbox("Buff 3", 149, 35, 65, 17)
$Buff4key = GUICtrlCreateInput("", 219, 64, 49, 21)
$Label3 = GUICtrlCreateLabel("Place the hotkey of buffs in boxes!", 24, 96, 288, 28)
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
$Buff3key = GUICtrlCreateInput("", 219, 35, 49, 21)
$Buff1key = GUICtrlCreateInput("", 80, 35, 49, 21)
$Buff2key = GUICtrlCreateInput("", 80, 64, 49, 21)
$TabSheet4 = GUICtrlCreateTabItem("Others")
GUICtrlCreateTabItem("")
$Start = GUICtrlCreateButton("START", 8, 144, 65, 33, 0)
GUICtrlSetBkColor(-1, 0x00FF00)
$Stop = GUICtrlCreateButton("STOP", 77, 144, 65, 33, 0)
GUICtrlSetBkColor(-1, 0xFF0000)
$Exit = GUICtrlCreateButton("EXIT", 148, 144, 65, 33, 0)
GUICtrlSetBkColor(-1, 0x808000)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

GUICtrlSetOnEvent($Exit, "Terminate")
GUICtrlSetOnEvent($Start, "StartB")
GUICtrlSetOnEvent($Stop, "StopB")
;=================END OF USER INTERFACE


;WinWaitActive($GameTitle)?

while 1
        if $runb = True then
        call("Botloop")
    EndIf
    
    if $runb = False then
        ToolTip("  GuiBot is Paused. For options press {INSERT}  Press {Pause} To start Guibot ", 0, 0,"",0,4) 
        endif

wend


;===================Options==================
Func Options()
While 1
    Sleep(10)
$t = '-----GuiBOT OPTIONS-----' & @CR & '{PAUSE} Starts or Pauses GuiBot.' & @CR & '{END} Exit GuiBot' & @CR & '{HOME} Starts Autoitem Pickup + Autobuff' & @CR & '{CONTROL+PAGE UP} Increase Monster Kill Seconds' & @CR &'{CONTROL+PAGE DOWN} Decrease Monster Kill Seconds'& @CR &'{INSERT} Open this Menu'
    ToolTip($t,0,0,"",0,4)
 WEnd
EndFunc
;==============PAGE UP/DOWN SET TIMER FOR MONSTER!!======
Func Togglelvlup()
    $timerpg = timerinit()
    $MonsterKill = $MonsterKill + 1
    
    While $lvlup = True
    ToolTip( "  Press Pause to resume GuiBot. Kill Monster Cooldown = " & $MonsterKill, 0, 0,"",0,4)
    If timerdiff($timerpg) >= 5000 Then
    Call("Start")
        EndIf
    WEnd
    
    While $lvlup = False
    ToolTip( "  Press Pause to resume GuiBot. Kill Monster Cooldown = " & $MonsterKill, 0, 0,"",0,4)
    If timerdiff($timerpg) >= 5000 Then
    Call ("Botloop")
        EndIf
WEnd
EndFunc

Func Togglelvldown()
    $timerpg = timerinit()
    $MonsterKill = $MonsterKill - 1
    
    While $lvlup = True
    ToolTip( "  Press Pause to resume GuiBot. Kill Monster Cooldown = " & $MonsterKill, 0, 0,"",0,4)
    If timerdiff($timerpg) >= 5000 Then
    Call("Start")
        EndIf
    WEnd
    
    While $lvlup = False
    ToolTip( "  Press Pause to resume GuiBot. Kill Monster Cooldown = " & $MonsterKill, 0, 0,"",0,4)
    If timerdiff($timerpg) >= 5000 Then
    Call ("Botloop")
        EndIf
WEnd
EndFunc
;=============START PREBUFF============
func Prebuff()
    if $prebuffed = False then
        ToolTip("Pre-Buffing ", 0, 0,"",0,4)
    $prebuffed = True
        Sleep(2000)
        ControlSend($GameTitle, "", "", "{f5}")
        Sleep(2700)
    $timer1 = timerinit()
        ControlSend($GameTitle, "", "", "{f6}")
        Sleep(2700)
    $timer2 = timerinit()
        ControlSend($GameTitle, "", "", "{f7}")
        Sleep(2700)
    $timer3 = timerinit()
        If $usepotion = True Then
        ControlSend($GameTitle, "", "", "{f8}")
        Sleep(2700)
    $timerpot = timerinit()
    EndIf
    endif
    
    




endfunc
;===============Attack.=================
Func Attack()
ToolTip(" GuiBot Runing. {PAUSE} To Pause. {END} To Quit.", 0, 0,"",0,4) 
        Sleep(100 + Random(1, 300)) 
    ControlSend($GameTitle, "", "", "{TAB}")
        sleep(500)
    ControlSend($GameTitle, "", "", "{f1}")
        Sleep(4500)
    ControlSend($GameTitle, "", "", "{f2}")     
        If $minimized = True Then
    Sleep($MonsterKill * 1000)
EndIf
    If $minimized = False Then  
        $timeratak = TimerInit()
        While 1
        $var = PixelGetColor( 413,59 )
            if timerdiff($timeratak) > 20000 Then
                ExitLoop
                EndIf
            if $var = 2170913 Then
                Sleep(1500)
                ExitLoop
            EndIf
        WEnd
        EndIf
EndFunc 

;=================Buffs 1-3=======
Func buff1()
    if timerdiff($timer1) > $BuffTimer1 * 1000 then
ControlSend($GameTitle, "", "", "{f5}")
$timer1 = timerinit()
Sleep(2200)
EndIf
EndFunc

Func buff2()
    if timerdiff($timer2) > $BuffTimer2 * 1000 then
ControlSend($GameTitle, "", "", "{f6}")
$timer2 = timerinit()
Sleep(2200)
EndIf
EndFunc

Func buff3()
    if timerdiff($timer3) > $BuffTimer3 * 1000 then
ControlSend($GameTitle, "", "", "{f7}")
$timer3 = timerinit()
Sleep(2200)
EndIf
EndFunc
    
;===========USE POTION
Func potion()
    
    if timerdiff($timerpot) > $pottimer * 1000 then
ControlSend($GameTitle, "", "", "{f8}")
$timerpot = timerinit()
EndIf
EndFunc 
    
;================Rebuff======
Func Rebuff()
    If $BuffTimer1 > 1 Then
        Call ("buff1")
    EndIf
    If $BuffTimer2 > 1 Then
        Call ("buff2")
    EndIf
    If $BuffTimer3 > 1 Then
        Call ("buff3")
    EndIf
    If $pottimer > 1 Then
        Call("potion")
    EndIf
EndFunc
        
;================START AUTOBUFF=======
Func Autobuff() 
    $UnBuff = NOT $UnBuff
call ("Prebuff") 
While $UnBuff
call ("Rebuff")
Call("Pickup")
wend
endfunc

;==================PICKUP ItEMS======
Func Pickup()
    $var = PixelGetColor( 22,95 ) ;====pixel that recognizes a party
If $var <> 16777215 Then ;====if pixel not there...then ACTION!
ControlSend($GameTitle, "", "", "{f9}")
sleep(500)
ControlSend($GameTitle, "", "", "{f9}")
sleep(500)
ControlSend($GameTitle, "", "", "{f9}")
sleep(500)
Else 
    EndIf
endfunc

;=============BOTLOOP==============
Func Botloop()
    
    
    ;If $runb Then

call("Prebuff")
$prebuffed = false




;While 1
        If $minimized = False Then
            WinMove("Archlord", "", 0, 0)
            EndIf
call ("Attack")
call("Pickup") 
call ("Rebuff")
ControlSend($GameTitle, "", "", "{space}")
Call("reload")

If $usepotion = True Then 
    Call ("potion")
EndIf
;WEnd


;endif
endfunc

;===========IF WINDOW DONT EXIST, RESTART!=======
Func reload()
    If WinExists($GameTitle) = False Then
    Call("Restart")
EndIf
EndFunc
    
    
;===============RESTART AL==============
Func Restart()
    ToolTip("Executing Archlord.exe", 0, 0,"",0,4) 
Run ("C:\Program Files\Codemasters\Archlord\Archlord.exe")

Sleep(1800)
WinWaitActive("Archlord Patch Client")
$state = WinGetState("Archlord Patch Client")
WinMove("Archlord Patch Client", "", 0, 0)
Sleep(5000)
MouseMove(516,297)
Sleep(500)
MouseClick("left")
WinWaitActive("Archlord")
Sleep(1500)
$state = WinGetState("Archlord")
WinMove("Archlord", "", 0, 0)
$timerrestart = TimerInit()
While 1
    $var = PixelGetColor( 519,558 )
    If $var = 16773036 Then 
ExitLoop        
    EndIf
    Sleep(100)
    WEnd
    ToolTip("Clicking on User ID.", 0, 0,"",0,4)
Sleep(1500) 
Send($account)
Sleep(500)
    ToolTip("Clicking on Password.", 0, 0,"",0,4) 
    ControlSend($GameTitle, "", "", "{TAB}")
Sleep(500)
Send($password)
Sleep(500)
    ToolTip("Id and password entered, Loging in!", 0, 0,"",0,4) 
Send("{ENTER}")

While 1
    $var = PixelGetColor( 596,581 );===choose server pixel
    If $var = 3223601 Then
ExitLoop
EndIf
    if timerdiff($timerrestart) > 240 * 1000 then
        Call("Restart")
        ExitLoop
    EndIf
    WEnd
Sleep(1500)
    ToolTip("Choosing Server!!", 0, 0,"",0,4) 
MouseMove(432,406)
MouseClick("left")
Sleep(500)
MouseClick("left")
Sleep(500)
MouseClick("left")
    ToolTip("Pick your character!", 0, 0,"",0,4) 
While 1
    ToolTip("Looking for char", 0, 0,"",0,4) 
    $var = PixelGetColor( 842,361 )
    If $var = 10910573 Then
        ToolTip("FOUND PIXEL!", 0, 0,"",0,4)
ExitLoop        
    EndIf
    Sleep(100)
    WEnd
    ToolTip("Mouse Moving", 0, 0,"",0,4) 
MouseMove(505,624)
MouseClick("left")
Sleep(500)
MouseClick("left")
Sleep(500)
    ToolTip("Clicking Connection.", 0, 0,"",0,4) 
MouseMove(933,684)
MouseClick("left")
Sleep(500)
MouseClick("left")
$var = PixelGetColor( 65,766 )
While 1
    ToolTip("(LOADING SCREEN) Waiting to enter the world.", 0, 0,"",0,4)
    $var = PixelGetColor( 65,766 )
    If $var = 6512219 Then
        ToolTip("WE ARE IN! SUCESS...GUI RULES", 0, 0,"",0,4)
ExitLoop        
    EndIf
    Sleep(100)
    WEnd
Call("Prebuff")
Call("Botloop")
EndFunc
;===============START BOT & PAUSE and UNPAUSE=======
Func TogglePause() 
    $Paused = NOT $Paused 

If $Paused = True Then
    $lvlup = True
    Call("Start")
    EndIf


If $Paused = False Then 
    $lvlup = False
    Call ("Prebuff")
    call ("Botloop")
    ControlSend($GameTitle, "", "", "{f10}")
EndIf

;If $prebuffed = False Then 
;Call ("Prebuff")
;EndIf



Endfunc

;======Function that starts the bot
Func StartB()
;$Paused = True
;Call("TogglePause")
    $runb = True
;call("Botloop")
EndFunc
;====Function that stops the bot
Func StopB()
    $Paused = False
    $runb = false
;ToolTip("  GuiBot is Paused. For options press {INSERT}  Press {Pause} To start Guibot ", 0, 0,"",0,4) 
;Call("TogglePause")
EndFunc

;=====FUNCTION THAT EXITS BOT===========
Func Terminate() 
    Exit 0 
EndFunc

;=======testthingy

Share this post


Link to post
Share on other sites
Tvern

Better remove your accountname and password from the script ^^

Share this post


Link to post
Share on other sites
BlackDragonBE

I hope that isn't your real login and password... :D

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.