Jump to content

Starting a AU3 script from within an AU3 script.


Recommended Posts

If you #include a script into your main script the non-functioned (not put into functions) code will execute at the time of the call. Example:

main.AU3

If Not @compiled then
   #include "include.au3"
endif

include.au3

msgbox(0,"", "This script it not compiled!")

It is a simple example but I believe it works.

*** Matt @ MPCS

Link to comment
Share on other sites

CSS Multi-Launch.au3:

#include "Window Movement and Resize.au3"
#include "Burst Fire.au3"
#include "Throw Grenade.au3"

Burst Fire.au3:

$keywait = 150

Opt("WinTitleMatchMode", 3)
Opt("SendKeyDelay", 0)

$window_name = "Counter-Strike Source"
$hotkey1 = "01";Left mouse button
$hotkey2 = "{TAB}"
$burst_active = 0
$burstfireon = 0
$rounds = 0
$rest = 5

HotKeySet($hotkey2, "ToggleBurstFire")

While (1)
    If ((_IsPressed($hotkey1) = 1) AND WinActive($window_name) AND $burstfireon) Then
        FireBurst()
    EndIf
    Sleep ($rest)
WEnd

Func FireBurst()
    If ($burstfireon = 3) Then
        $rounds = 3
        $keywait = 150
    Else
        $rounds = 10
        $keywait = 250
    EndIf

    For $i = 0 To ($rounds - 2) Step 1
        Sleep($keywait)
        Send("{LCTRL}")
    Next

    If (WinActive($window_name)) Then
        Send("{F11}")
        Sleep($keywait)
    EndIf
EndFunc

Func ToggleBurstFire()
    Select
            Case $burstfireon = 0
            $burstfireon = 3
           Case $burstfireon = 3
            $burstfireon = 10
            Case Else
            $burstfireon = 0
    EndSelect

    HotKeySet($hotkey2)
    Send($hotkey2)
    HotKeySet($hotkey2, "ToggleBurstFire")
EndFunc
    






; ezzetabi's _IsPressed function
Func _IsPressed($hexKey)
; $hexKey must be the value of one of the keys.
; _IsPressed will return 0 if the key is not pressed, 1 if it is.
  
  Local $aR, $bRv;$hexKey
  $hexKey = '0x' & $hexKey
  $aR = DllCall("user32", "int", "GetAsyncKeyState", "int", $hexKey)
;If $aR[0] = -32767 Then
  If $aR[0] <> 0 Then
     $bRv = 1
  Else
     $bRv = 0
  EndIf
  
  Return $bRv
EndFunc;==>_IsPressed

Throw Grenade.au3:

Opt("WinTitleMatchMode", 3)

$window_name = "Counter-Strike Source"
$throw_hotkey = "{F1}"
$throw_active = 0
$rest = 10

HotKeySet($throw_hotkey, "Toss")

while (1)
    Sleep(2147483647)
WEnd

Func Toss()
    If (WinActive($window_name) AND ($throw_active == 0)) Then
        $throw_active = 1
        Send("4")
        Sleep($rest)
        Send("{LCTRL}")
        Sleep(700)
        Send("{LCTRL}")
        $throw_active = 0
    Else
        HotKeySet($throw_hotkey)
        Send($throw_hotkey)
        HotKeySet($throw_hotkey, "Toss")
    EndIf
EndFunc

Window Movement and Resize.au3:

#include <GUIConstants.au3>

Opt("WinTitleMatchMode", 3)

Global $GWL_STYLE = -16
$window_name = "Counter-Strike Source"
$hidden = 0
$window_hotkey = "!q"

HotKeySet($window_hotkey, "ToggleWindowHide")

; Move the Window into postion
WinMove($window_name, "", 0, 0, 1024, 768)
;WinMove($window_name, "", -3, -29)

RemoveWindowBorders()
; Wait for hotkey input
while (1)
    Sleep (2147483647)
WEnd

; Hides/Unhides window
Func ToggleWindowHide()
    If ($hidden) Then
        WinMove($window_name, "", 0, 0)
    Else    
        WinMove($window_name, "", -5000, -5000)
    EndIf
    $hidden = NOT $hidden
EndFunc

;Remove the window borders
Func RemoveWindowBorders()
    $hWnd = WinGetHandle($window_name)

    $OldStyle = DLLCall( "user32.dll", "long", "GetWindowLong", "hwnd", $hWnd, "int", $GWL_STYLE )
    If @error Then Exit
    $OldStyle = $OldStyle[0]

    $NewStyle = BitAND($OldStyle,BitNOT($WS_DLGFRAME) )
    $NewStyle = BitAND($NewStyle,BitNOT($WS_THICKFRAME) )
    $NewStyle = BitAND($NewStyle,BitNOT($WS_BORDER) )

    DLLCall( "user32.dll", "long", "SetWindowLong", "hwnd", $hWnd, "int", $GWL_STYLE, "long", $NewStyle )
EndFunc
Edited by Christopher Blue
Link to comment
Share on other sites

From what I can tell it never makes it to the second script. I can't test it because I don't have counter-strike, but logically reading through your code... it gets stuck on the inifinite while loop in the first script included.

*** Matt @ MPCS

Link to comment
Share on other sites

include will not work for independently whole scripts. You will need to run them... compile them to run them all at once. Also, I noticed the long Sleep()... no good... make it short like 100

Lar.

<{POST_SNAPBACK}>

^^^^ This is god's word on the topic ^^^^
Link to comment
Share on other sites

Larry, what is the difference between using a long sleep and infinitely looping a short sleep?

<{POST_SNAPBACK}>

If you have a long sleep, your script will not pick up the hotkeys you are looking for. This actually holds the script from any input. I think that is right, Larry can verify.

*** Matt @ MPCS

Link to comment
Share on other sites

Running multiple AutoIt scripts from AutoIt requires that I compile the scripts which complicates the coding process since I have to remember to compile after each new change.

Using a simple batch file can do the job but the popup command window it makes is annoying.

However, I have been able to create a solution using WSH that fits my needs:

CSS Multi-Launch.vbs:

set Wshshell= WScript.createobject("wscript.shell")
Wshshell.Run(chr(34) + WshShell.CurrentDirectory + "\Burst Fire.au3" + chr(34))
Wshshell.Run(chr(34) + WshShell.CurrentDirectory + "\Throw Grenade.au3" + chr(34))
Wshshell.Run(chr(34) + WshShell.CurrentDirectory + "\Window Movement and Resize.au3" + chr(34))

This will work until AutoIt3 supports running non .exe programs.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...