Jump to content
Sign in to follow this  
Rydextillxixdiex

GUI Button Function Codeing

Recommended Posts

Rydextillxixdiex

I have created a GUI with 4 Buttons in a Pop Up Window to my likeing, and depending on which button you press i need it "Replace" Attack() in the script with a specified function, designed specifically for each button.

The idea is that the Func Start() script is still there, however depending on which button is pressed when the script reaches the attack() step will have a different function to call.

I want the script to start running, ask for your input, and then replace "Attack()" with 1 of four choices depending on the button that was pressed.

My GUI script is present i just need to know how to assign each button to a variable and then to tell the Start() Function which Attack() function to pick depending on the users input.

The full script is as follows so you can get an idea of what exactly i am talking about:

HotKeySet("{F9}", "Start")
HotKeySet("{F10}", "Stop")
AutoItSetOption("WinTitleMatchMode", 4)
Global $handle = WinGetHandle("classname=GxWindowClassD3d")
   WinSetState($handle, "", @SW_SHOW)
   WinSetState($handle, "", @SW_SHOWMAXIMIZED)
While 1
    Sleep(1000)
WEnd
;============================================
    Func start()
    While 1     
        Global $show = 0
        Global $Join = 0x6a0706
        Global $Enter = 0xEE1400
        BgGUI()
        Join()
        Sleep(5000)
        Enter()
        Sleep(5000)
        Attack()
        If $show > 0 then ExitLoop
      WEnd
    EndFunc
;===========================================    
    Func BgGUI()
    #include <GUIConstants.au3>

#Region ### START Koda GUI section ### Form=c:\users\brandon\desktop\autoit\queueing bgbot\gui\battle ground selector.kxf
$Form1_1 = GUICreate("Battle Ground Selector", 471, 101, -1, -1)
GUISetBkColor(0x0000FF)
$WSG = GUICtrlCreateButton("Warsong Gulch", 8, 32, 110, 40, 0)
GUICtrlSetFont(-1, 8, 400, 0, "Verdana")
$AV = GUICtrlCreateButton("Alterac Valley", 122, 32, 110, 40, 0)
GUICtrlSetFont(-1, 8, 400, 0, "Verdana")
$AB = GUICtrlCreateButton("Arathi Basin", 237, 32, 110, 40, 0)
GUICtrlSetFont(-1, 8, 400, 0, "Verdana")
$EOTS = GUICtrlCreateButton("Eye of the Storm", 351, 32, 110, 40, 0)
GUICtrlSetFont(-1, 8, 400, 0, "Verdana")
$Bottom = GUICtrlCreateLabel("World of Warcraft Battleground Automation Bot", 120, 80, 226, 17)
$Title = GUICtrlCreateLabel("Select Which Battleground You Wish to Enter:", 80, 8, 298, 19)
GUICtrlSetFont(-1, 8, 800, 0, "MS Reference Sans Serif")
GUICtrlSetColor(-1, 0x800000)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $Form1_1
        Case $Form1_1
        Case $Form1_1
        Case $Form1_1
        Case $WSG
        Case $AV
        Case $AB
        Case $EOTS
        Case $Bottom
        Case $Title
    EndSwitch
WEnd
EndFunc
;============================================
    Func Join()
        MouseClick("Right", 652, 421, 1, 0)
        Sleep(5000)
        $Coords = PixelSearch(180, 510, 328, 550, $Join, 10)
        If isArray($Coords) then
        MouseClick("Left",$Coords[0], $Coords[1],1,1)
        EndIf
    EndFunc
;========================================== 
    Func Enter()
        $boolean = 0
        While $boolean = 0
        $Coords = PixelSearch(472, 192, 640, 222, $Enter, 2)
        Sleep(2000)
        $boolean = isArray($Coords)
        WEnd
        MouseClick("Left",$Coords[0], $Coords[1],1,1)
    EndFunc
    
;=========================================

Func Attack1()
    EndFunc
        
Func Attack2()
    EndFunc

Func Attack3()
    EndFunc
    
Func Attack4()
    EndFunc
    
;========================================
    
    Func stop()
        Global $show = 1
        WinSetState("World of Warcraft", "", @SW_SHOW)
        WinSetState("World of Warcraft", "", @SW_MAXIMIZE)
        WinActivate($handle, "")
    EndFunc

Thanks for anyone who can give me a hand.


...will never learn all there is to know about autoit, no worries...i came to the forums :)

Share this post


Link to post
Share on other sites
Valuater

This is about as far as I can go this will work for the GUI

#include <GUIConstants.au3>

AutoItSetOption("WinTitleMatchMode", 4)

Global $handle = WinGetHandle("classname=GxWindowClassD3d")
Global $show = 0, $Join = 0x6a0706, $Enter = 0xEE1400

