ParoXsitiC Posted July 26, 2006 Share Posted July 26, 2006 First off I havent done much searching on the forum to see if this problem has been answered, because not only do I need help with the GUI, but also my code could be optimized and improved as well. Any lurkers who think to themselfs "Why is he doing it that way?" please comment and help me improve myself. This script will open a GUI and set events for the close, minimized buttons to do my own functions, I also set events for the Start button and Add player button to do their own functions as well. Once the user clicks the start button the GUI is hidden and the script starts in an endless search for something on the webpage. The user can bring the gui back up by primary double clicking the trayicon and the GUI shows itself again. My problem is that once the GUI is shown again, the close, minimize, start or addplayer buttons do not do their user functions. The only button that halfway works is minimize and it does the windows default. expandcollapse popup#include <Constants.au3> #include <IE.au3> #include <Array.au3> #include <File.au3.> #Include <GuiList.au3> #include <GUIConstants.au3> Opt("GUIOnEventMode", 1) Opt("TrayOnEventMode", 1) Opt("TrayMenuMode", 1) ;TraySetIcon("error") TraySetToolTip("Auto Assaulter") TraySetClick(16) $TrayShow = TrayCreateItem("Show Window") TrayItemSetOnEvent(-1, "Show") TrayCreateItem("Contact ParoXsitiC") TrayItemSetOnEvent(-1, "About") TrayCreateItem("") TrayCreateItem("Exit") TrayItemSetOnEvent(-1, "Quit") TraySetOnEvent($TRAY_EVENT_PRIMARYDOUBLE, "PrimaryDouble") Global $Version = "2.0" Global $PlayersFile = @AppDataDir & "\AutoAssault\Players.txt" Global $UsersFile = @AppDataDir & "\AutoAssault\Users.ini" Global $PlayerArray Global $Que[1] Global $OnlinePlayers[1] Global $o_IE If Not FileExists(@AppDataDir & "\AutoAssault\") Then DirCreate(@AppDataDir & "\AutoAssault\") $Form = GUICreate("Auto Assaulter " & $Version, 400, 175, 306, 190) GUICtrlCreateLabel("Auto Assaulter " & $Version, 16, 24, 184, 20) GUICtrlSetFont(-1, 12, 800, 0, "Courier") GUICtrlCreateLabel("created by: ParoXsitiC", 16, 44, 180, 17) GUICtrlSetFont(-1, 10, 400, 0, "Courier") GUICtrlCreateLabel("Players to be invited if online:", 220, 8, 200, 15) $PlayerList = GUICtrlCreateList("", 220, 24, 160, 97, -1, $WS_EX_CLIENTEDGE) $PlayerInput = GUICtrlCreateInput("", 220, 137, 160, 21, -1, $WS_EX_CLIENTEDGE) $PlayerButton = GUICtrlCreateButton("^ Add player ^", 220, 110, 160, 25) GUICtrlCreateLabel("Password:", 11, 114, 53, 17) GUICtrlCreateLabel("Username:", 9, 91, 55, 13) $UsernameGUI = GUICtrlCreateInput("", 68, 87, 140, 21, -1, $WS_EX_CLIENTEDGE) $PasswordGUI = GUICtrlCreateInput("", 68, 112, 140, 21, -1, $WS_EX_CLIENTEDGE) $StartGUI = GUICtrlCreateButton("Start", 68, 135, 140, 25) LoadFormInfo() GUICtrlSetOnEvent($PlayerButton, "PlayerButton") GUICtrlSetOnEvent($StartGUI, "StartGUI") GUISetOnEvent($GUI_EVENT_CLOSE, "Quit") GUISetOnEvent($GUI_EVENT_MINIMIZE, "Minimize") GUICtrlSetState($StartGUI, $GUI_FOCUS) GUISetState(@SW_SHOW) $o_IE = _IECreate ("about:blank", 0, 0, 0) While 1 Sleep(1000) WEnd Func PrimaryDouble() GUICtrlSetOnEvent($StartGUI, "Minimize") GUISetState(@SW_SHOW) EndFunc ;==>PrimaryDouble Func StartGUI() Minimize() If CheckLogin() Then SavePlayerList() TraySetToolTip("Auto Assaulter - Searching") StartRefresh() EndIf EndFunc ;==>StartGUI Func PlayerButton() If GUICtrlRead($PlayerInput) <> "" Then GUICtrlSetData($PlayerList, GUICtrlRead($PlayerInput)) _GUICtrlListSelectString ($PlayerList, GUICtrlRead($PlayerInput)) GUICtrlSetData($PlayerInput, "") EndIf EndFunc ;==>PlayerButton Func DeleteItem() Local $SelectedIndex = _GUICtrlListSelectedIndex ($PlayerList) If $SelectedIndex <> - 1 Then _GUICtrlListDeleteItem ($PlayerList, $SelectedIndex) _GUICtrlListSelectIndex ($PlayerList, $SelectedIndex) EndIf EndFunc ;==>DeleteItem Func LoadFormInfo() Local $Username = IniRead($UsersFile, "LastUser", "Username", "") Local $Password = IniRead($UsersFile, "LastUser", "Password", "") If _FileReadToArray($PlayersFile, $PlayerArray) Then _ArrayDelete($PlayerArray, 0) If $PlayerArray[0] = "" Then DownloadFiles() Else DownloadFiles() EndIf For $Player In $PlayerArray If $Player <> "" Then GUICtrlSetData($PlayerList, $Player) Next HotKeySet("{DEL}", "DeleteItem") GUICtrlSetData($UsernameGUI, $Username) GUICtrlSetData($PasswordGUI, $Password) EndFunc ;==>LoadFormInfo Func DownloadFiles() If Not FileExists($UsersFile) Then InetGet("http://urbaniacs.50webs.com/Users.ini", $UsersFile, 1) InetGet("http://urbaniacs.50webs.com/Players.txt", $PlayersFile, 1) LoadFormInfo() EndFunc ;==>DownloadFiles Func StartRefresh() While 1 _IENavigate ($o_IE, "http://www.urbaniacs.com/") Local $HTMLSource = _IEBodyReadHTML ($o_IE) ExtractPlayers($HTMLSource) If StringRegExp($HTMLSource, "or enter an Alter Ego...", 0) Then FoundAssault() EndIf WEnd _ArrayDelete($Que, 0) EndFunc ;==>StartRefresh Func ExtractPlayers(ByRef $HTML) Local $Players = StringRegExp($HTML, "last_player_seen href=""http://profiles.urbaniacs.com/(.*?)"">", 3) For $Player In $Players _ArraySearch ($Que, $Player) If @error Then _ArrayAdd($Que, $Player) Next EndFunc ;==>ExtractPlayers Func FoundAssault() HotKeySet("+Q", "StartAssault") HotKeySet("+W", "LookForPlayers") FilterGoodPlayers() _ArrayDelete($OnlinePlayers, 0) $MsgboxString = "" $MsgboxString = ListOnlinePlayers() $MsgboxString = $MsgboxString & @CR & @CR & "Press Shift+Q to battle now" & @CR & "Press Shift+W to look for more players" While 1 TrayTip("Assault found", $MsgboxString, 10) Sleep(8000) WEnd EndFunc ;==>FoundAssault Func FilterGoodPlayers($StartIndex = 0) For $i = $StartIndex To UBound($Que) - 1 _ArraySearch ($PlayerArray, $Que[$i]) If Not @error Then _ArrayAdd($OnlinePlayers, $Que[$i]) Next EndFunc ;==>FilterGoodPlayers Func StartAssault() HotKeySet("+Q") HotKeySet("+W") TrayTip("Loading", "Inviting players...", 10) $o_IE2 = _IECreate ("http://www.urbaniacs.com/", 0, 0) If Not StringRegExp(_IEBodyReadHTML ($o_IE2), "or enter an Alter Ego...", 0) Then TrayTip("Error", "Searching for assault again", 10) Sleep(2000) TrayTip("CLEAR", "", 0) StartRefresh() EndIf $o_form = _IEFormGetObjByName ($o_IE2, "assault_form") $o_invite = _IEFormElementGetObjByName ($o_form, "assault_invite_list_other") $o_button = _IEGetButtonObj($o_IE2, "assault_invite_button") For $Player In $OnlinePlayers _IEFormElementSetValue ($o_invite, $Player) $o_button.click Next _IEFormElementSetValue ($o_invite, "paroxsitic") $o_button.click TrayTip("CLEAR", "", 0) WinSetState(_IEPropertyGet ($o_IE2, "hwnd"), "", @SW_MAXIMIZE) ;_IEAction($o_IE2,"visible") Sleep(30000) TrayTip("Continuing", "Search for assault", 10) Sleep(2000) TrayTip("CLEAR", "", 0) StartRefresh() EndFunc ;==>StartAssault Func LookForPlayers() HotKeySet("+Q", "StartAssault") While 1 $MsgboxString = "" $Index = UBound($Que) _IENavigate ($o_IE, "http://www.urbaniacs.com/") Local $HTMLSource = _IEBodyReadHTML ($o_IE) ExtractPlayers($HTMLSource) FilterGoodPlayers($Index) $MsgboxString = ListOnlinePlayers() $MsgboxString = $MsgboxString & @CR & @CR & "Press Shift+Q to battle now" TrayTip("Searching...", $MsgboxString, 10) WEnd EndFunc ;==>LookForPlayers Func ListOnlinePlayers() Local $MSG = "Players online:" & @CR For $Player In $OnlinePlayers $MSG = $MSG & " " & $Player & @CR Next Return $MSG EndFunc ;==>ListOnlinePlayers Func Quit() SavePlayerList() Exit EndFunc ;==>Quit Func Show() If TrayItemGetText($TrayShow) = "Show Window" Then ;_IEAction ($o_IE, "visible") WinSetState(_IEPropertyGet ($o_IE, "hwnd"), "", @SW_MAXIMIZE) TrayItemSetText($TrayShow, "Hide Window") Else _IEAction ($o_IE, "invisible") TrayItemSetText($TrayShow, "Show Window") EndIf EndFunc ;==>Show Func SavePlayerList() $File = FileOpen($PlayersFile, 2) For $x = 0 To _GUICtrlListCount ($PlayerList) - 1 FileWriteLine($File, _GUICtrlListGetText ($PlayerList, $x)) Next FileClose($File) _FileReadToArray($PlayersFile, $PlayerArray) _ArrayDelete($PlayerArray, 0) EndFunc ;==>SavePlayerList Func CheckLogin() Local $Username = GUICtrlRead($UsernameGUI) Local $Password = GUICtrlRead($PasswordGUI) If $Username = "" Then GUISetState(@SW_SHOW) MsgBox(0, "Username Error", "Please insert a username") Return 0 EndIf If $Password = "" Then GUISetState(@SW_SHOW) MsgBox(0, "Password Error", "Please insert a password") Return 0 EndIf TrayTip("Auto Assaulter " & $Version, "Searching in progress", 1, 1) _IENavigate ($o_IE, "http://urbaniacs.freehostia.com/autologin.html?user=" & $Username & "&pass=" & $Password) If StringRegExp(_IEBodyReadHTML ($o_IE), "Login Error", 0) Then GUISetState(@SW_SHOW) MsgBox(0, "Login Error", "Please check your username and password") Return 0 EndIf IniWrite($UsersFile, "LastUser", "Username", $Username) IniWrite($UsersFile, "LastUser", "Password", $Password) TrayTip("CLEAR", "", 0) Return 1 EndFunc ;==>CheckLogin Func Minimize() GUISetState(@SW_HIDE) EndFunc ;==>Minimize Func About() MsgBox(0, "ParoXsitiC", "Urbaniacs: http://profiles.urbaniacs.com/paroxsitic" & @CR & "AIM: bharesupport" & @CR & "Yahoo: paroxsitic_x" & @CR & "MSN: paroxsitic@gmail.com" & @CR & "Email: paroxsitic@gmail.com") EndFunc ;==>About Func _IEGetButtonObj(ByRef $o_object, $s_linkText) Local $button, $buttons Local $oTemp = _IEDocGetObj ($o_object) $buttons = _IETagNameGetCollection ($oTemp, "input") For $button In $buttons If StringInStr($button.name, $s_linkText) Then Return $button EndIf Next EndFunc ;==>_IEGetButtonObj Link to comment Share on other sites More sharing options...
ParoXsitiC Posted July 26, 2006 Author Share Posted July 26, 2006 To help those debugging. Here is login: username:hassan password: runescape PLEASE do not mess with the account, only use it for testing. Link to comment Share on other sites More sharing options...
Minion Posted July 26, 2006 Share Posted July 26, 2006 Someone out there will mess with it. I suggest creating a dummy account. Link to comment Share on other sites More sharing options...
ParoXsitiC Posted July 26, 2006 Author Share Posted July 26, 2006 Someone out there will mess with it. I suggest creating a dummy account.This account is pretty much a dummy account (just not mine) , no worries. Link to comment Share on other sites More sharing options...
ParoXsitiC Posted July 27, 2006 Author Share Posted July 27, 2006 I figured out the obvious reason why the GUI buttons don't work after I call the start button. Once I called the start button is calls the function StartRefresh() and never returns out of that function, therefore none of the GUIevents will work until StartRefresh is done. My question now is how can I work around this? How can I have the start button call the function but still be able to use the rest of the GUI buttons? Link to comment Share on other sites More sharing options...
ParoXsitiC Posted July 27, 2006 Author Share Posted July 27, 2006 Nevermind. Everything is fine now. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now