HotKeySet("{F9}", "Start")
HotKeySet("{F10}", "Stop")

#Region ### START Koda GUI section ### Form=c:\users\brandon\desktop\autoit\queueing bgbot\gui\battle ground selector.kxf
$Form1_1 = GUICreate("Battle Ground Selector", 471, 101, -1, -1)
GUISetBkColor(0x0000FF)
$WSG = GUICtrlCreateButton("Warsong Gulch", 8, 32, 110, 40, 0)
GUICtrlSetFont(-1, 8, 400, 0, "Verdana")
$AV = GUICtrlCreateButton("Alterac Valley", 122, 32, 110, 40, 0)
GUICtrlSetFont(-1, 8, 400, 0, "Verdana")
$AB = GUICtrlCreateButton("Arathi Basin", 237, 32, 110, 40, 0)
GUICtrlSetFont(-1, 8, 400, 0, "Verdana")
$EOTS = GUICtrlCreateButton("Eye of the Storm", 351, 32, 110, 40, 0)
GUICtrlSetFont(-1, 8, 400, 0, "Verdana")
$Bottom = GUICtrlCreateLabel("World of Warcraft Battleground Automation Bot", 120, 80, 226, 17)
$Title = GUICtrlCreateLabel("Select Which Battleground You Wish to Enter:", 80, 8, 298, 19)
GUICtrlSetFont(-1, 8, 800, 0, "MS Reference Sans Serif")
GUICtrlSetColor(-1, 0x800000)
GUISetState(@SW_HIDE)
#EndRegion ### END Koda GUI section ###

While 1
    Sleep(20)
WEnd


Func Big_GUI()
    GUISetState(@SW_SHOW, $Form1_1)

    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $WSG
                Attack1()
                ; ExitLoop ;?????
            Case $AV
                Attack2()
            Case $AB
                Attack3()
            Case $EOTS
                Attack4()
            Case $Bottom
            Case $Title
        EndSwitch
    WEnd
    GUISetState(@SW_HIDE, $Form1_1)
EndFunc   ;==>Big_GUI
;============================================
Func start()
    WinSetState($handle, "", @SW_SHOW)
    WinSetState($handle, "", @SW_SHOWMAXIMIZED)
    Big_GUI()
    While 1
        $show = 0
        Join()
        Sleep(5000)
        Enter()
        Sleep(5000)
        Attack1()
        If $show > 0 Then ExitLoop
    WEnd
EndFunc   ;==>start

;============================================
Func Join()
    MouseClick("Right", 652, 421, 1, 0)
    Sleep(5000)
    $Coords = PixelSearch(180, 510, 328, 550, $Join, 10)
    If IsArray($Coords) Then
        MouseClick("Left", $Coords[0], $Coords[1], 1, 1)
    EndIf
EndFunc   ;==>Join

;==========================================
Func Enter()
    $boolean = 0
    While $boolean = 0
        $Coords = PixelSearch(472, 192, 640, 222, $Enter, 2)
        Sleep(2000)
        $boolean = IsArray($Coords)
    WEnd
    MouseClick("Left", $Coords[0], $Coords[1], 1, 1)
EndFunc   ;==>Enter

;=========================================

Func Attack1()
    MsgBox(0x0, "Attack", "Attacking Warsong Gulch", 3)
EndFunc   ;==>Attack1

Func Attack2()
    MsgBox(0x0, "Attack", "Attacking Alterac Valley", 3)
EndFunc   ;==>Attack2

Func Attack3()
    MsgBox(0x0, "Attack", "Attacking Arathi Basin", 3)
EndFunc   ;==>Attack3

Func Attack4()
    MsgBox(0x0, "Attack", "Attacking Eye of the Storm", 3)
EndFunc   ;==>Attack4

;========================================

Func stop()
    Global $show = 1
    WinSetState("World of Warcraft", "", @SW_SHOW)
    WinSetState("World of Warcraft", "", @SW_MAXIMIZE)
    WinActivate($handle, "")
EndFunc   ;==>stop

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites
Rydextillxixdiex

Thanks didn't realize the simplicity of just addding the call function.

Now is it possible to add another line to where the Attack() in "Start" will equal "Attack1()" if the First button is pressed, "attack2()" if the second button is pressed...etc?


...will never learn all there is to know about autoit, no worries...i came to the forums :)

Share this post


Link to post
Share on other sites
Valuater

Use Call()... I only did it for the first button

#include <GUIConstants.au3>

AutoItSetOption("WinTitleMatchMode", 4)

Global $handle = WinGetHandle("classname=GxWindowClassD3d")
Global $show = 0, $Join = 0x6a0706, $Enter = 0xEE1400, $Killer = ""

HotKeySet("{F9}", "Start")
HotKeySet("{F10}", "Stop")

#Region ### START Koda GUI section ### Form=c:\users\brandon\desktop\autoit\queueing bgbot\gui\battle ground selector.kxf
$Form1_1 = GUICreate("Battle Ground Selector", 471, 101, -1, -1)
GUISetBkColor(0x0000FF)
$WSG = GUICtrlCreateButton("Warsong Gulch", 8, 32, 110, 40, 0)
GUICtrlSetFont(-1, 8, 400, 0, "Verdana")
$AV = GUICtrlCreateButton("Alterac Valley", 122, 32, 110, 40, 0)
GUICtrlSetFont(-1, 8, 400, 0, "Verdana")
$AB = GUICtrlCreateButton("Arathi Basin", 237, 32, 110, 40, 0)
GUICtrlSetFont(-1, 8, 400, 0, "Verdana")
$EOTS = GUICtrlCreateButton("Eye of the Storm", 351, 32, 110, 40, 0)
GUICtrlSetFont(-1, 8, 400, 0, "Verdana")
$Bottom = GUICtrlCreateLabel("World of Warcraft Battleground Automation Bot", 120, 80, 226, 17)
$Title = GUICtrlCreateLabel("Select Which Battleground You Wish to Enter:", 80, 8, 298, 19)
GUICtrlSetFont(-1, 8, 800, 0, "MS Reference Sans Serif")
GUICtrlSetColor(-1, 0x800000)
GUISetState(@SW_HIDE)
#EndRegion ### END Koda GUI section ###

While 1
    Sleep(20)
WEnd


Func Big_GUI()
    GUISetState(@SW_SHOW, $Form1_1)

    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $WSG
                GUISetState(@SW_HIDE, $Form1_1)
                $Killer = Attack1()
                ExitLoop ;?????
            Case $AV
                Attack2()
            Case $AB
                Attack3()
            Case $EOTS
                Attack4()
            Case $Bottom
            Case $Title
        EndSwitch
    WEnd
    GUISetState(@SW_HIDE, $Form1_1)
EndFunc   ;==>Big_GUI
;============================================
Func start()
    WinSetState($handle, "", @SW_SHOW)
    WinSetState($handle, "", @SW_SHOWMAXIMIZED)
    Big_GUI()
    While 1
        $show = 0
        Join()
        Sleep(5000)
        Enter()
        Sleep(5000)
        Call($Killer)
        If $show > 0 Then ExitLoop
    WEnd
EndFunc   ;==>start

;============================================
Func Join()
    MouseClick("Right", 652, 421, 1, 0)
    Sleep(5000)
    $Coords = PixelSearch(180, 510, 328, 550, $Join, 10)
    If IsArray($Coords) Then
        MouseClick("Left", $Coords[0], $Coords[1], 1, 1)
    EndIf
EndFunc   ;==>Join

;==========================================
Func Enter()
    $boolean = 0
    While $boolean = 0
        $Coords = PixelSearch(472, 192, 640, 222, $Enter, 2)
        Sleep(2000)
        $boolean = IsArray($Coords)
    WEnd
    MouseClick("Left", $Coords[0], $Coords[1], 1, 1)
EndFunc   ;==>Enter

;=========================================

Func Attack1()
    MsgBox(0x0, "Attack", "Attacking Warsong Gulch", 3)
EndFunc   ;==>Attack1

Func Attack2()
    MsgBox(0x0, "Attack", "Attacking Alterac Valley", 3)
EndFunc   ;==>Attack2

Func Attack3()
    MsgBox(0x0, "Attack", "Attacking Arathi Basin", 3)
EndFunc   ;==>Attack3

Func Attack4()
    MsgBox(0x0, "Attack", "Attacking Eye of the Storm", 3)
EndFunc   ;==>Attack4

;========================================

Func stop()
    Global $show = 1
    WinSetState("World of Warcraft", "", @SW_SHOW)
    WinSetState("World of Warcraft", "", @SW_MAXIMIZE)
    WinActivate($handle, "")
EndFunc   ;==>stop

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites
Rydextillxixdiex

Thanks, i have been struggling to make my auto it script for a few months now, then it occurred to me, Auto it Forums! And you as well as a few other users have been of great help to me, i appreciate it :)


...will never learn all there is to know about autoit, no worries...i came to the forums :)

Share this post


Link to post
Share on other sites
Valuater

Thanks, i have been struggling to make my auto it script for a few months now, then it occurred to me, Auto it Forums! And you as well as a few other users have been of great help to me, i appreciate it :)

Welcome!

8)


NEWHeader1.png

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  

×