Sign in to follow this  
Followers 0
The_Lorax

Tips for unraveling a recursive mess

19 posts in this topic

Hello all,

I don't have much of a programming background.. anyway I coded a trading bot for magic the gathering online. The bot works, but crashes after 6 hours of use, because I am exceeding the 384 recursive function limit.

I know why its happening - im recurring a main loop over and over instead of waiting for the function that called it to finish. Unfortunatly I now have 10 interlocked functions that can be called from multiple places!

Does anyone have experience in cleaning up messes like this? Are there any modelling techniques that I can use to make this fix-it job easier? I'm getting a headache trying to figure out how to fix this, and I wrote it!! :P

Tim

Oh yeah.. I don't really want to post my code because its huge and I think I'd get laughed at!

;)

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Welcome to the Forums...

You are new and Your script works.... whos going to laff

We need to see it to help find the problem...

post your script like this

[ code ] ;no spaces

; copy paste your script here

[ /code ] ; no spaces

8)

Edited by Valuater

NEWHeader1.png

Share this post


Link to post
Share on other sites

Ok here goes,

Theres some really bad programming here, including:

- timers named stuff like '$10sectimer' that then had the duration check changed afterwards (just to make it really confusing)

- I couldn't figure out how to do a 'if (condition) is false' check on several variables so I coded it the long way: if true (do something useless) else (do the thing I wanted for the false condition)

- the commenting may be missing or misleading ;)

with that in mind..

#include <Array.au3>
#include <Date.au3>
#include <GuiConstants.au3>
HotKeySet("{ESC}", "Terminate")
Dim $tradernametime,$traderlog[1],$logtimer,$boardtimer,$lastspam = Timerinit(),$startoftrade,$nameabovebot = 0,$botname,$botpass,$msgbrdspam,$mktplcespam,$1stwelcome,$2ndwelcome,$3rdwelcome,$buddylist=0,$morecards = 0,$cardcounter,$spamcounter = 1
const $DELIMITER = ","
call("agui")
func agui()
Dim $line,$file,$i=1,$array[1],$b,$buttonval
GuiCreate("MTGbot Control Panel", 520, 367,(@DesktopWidth-520)/2, (@DesktopHeight-367)/2)
$save = GuiCtrlCreateButton("Save Settings", 40, 330, 90, 30)
$export = GuiCtrlCreateButton("Export Collection", 140, 330, 110, 30)
$hash = GuiCtrlCreateButton("Hash Cards", 260, 330, 70, 30)
$run = GuiCtrlCreateButton("Run Bot", 340, 330, 70, 30)
$inputname = GuiCtrlCreateInput("Name", 120, 10, 390, 20)
$Label_30 = GuiCtrlCreateLabel("Botname", 10, 10, 80, 20)
$Label_31 = GuiCtrlCreateLabel("Password", 10, 40, 80, 20)
$inputpass = GuiCtrlCreateInput("Password", 120, 40, 390, 20)
$chkreconnect = GuiCtrlCreateCheckbox("I want MTGbot to reconnect on disconnection", 10, 70, 240, 20)
$chkbuddylist = GuiCtrlCreateCheckbox("The bot has a buddylist", 10, 100, 130, 20)
$Label_39 = GuiCtrlCreateLabel("Welcome Message", 10, 200, 100, 20)
$inputwelcome1 = GuiCtrlCreateInput("Line 1", 120, 230, 390, 20)
$inputwelcome2 = GuiCtrlCreateInput("Line 2", 120, 260, 390, 20)
$inputwelcome3 = GuiCtrlCreateInput("Line 3", 120, 290, 390, 20)
$Label_43 = GuiCtrlCreateLabel("Line 1", 10, 230, 60, 20)
$Label_44 = GuiCtrlCreateLabel("Line 2", 10, 260, 60, 20)
$Label_45 = GuiCtrlCreateLabel("Line 3", 10, 290, 60, 20)
$file = fileopen("c:\program files\MTGbot\buysettings.dat",0)
While $i = 1
;read a line
$line = FileReadLine($file)
           If @error = -1 Then
            ExitLoop
        endif
;split it into a temporary array
_arrayadd($array,$line)
Wend
GUICtrlSetData ($inputname,$array[1])
if $array[2] = "," then
    $array[2] = ","
else
GUICtrlSetData ($inputpass,$array[2])
GUICtrlSetState ($chkreconnect,$GUI_CHECKED)
Endif
GUICtrlSetData ($inputpass,$array[2])
GUICtrlSetState ($inputpass,$GUI_DISABLE)
if $array[3] = "1" then
GUICtrlSetState ($chkbuddylist,$GUI_CHECKED)
else
GUICtrlSetState ($chkbuddylist,$GUI_UNCHECKED)
Endif
GUICtrlSetData ($inputwelcome1,$array[6])
GUICtrlSetData ($inputwelcome2,$array[7])
GUICtrlSetData ($inputwelcome3,$array[8])
GuiSetState()
While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        Exit 0
    Case $msg = $chkreconnect
        GUICtrlSetState ($inputpass,$GUI_ENABLE)
    Case $msg = $hash
        $buttonval = "hash"
        ExitLoop
    Case $msg = $run
$botname = GUICtrlRead ($inputname)
$msgbrdspam = "^qs^qv^qv BOT BUYING YOUR CARDS ^qv ALL CARDS ^qv ALL PRICES ^qv^qv^qv"
$mktplcespam = "BOT BUYING CARDS FOR ALL PRICES FAST  FAIR"
$1stwelcome = GUICtrlRead ($inputwelcome1) & "{ENTER}"
$2ndwelcome = GUICtrlRead ($inputwelcome2) & "{ENTER}"
$3rdwelcome = GUICtrlRead ($inputwelcome3) & "{ENTER}"
if GUICtrlRead ($chkreconnect) = $GUI_CHECKED then
    $botpass = GUICtrlRead ($inputpass)
Else
    $botpass = ""
Endif
if GUICtrlRead ($chkbuddylist) = $GUI_CHECKED Then
    $buddylist = 154
Else
    $buddylist = 0
Endif
$buttonval = "run"
        ExitLoop
    Case $msg = $export
        $buttonval = "export"
        ExitLoop
    Case $msg = $save
    $file = fileopen("c:\program files\MTGbot\buysettings.dat",2)
        filewriteline($file,GUICtrlRead ($inputname))
        if GUICtrlRead ($chkreconnect) = $GUI_CHECKED then 
            filewriteline($file,GUICtrlRead ($inputpass))
        Else
            filewriteline($file,",")
        Endif
        filewriteline($file,GUICtrlRead ($chkbuddylist))
        filewriteline($file,"empty")
        filewriteline($file,"empty")
        filewriteline($file,GUICtrlRead ($inputwelcome1))
        filewriteline($file,GUICtrlRead ($inputwelcome2))
        filewriteline($file,GUICtrlRead ($inputwelcome3))
    fileclose($file)
    msgbox(0,"","saved")
    EndSelect
WEnd
if $buttonval = "export" then
    GuiSetState(@SW_HIDE)
    call("export")
elseif $buttonval = "run" then
    GuiSetState(@SW_HIDE)
    call("firstlogin")
elseif $buttonval = "hash" then
    GuiSetState(@SW_HIDE)
    call ("hashacard")
endif
EndFunc
func innerloop(); the main loop the bot runs when it isn't trading.
    Dim $lagtimer
    Dim $i=1
    $cardcounter = 0
    While $I = 1 
    ;if a trade request is recieved
        if PixelGetColor (786,641) = 7917693 Then
        ;accept the trade and then..
            MouseClick("left",786,641)
        ; wait for the user to load in.
            $lagtimer = TimerInit()
            While timerdiff($lagtimer) < 40000
            ;select the place where the second name will appear
            mouseclick("left",1572,1088)
        ;if the customer has loaded in, end the loop
                if Pixelgetcolor(1582,1085) = 8224125 Then
                    ExitLoop
                EndIf
            sleep(500)
        WEnd
        ;if the customer hasnt loaded into the trade within 40 seconds, exit the trade and restart the inner loop
            if timerdiff($lagtimer) > 40000 Then 
                mouseclick("left",546,1135)
                MouseClick("left",1348,1043)
                Call("innerloop")
            endif
            ;when they load in:
            ; close any open PM's
            call("pm")
        ;close any open marketplace windows
            if pixelgetcolor(697,150) = 16776152 Then
                if pixelgetcolor(709,150) = 16770742 Then
                    if pixelgetcolor(709,162) = 9204540 Then
                        mouseclick("left",685,155)
                    EndIf
                EndIf
            Endif
        ;close any open messageboard windows
            if pixelgetcolor(757,150) = 16776152 Then
                if pixelgetcolor(769,150) = 16770742 Then
                    mouseclick("left",744,157)
                EndIf
            Endif
            ; copy the name to the clipboard
            send("^c",0)
            ;parse the name into a string
            $tradernametime = clipget()
        ;trim the funny character off the end
            $tradernametime = StringTrimRight ($tradernametime,1)
        ; if this name is the name of the bot
            if $tradernametime = $botname then
            ; click the customer's name 
                mouseclick("left",1440,1069)
            ;copy it onto the clipboard
                send("^c",0)
            ;parse it into a string
                $tradernametime = clipget()
            ;trim the funny character off the end
                $tradernametime = StringTrimRight ($tradernametime,1)
            ; set variable to true. used for later banning
                $nameabovebot = 1
            Else
            ;set variable to false. used for later banning
                $nameabovebot = 0
            endif
            if $tradernametime = "TraderBob{s}" Then
                call("botowner")
            endif
            ; add the current date / time to the customers name, seperated with a comma
            $tradernametime = $tradernametime & ","& _NowCalc()
            ; if the log is empty add the name to the first position
            if $traderlog[0] = "0" Then
                $traderlog[0] = $tradernametime
            ; if the log isn't empty
         Else 
        ;add it to the end of the log
                _ArrayAdd( $traderlog,$tradernametime)
        ; sort the log
                _ArraySort($traderlog,0,0)
        ; check for old entries in the log
                oldentries($traderlog,30)
            Endif
        ; sort the log
            _ArraySort($traderlog,0,0)
            ;check the log for abuse
            tard_checker($traderlog,6)
        ;send welcome message
            mouseclick("left",546,1135)
            sleep(100)
            send($1stwelcome,0)
            send($2ndwelcome,0)
            send($3rdwelcome,0)
        ; set the filters to show number owned =<1
            Mouseclick("left",121,70)
            Sleep(50)
            Mouseclick("left",207,203)
            Sleep(50)
            Mouseclick("left",187,235)
            Sleep(50)
            Mouseclick("left",248,194)
            Sleep(50)
            MouseMove(255,154)
            MouseDown("left")
            MouseUp("left")
            Sleep(50)
            MouseMove(190,194)
            MouseDown("left")
            MouseUp("left")
            Sleep(50)
            Mouseclick("left",199,72)
            Sleep(50)
        ;initialize a trade timer and enter the main loop
            $startoftrade = TimerInit()
            call("trade")
        EndIf
;check to see if a 'withdrawn from trade' or 'after trade' message is onscreen and close it if nessecary
call("checkwithdraw")
;check for the new cards window and close it if nessecary
call("newcardscheck")
;check if a duel request is recieved and close it if nessecary
call("duel_request")
;check if a PM is recieved and tell them to enter a trade with you.
call("PM")
;check if the log contains old entries
call("checklogtimer")
;check if the bot has been disconnected from the server.
call("checkdisconnect")
; if you havnt spammed the marketplace in 62 seconds, do it again
if TimerDiff ($lastspam) >62000 Then
;this will be replaced with the marketplace spam entered in the GUI
    Spam($mktplcespam)
    $lastspam = Timerinit() 
Endif
if TimerDiff ($boardtimer) > 7200000 Then; if the marketplace ad has timed out, update it.
;this will be replaced with the trade message entered in the GUI.
    boardupdate($msgbrdspam)
    $boardtimer= TimerInit()    
EndIf
;delay to reduce CPU usage before looping again
Sleep(1000) 
Wend
EndFunc
; the loop the bot runs when it is in a trade
Func trade()
call("intradecheck")
;check if a duel request is recieved, decline if nessecary
call("duel_request")
;check if a PM is recieved, tell them to enter a trade with you instead
call("PM")
;check to see if theyve been in the trade for longer than 5min.
call("tradetimer")
$buystr = "I'm buying: "
;check if a card is present in the top left corner of the binder (look for a white / black / green border)
if pixelgetcolor(465,120) = 16777215 Then
    call("pullcards")
elseif pixelgetcolor(465,120) = 0 then
    call("pullcards")
elseif pixelgetcolor(465,120) = 65280 Then
    call("pullcards")
endif
; if they didnt have anything you wanted, exit the trade.
if $cardcounter = 0 Then
        ;if they dont have cards you want marked tradable
        ; tell them
                mouseclick("left",546,1135)
                sleep (100)
                send("I can't see any cards that I need. If you have others for sale, please mark them tradable.{ENTER}",0)
                $p = TimerInit()
            ;loop around for 8 seconds waiting for a card you want to appear. if it happens, rerun trade.
                while timerdiff($p) < 8000
                if pixelgetcolor(465,120) = 16777215 Then
                    call("trade")
                elseif pixelgetcolor(465,120) = 0 then
                    call("trade")
                elseif pixelgetcolor(465,120) = 65280 Then
                    call("trade")
                endif
                call("intradecheck")
            ;check if a duel request is recieved, decline if nessecary
                call("duel_request")
            ;check if a PM is recieved, tell them to enter a trade with you instead
                call("PM")
                WEnd
            ;if they still havnt put cards up, exit the trade.
                mouseclick("left",546,1135)
                sleep (100)
                send("I still can't see any cards that I need. Thanks for trading with me.{ENTER}",0)
                sleep(2000)
                MouseClick("left",1348,1043)
                Call("innerloop")               
endif
call("id_cards")    
EndFunc
;check for a duel request and decline it.
Func duel_request()
    ;if a duel request is recived, decline it.
    if pixelchecksum(637,470,772,487) = 747246472 Then
    MouseClick("left",928,640)
    EndIf
EndFunc
;check for a PM and tell them to enter a trade with you.
Func PM()
; loop around for all 49 possible PM window locations 
for $i = 1 to 49
; if a pm window is open
    if pixelgetcolor((665+($i*12)),(112+($i*18))) = 16776152 Then
        if pixelgetcolor((677+($i*12)),(112+($i*18))) = 16770742 Then
            if pixelgetcolor((677+($i*12)),(124+($i*18))) = 9204540 Then
            ;select it
                mouseclick("left",(571+($i*12)),(117+($i*18)))
                sleep (100)
            ;click the textbox
                mouseclick("left",(526+($i*12)),(295+($i*18)))
                sleep(100)
            ;tell the user to enter a trade instead
                send ("I'm an automated bot that buys cards. Please open a trade if you want to sell me cards ^qs",0); ask the user to send a trade request instead of a PM
                if PixelGetColor (786,641) = 7917693 Then
                    call("innerloop")
                endif
                send("{ENTER}",0)
                sleep(1000)
            ;close the window
                mouseclick("left",(678+($i*12)),(114+($i*18)))
                sleep(1000)
            EndIf
        EndIf
    EndIf
Next

EndFunc
; spam the marketplace with an ad
Func Spam($a)
;if left = messageboard then click right
if pixelchecksum(1221-$buddylist,1157,1375-$buddylist,1169) = 3061995020 Then
mouseclick("left",1430-$buddylist,1159)
Else
; if right = messageboard then click left.
mouseclick("left",1308-$buddylist,1161)
Endif
Sleep(1000)
;spam it
MouseMove(240,371)
MouseDown("left")
MouseUp("left")
Sleep(100)
if $spamcounter = 1 Then
    Send("III  " & $a & "  III",0)
    $spamcounter = $spamcounter + 1
elseif $spamcounter = 2 Then
    Send("ZZZ  " & $a & "  ZZZ",0)
    $spamcounter = $spamcounter + 1
elseif $spamcounter = 3 Then
    Send("---  " & $a & "  ---",0)
    $spamcounter = $spamcounter + 1
elseif $spamcounter = 4 Then
    Send("lll  " & $a & "  lll",0)
    $spamcounter = $spamcounter + 1
elseif $spamcounter = 5 Then
    Send("-+-  " & $a & "  -+-",0)
    $spamcounter = 1
EndIf
if PixelGetColor (786,641) = 7917693 Then
call("innerloop")
endif
Send("{ENTER}",0)
MouseMove(687,156)
MouseDown("left")
MouseUp("left")
;update the timer
$lastspam = Timerinit()
EndFunc
;check for old entries in the log every minute.
Func checklogtimer()
;if the log hasnt been checked in a minute, check it again
if TimerDiff ($logtimer) > 60000 Then
oldentries($traderlog,10)
EndIf
EndFunc
; remove old entries from the log if they are older than $b
Func oldentries(byref $a,$b)
; check for entries older than $b min
Local $value
Local $datetime
Local $diff
For $i = Ubound($a) to 1 Step -1
$value = $a[($i-1)]
$datetime = StringTrimLeft ( $value, StringInStr ( $value, ","))
$diff = _DateDiff('n',$datetime,_NowCalc())
; if it is older than $b, delete it
if $diff > $b Then
    if ($i-1) = 0 Then
    $a[0] = "0"
    Else
_ArrayDelete ($a, ($i-1))
EndIf
EndIf
if $a[0] = "0" and Ubound($a) > 1 Then
_ArrayDelete ($a,0)
Endif
Next
Return ""
EndFunc
;search the logs for abuse.
Func tard_checker($array,$MaxCount)
;if someone appears in the logs more than $maxcount, call the block function
$maxcount = $maxcount - 1
$name = get_name($array[0])
$occurance = 0
for $n = 1 to Ubound($array)-1
       if get_name($array[$n]) = $name then
         $occurance = $occurance +1
        if $occurance >= $MaxCount then
        call("block_user")
         endif
    else
         $name = get_name($array[$n])
         $occurance = 0
     endif
next
endfunc
; block a tard
func block_user()
;if their name appears above yours, click the top name and block them
if $nameabovebot = 1 Then
    MouseMove(1285,1073)
    MouseDown("left")
    MouseUp("left")
    Sleep(100)
    MouseMove(1352,1075)
    MouseDown("right")
    MouseUp("right")
    Sleep(100)
    MouseMove(1374,1155)
    MouseDown("left")
    MouseUp("left")
    Sleep(100)
    MouseMove(1350,1078)
    MouseDown("right")
    MouseUp("right")
    Sleep(100)
    MouseMove(1361,1107)
    MouseDown("left")
    MouseUp("left")
    Sleep(100)
;if their name appears below yours, click the top name and block them
Else
    MouseMove(1301,1086)
    MouseDown("left")
    MouseUp("left")
    Sleep(100)
    MouseDown("right")
    MouseUp("right")
    Sleep(100)
    MouseMove(1322,1161)
    MouseDown("left")
    MouseUp("left")
    Sleep(100)
    MouseMove(1290,1092)
    MouseDown("right")
    MouseUp("right")
    Sleep(100)
    MouseMove(1311,1107)
    MouseDown("left")
    MouseUp("left")
    Sleep(100)
Endif
; tell them they have been owned.
    MouseCLick("left",145,304)
    sleep (100)
    Send("You have been blocked for sending me excessive trade requests.{ENTER}",0)
    MouseMove(688,140)
    MouseDown("left")
    MouseUp("left")
    Sleep(100)
    MouseMove(1348,1043)
    MouseDown("left")
    MouseUp("left")
endfunc
;part of tard_checker
func get_name($text)
 
local $items = StringSplit($text,$DELIMITER)
  return $items[1]
endfunc
;part of tard_checker
func get_time($text)
    local $items = StringSplit($text,$DELIMITER)
    return $items[2]
endfunc
;post your ad on the messageboard.
func boardupdate($a)
if pixelchecksum(1221-$buddylist,1157,1375-$buddylist,1169) = 3061995020 Then;if left = messageboard then click left
mouseclick("left",1308-$buddylist,1161)
Else;if right = messageboard then click right
mouseclick("left",1430-$buddylist,1159)
Endif
;spam $a message on the message board and minimize it.
Sleep(1000)
MouseMove(275,468)
MouseDown("left")
MouseUp("left")
Sleep(100)
Send($a,0)
if PixelGetColor (786,641) = 7917693 Then
call("innerloop")
endif
Send("{ENTER}",0)
MouseMove(745,155)
MouseDown("left")
MouseUp("left")
Sleep(1000)
$boardtimer= TimerInit()
EndFunc
;check to see if there is a 'withdraw' prompt onscreen and close it if nessecary.
func checkwithdraw()
    ;if a withdraw prompt is onscreen
    if pixelchecksum(637,470,772,487) = 2078928619 Then
        ;close it
            MouseClick("left",891,633)
    Endif
Endfunc
; calculate the selling price for the cards the user chose.
func ID_cards()
Dim $file,$line,$linearray[4],$tradestr,$buytotal = 0,$atimer,$tradeok = 1,$tradearray[3][32],$1mintimer
for $i= 1 to 32
call("intradecheck")
;check if a duel request is recieved, decline if nessecary
call("duel_request")
;check if a PM is recieved, tell them to enter a trade with you instead
call("PM")
;check to see if theyve been in the trade for longer than 5min.
;generate a checksum for the top part of the card. store this in $traderarray[0][X]
$tradearray[0][$i-1] = pixelchecksum(156,(95+(12*$i)),229,(106+(12*$i)))
$file = FileOpen ( "c:\program files\MTGbot\botdata.csv",0 )
;Loop until end of file.
While 1
   $line = FileReadLine($file)
         If @error = -1 Then ExitLoop   
    $linearray = StringSplit ( $line, ",")
; if the checksum matches the checksum in the csv file, copy the price and name into $traderarray[1&2][x] and add to the total.
    if $linearray[1] = $tradearray[0][$i-1] Then
        $tradearray[2][$i-1] = $linearray [4]
        $buytotal = $buytotal + $tradearray[2][$i-1]
        if $buytotal > 32 Then
            $buytotal = $buytotal - $tradearray[2][$i-1]
            while 1
                if pixelchecksum(156,(197+(12*($i-1))),229,(197+(12*($i-1)))) = 1456332067 Then
                        exitloop
                elseif pixelchecksum(156,(197+(12*($i-1))),229,(197+(12*($i-1)))) = 14548993 then
                        exitloop
                    elseif pixelchecksum(156,(197+(12*($i-1))),229,(197+(12*($i-1)))) = 495143351 Then
                        ExitLoop
                
                Endif
                mouseclick("left",195,(99+(12*$i)))
                sleep (200)
            wend
            Exitloop 2
        endif
        $tradearray[1][$i-1] = $linearray[2]
        endif
Wend
if $tradearray[1][$i-1] = "0" then
    $tradearray[1][$i-1] = "0"
; generate a transaction summary for the customer.
; if its the first time through the loop, don't put a comma between 'you have selected:' and the name of the first card.
ElseIf $i = 1 then 
$tradestr = $tradearray[1][$i-1] & " for " & $tradearray[2][$i-1]
; if it isn't the first time through, add a comma in between.
Else
$tradestr = $tradestr & " ," & $tradearray[1][$i-1] & " for " & $tradearray[2][$i-1]
Endif
FileClose($file)
Next
$tradestr = $tradestr & " TOTAL = " & $buytotal &" Event Tickets."
mouseclick("left",546,1135)
sleep (100)
send("I'm interested in buying these cards:{ENTER}",0)
send($tradestr & "{ENTER}",0)
send("Make any cards you don't want to sell for these prices untradable{ENTER}",0)
send("or please take " & int($buytotal) & " ticket(s) and confirm the trade.{ENTER}",0)
if pixelgetcolor(465,120) = 0 Then
    $morecards = 1
elseif pixelgetcolor(465,120) = 16777215 Then
    $morecards = 1
endif
$atimer = Timerinit()
tix(int($buytotal),$atimer)
Endfunc

func tradecheck($total,$1mintimer)
Dim $tradearray[3][32], $file, $line,$newtotal,$linearray[4],$tradeok,$c,$notenoughtickets,$ticketcount
;perform the hashcheck again.
;loop around for each card in the trade window
for $i= 1 to 32
call("intradecheck")
;check if a duel request is recieved, decline if nessecary
call("duel_request")
;check if a PM is recieved, tell them to enter a trade with you instead
call("PM")
;generate a checksum for the top part of the card. store this in $traderarray[0][X]
$tradearray[0][$i-1] = pixelchecksum(156,(95+(12*$i)),229,(106+(12*$i)))
$file = FileOpen ( "c:\program files\MTGbot\botdata.csv",0 )
;Loop until end of file.
While 1
   $line = FileReadLine($file)
         If @error = -1 Then ExitLoop   
    $linearray = StringSplit ( $line, ",")
; if the checksum matches the checksum in the csv file, copy the price and name into $traderarray[1&2][x] and add to the total.
    if $linearray[1] = $tradearray[0][$i-1] Then
        $newtotal = $newtotal + $linearray[4]
    EndIf
Wend
FileClose($file)
Next
;if the trade is still the same
if int($newtotal) = $total Then
;and there are enough tickets in the trade
    $ticketcount = 0
    for $x = 1 to 32
        if pixelgetcolor(50,(96+($x*12))) = 1247493 Then
            $ticketcount = $ticketcount + 1
        Else
            exitloop
        EndIf
    Next
if $ticketcount = $total then
    confirm($total)
elseif $ticketcount < $total then
    mouseclick("left",546,1135)
    sleep (100)
    Send("Please take " & ($total - $ticketcount) & " more event tickets and confirm the trade.{ENTER}",0)
;unconfirm the customers trade.
    MouseMove(340,41)
    MouseDown("left")
    MouseUp("left")
    Sleep(50)
    MouseMove(249,219)
    MouseDown("left")
    MouseMove(249,218)
    MouseUp("left")
    Sleep(50)
    MouseMove(159,297)
    MouseDown("left")
    MouseUp("left")
    Sleep(50)
    MouseMove(547,369)
    MouseDown("left")
    MouseUp("left")
    Sleep(50)
    MouseMove(547,375)
    MouseDown("left")
    MouseUp("left")
    Sleep(50)
    MouseMove(448,41)
    MouseDown("left")
    MouseUp("left")
    while pixelchecksum(57,739,115,758) = 1600235646
    Sleep(50)
    WEnd
    tix($total,$1mintimer)
elseif $ticketcount > $total then 
    mouseclick("left",546,1135)
    sleep (100)
    Send("Please remove " & ($ticketcount - $total) & " event tickets and confirm the trade.{ENTER}",0)
;unconfirm the customers trade.
    MouseMove(340,41)
    MouseDown("left")
    MouseUp("left")
    Sleep(50)
    MouseMove(249,219)
    MouseDown("left")
    MouseMove(249,218)
    MouseUp("left")
    Sleep(50)
    MouseMove(159,297)
    MouseDown("left")
    MouseUp("left")
    Sleep(50)
    MouseMove(547,369)
    MouseDown("left")
    MouseUp("left")
    Sleep(50)
    MouseMove(547,375)
    MouseDown("left")
    MouseUp("left")
    Sleep(50)
    MouseMove(448,41)
    MouseDown("left")
    MouseUp("left")
    while pixelchecksum(57,739,115,758) = 1600235646
    Sleep(50)
    WEnd
    tix($total,$1mintimer)
endif
else
;inform the customer
    mouseclick("left",546,1135)
    sleep (100)
    Send("You have removed some cards in the trade. Recalculating the trade.{ENTER}",0)
;update $cardcounter to reflect the number of cards in the trade window
    $cardcounter = 0
    for $t = 1 to 32
call("intradecheck")
;check if a duel request is recieved, decline if nessecary
call("duel_request")
;check if a PM is recieved, tell them to enter a trade with you instead
call("PM")
            if pixelchecksum(156,(95+($t*12)),229,(95+($t*12))) = 1456332067 Then
                $cardcounter = $cardcounter +1
            Elseif pixelchecksum(156,(95+($t*12)),229,(95+($t*12))) = 14548993 Then
                $cardcounter = $cardcounter +1
            Else
            Exitloop    
            EndIf
        Next
; if newtotal is less than 19, go back to the main trade loop. this may add new cards to the trade window.
; if its above 19, recalculate the trade instead.
    if $newtotal > 19 Then
        call("ID_cards")
    Else
        call("trade")
    endif
Endif
Endfunc
;complete the trade.
func confirm($total)
    Dim $30sectimer,$10sectimer
call("intradecheck")
;check if a duel request is recieved, decline if nessecary
call("duel_request")
;check if a PM is recieved, tell them to enter a trade with you instead
call("PM")
;confirm the trade
    MouseMove(248,742)
    MouseDown("left")
    MouseUp("left")
    Sleep(200)
    MouseMove(205,764)
    MouseDown("left")
    MouseUp("left")
    Sleep(200)
    MouseMove(310,1142)
    MouseDown("left")
    MouseUp("left")
    Sleep(200)
    $30sectimer = timerinit()
    while timerdiff($30sectimer) < 30000
        ;check for them removing cards
            tradechange($total)
        ;check to see if you are still in a trade, head back to inner loop if you arn't
            call("intradecheck")
        ;check if a duel request is recieved, decline if nessecary
            call("duel_request")
        ;check if a PM is recieved, tell them to enter a trade with you instead
            call("PM")
        ; if the confirm trade button is onscreen
            if pixelchecksum(1219,1028,1374,1037) = 2336066960 Then
        ;thank them
            mouseclick("left",546,1135)
            sleep (100)
            send("Thanks for selling some cards to me! ^qs{ENTER}",0)
            if $morecards = 1 then
                send("I want to buy more cards from your collection. Please open a trade after this if you want to sell more cards.{ENTER}",0)
                $morecards = 0
            endif
            sleep(1000)
        ; click the trade button
            mouseclick("left",1273,1029)
                $10sectimer=TimerInit()
                while timerdiff($10sectimer) < 10000
            sleep(300)
        Wend
;if they back out of the trade, go on to the next step
    If pixelgetcolor(436,35) = 6600129 then
        ExitLoop
        endif
    EndIf
    sleep(500)
WEnd
; if still in a trade (customer didn't click it)
If pixelgetcolor(436,35) = 6600129 then 
    mouseclick("left",546,1135)
    sleep (100)
    send("You aborted the trade. Recalculating.{ENTER}",0)
;go back to the start of the trade loop
    call("trade")
Else
;trade has ended, so go back to the 'waiting for a trade' loop
    call("innerloop")
EndIf
EndFunc
;this checks for the new cards window, and closes it if nessecary.
func newcardscheck()
;the window can be in 3 places. check for its presence and close it if nessecary.
if pixelchecksum(321,61,386,70) = 4069852983 Then
    if pixelchecksum(791,59,805,72) = 182725946 Then
        mouseclick("left",798,65)
    elseif pixelchecksum(745,59,759,72) = 182725946 then
        mouseclick("left",752,65)
    elseif pixelchecksum(803,59,817,72) = 182725946 Then
        mouseclick("left",810,65)
    endif
EndIf
EndFunc

Func tix($total,$1mintimer)
Dim $ticketcount = 0
while 1
;check to see if the trade has changed since the confirm button was clicked     
tradechange($total)
;check to see if you are still in a trade, head back to inner loop if you arn't
call("intradecheck")
;check if a duel request is recieved and decline if nessecary
call("duel_request")
;check if a PM is recieved, and tell them to open a trade
call("PM")
;if they have taken an event ticket, loop around until they select $total tickets
if pixelchecksum(57,739,115,758) = 1600235646 Then
    tradecheck($total,$1mintimer)
endif
if timerdiff($1mintimer) > 60000 then
    MouseClick("left",385,1141)
    sleep (100)
    Send("You havn't confirmed the trade. Recalculating.{ENTER}",0)
    call("trade")
EndIf
wend
EndFunc

func tradechange($total)
Dim $tradearray[3][32], $file, $line,$newtotal,$linearray[4],$10sectimer
for $i= 1 to 32
;generate a checksum for the top part of the card. store this in $traderarray[0][X]
$tradearray[0][$i-1] = pixelchecksum(156,(95+(12*$i)),229,(106+(12*$i)))
$file = FileOpen ( "c:\program files\MTGbot\botdata.csv",0 )
;Loop until end of file.
While 1
   $line = FileReadLine($file)
         If @error = -1 Then ExitLoop   
    $linearray = StringSplit ( $line, ",")
; if the checksum matches the checksum in the csv file, copy the price into $traderarray[1&2][x] and add to the total.
    if $linearray[1] = $tradearray[0][$i-1] Then
        $newtotal = $newtotal + $linearray[4]
    EndIf
Wend
FileClose($file)
Next
;if the trade has changed
if int($newtotal) <> $total Then
;inform the customer
    mouseclick("left",546,1135)
    sleep (100)
    Send("You have removed some cards in the trade. Recalculating.{ENTER}",0)
;update $cardcounter to reflect the number of cards in the trade window
    $cardcounter = 0
    for $t = 1 to 32
            if pixelchecksum(156,(95+($t*12)),229,(95+($t*12))) = 1456332067 Then
                $cardcounter = $cardcounter +1
            Elseif pixelchecksum(156,(95+($t*12)),229,(95+($t*12))) = 14548993 Then
                $cardcounter = $cardcounter +1
            Else
            Exitloop    
            EndIf
        Next
; if newtotal is less than 19, go back to the main trade loop. this may add new cards to the trade window.
; if its above 19, recalculate the trade instead.
        if $newtotal > 19 Then
        call("ID_cards")
    Else
        call("trade")
    Endif
endif
EndFunc
;used to close the bot by hitting esc.
Func Terminate()
;when escape is hit, stop the bot.
    msgbox(0,"","MTGbot stopped")
    call("agui")
EndFunc
;check if the bot is still in a trade. if not, return to the inner loop
func intradecheck()
    if pixelgetcolor(415,36) = 0 Then
        call("innerloop")
    EndIf
endfunc
;if the bot gets disconnected, start the reconnection process
func checkdisconnect()
;if the user refused to provide a password in the gui, end the function
    if $botpass = "" then
        $botpass = ""
;if disconnected box is onscreen
    elseif pixelchecksum(637,470,857,487) = 2808774430 Then
    ;close it
        mouseclick("left",892,631)
        sleep(100)
        call ("dologin")
    Endif
endfunc
;try and log in
func dologin()
;input username
    mouseclick("left",764,582)
    sleep(100)
    Send($botname)
    sleep(100)
;input password
    mouseclick("left",760,632)
    sleep(100)
    Send($botpass)
    mouseclick("left",800,660)
;attempt to login
    call("loginattempt")
endfunc
;handle the login attempt
func loginattempt()
dim $10sectimer,$logintimer
$logintimer = timerinit()
;loop round for 3min waiting for the login attempt.
while TimerDiff ($logintimer) <  180000 
        ;if the 'no connection to server' error appears
            if  pixelchecksum(622,491,976,603) = 2151702803 Then
            ;close it
                mouseclick("left",925,678)
                sleep(100)
            ;erase the username field
                mouseclick("left",764,582)
                sleep(100)
                $10sectimer = timerinit()
                while timerdiff($10sectimer) < 4000
                    Send("{BACKSPACE}",0)
                    sleep(10)
                Wend
                $10sectimer = timerinit()
                while timerdiff($10sectimer) < 4000
                    Send("{DELETE}",0)
                    sleep(10)
                Wend
            ;erase the password field
                Sleep(200)
                mouseclick("left",760,632)
                sleep(100)
                $10sectimer = timerinit()
                while timerdiff($10sectimer) < 4000
                    Send("{BACKSPACE}",0)
                    sleep(10)
                Wend
                $10sectimer = timerinit()
                while timerdiff($10sectimer) < 4000
                    Send("{DELETE}",0)
                    sleep(10)
                Wend
            Sleep(200)
            ;try to login again
                call("dologin")
            elseif pixelchecksum(131,61,203,70) = 2666305482 Then
            ;if MTGO has logged in
            ;open the marketplace and message board
                call("firstlogin")
            ; if the 'this user is allready logged in' box appears
            elseif  pixelchecksum(654,532,962,541) = 2905472228 Then
            ; close it
                mouseclick("left",809,647)
                sleep(200)
            ;erase the username field
                mouseclick("left",764,582)
                sleep(100)
                $10sectimer = timerinit()
                while timerdiff($10sectimer) < 4000
                    Send("{BACKSPACE}",0)
                    sleep(10)
                Wend
                $10sectimer = timerinit()
                while timerdiff($10sectimer) < 4000
                    Send("{DELETE}",0)
                    sleep(10)
                Wend    
                Sleep(200)
            ;erase the password field
                mouseclick("left",760,632)
                sleep(100)
                $10sectimer = timerinit()
                while timerdiff($10sectimer) < 4000
                    Send("{BACKSPACE}",0)
                    sleep(10)
                Wend
                $10sectimer = timerinit()
                while timerdiff($10sectimer) < 4000
                    Send("{DELETE}",0)
                    sleep(10)
                Wend
                Sleep(200)      
            ;try to login again
                call("dologin")
            endif
    Sleep(5000)
WEnd
; if after 3 minutes you still havn't logged in, try again
call("dologin")
EndFunc
;this function opens the marketplace and message board, spams the message board and runs the bot.
func firstlogin()
dim $y=1,$z=1
; if MTGO is sitting on the 'main room'
    if pixelchecksum(131,61,203,70) = 2666305482 Then
    ;click the trade button
        mouseclick("left",618,567)
    ;loop around waiting for it to appear
        while pixelchecksum(131,61,203,70) = 2666305482
            sleep(500)
        wend
    ;open the message board
        mouseclick("left",835,531)
    ;loop around waiting for it to appear
        while $y = 1
        ;when it does appear, minimize it and exitloop
            if pixelgetcolor(274,460) = 9802661 then
                mouseclick("left",745,157)
                exitloop
            endif
        wend
    ;open the marketplace
        mouseclick("left",1043,554)
    ;wait for it to appear
        while $z = 1
        ;when it does appear, minimize it and exitloop
            if pixelgetcolor(182,371) = 9802661 then
                mouseclick("left",683,151)
                sleep(2000)
                exitloop
            endif
        wend
        sleep(200)
    ;update the message board
        boardupdate($msgbrdspam)
    ;start the bots inner loop.
        call("innerloop")
    Endif
EndFunc
; this function generates a checksum for the card in the 'you get' trade window.

; this function generates a checksum for the card in the 'you get' trade window.
Func hashacard()
dim $inputstr, $line, $file, $i = 1
$file = FileOpen ( "c:\program files\MTGbot\botdata.csv",1 )
while $i = 1
; ask the user to enter the card name, selling price and buying price
$inputstr = inputbox("card details", "enter the card name,selling price,buying price seperated by commas. Make sure the card you want to hash is visibile in the 'you get' trade box.")
if @error = 1 then
    call("terminate")
Endif
; write the hash,name,sellprice,buyprice to the end of the bot datafile.
$line = pixelchecksum(156,107,229,118) & "," & $inputstr
FileWriteLine($file,$line)
Wend
FileClose($file)
call("agui")
Endfunc
; this function exports the bots collection to owned.csv
Func export()
; select the collection tab
mouseclick("left",353,40)
sleep(100)
;reset all filters
mouseclick("left",215,340)
;change the filter to rare cards.
MouseMove(256,225)
MouseDown("left")
MouseUp("left")
Sleep(100)
MouseMove(213,291)
MouseDown("left")
MouseUp("left")
Sleep(100)
;sort by set, collector number.
MouseMove(248,266)
MouseDown("left")
Sleep(100)
MouseMove(200,300)
MouseDown("left")
MouseUp("left")
Sleep(100)
; if the collection isnt on the text style display, click the button to change to the text display.
if (pixelchecksum(1564,59,1584,72)) = 1694229323 then
    MouseMove(1579,69)
    MouseDown("left")
    MouseUp("left")
    Sleep(100)
Endif
; right click
MouseMove(392,150)
MouseDown("right")
; seleect all
MouseMove(387,152)
MouseUp("right")
Sleep(100)
MouseMove(412,180)
MouseDown("left")
MouseUp("left")
Sleep(100)
;export as csv
MouseMove(399,187)
MouseDown("right")
MouseUp("right")
Sleep(100)
MouseMove(428,232)
MouseDown("left")
MouseUp("left")
Sleep(100)
WinWait("Export as CSV","")
If Not WinActive("Export as CSV","") Then WinActivate("Export as CSV","")
WinWaitActive("Export as CSV","")
; save as owned.csv
Send("owned.csv")
MouseMove(507,398)
MouseDown("left")
MouseUp("left")
Sleep(100)
WinWait("Magic Online V2.0.001.522","")
If Not WinActive("Magic Online V2.0.001.522","") Then WinActivate("Magic Online V2.0.001.522","")
WinWaitActive("Magic Online V2.0.001.522","")
;close prompt
MouseMove(789,645)
MouseDown("left")
MouseUp("left")
Sleep(100)
msgbox(0,"","export completed")
call("agui")
Endfunc

Func pullcards()
dim $z = 1,$crdpixl
while $z = 1
$crdpixl = pixelgetcolor(465,120)
if $crdpixl = 16777215 Then
    $cardcounter = $cardcounter +1
    if $cardcounter < 32 Then
        mouseclick("left",533,202)
    EndIf
elseif $crdpixl = 0 then
    $cardcounter = $cardcounter +1
    if $cardcounter < 32 Then
        mouseclick("left",533,202)
    EndIf
elseif $crdpixl = 65280 Then
        $cardcounter = $cardcounter +1
    if $cardcounter < 32 Then
        mouseclick("left",533,202)
    EndIf
else
    sleep(200)
    call("trade")
endif
;check if a duel request is recieved and decline if nessecary
call("duel_request")
;check if a PM is recieved and tell them to enter a trade
call("PM")
;check to see if you are still in the trade.
call("intradecheck")
mousemove(376,130,3)
wend
EndFunc

func tradetimer()
if timerdiff($startoftrade) > 300000 then
    MouseClick("left",385,1141)
    sleep (100)
    Send("You have been inactive for five minutes. If you want to sell cards to me you'll need to send another trade request.{ENTER}",0)
    Send(" Now closing inactive trade{ENTER}",0)
    Sleep(2000)
    MouseClick("left",1348,1043)
    call("innerloop")
endif
EndFunc

func botowner()
dim $i = 1
; if the bot owner trades with the bot
; filter all cards where number owned > 1
mouseclick("left",331,39)
sleep(100)
MouseMove(214,332)
MouseDown("left")
MouseUp("left")
Sleep(100)
MouseMove(254,169)
MouseDown("left")
MouseUp("left")
Sleep(100)
MouseMove(250,136)
MouseDown("left")
MouseUp("left")
Sleep(100)
MouseMove(167,164)
MouseDown("left")
MouseUp("left")
Sleep(100)
MouseMove(917,259)
MouseDown("right")
MouseMove(916,259)
MouseUp("right")
Sleep(100)
MouseMove(938,289)
MouseDown("left")
MouseUp("left")
Sleep(100)
mouseclick("left",433,37)
Sleep(100)
call("ticketfilter")
call("pulltix")
;wait here for the owner to confirm the trade.
While $i = 1
    if pixelchecksum(57,739,115,758) = 1600235646 Then
        ExitLoop
    Else
        sleep(100)
    EndIf
WEnd
;confirm the trade
    MouseMove(248,742)
    MouseDown("left")
    MouseUp("left")
    Sleep(200)
    MouseMove(205,764)
    MouseDown("left")
    MouseUp("left")
    Sleep(200)
    MouseMove(310,1142)
    MouseDown("left")
    MouseUp("left")
    Sleep(100)
    $30sectimer = timerinit()
    while timerdiff($30sectimer) < 30000
        ; if the confirm trade button is onscreen
            if pixelchecksum(1219,1028,1374,1037) = 2336066960 Then
            ; click the trade button
                mouseclick("left",1273,1029)
                exitloop
            endif
    sleep(100)
wend
sleep(10000)
send("{ENTER}",0)
call("newcardscheck")
; make all the cards in your collection untradable.
MouseMove(220,341)
MouseDown("left")
MouseMove(220,342)
MouseUp("left")
Sleep(100)
MouseMove(251,130)
MouseDown("left")
MouseUp("left")
Sleep(100)
MouseMove(177,176)
MouseDown("left")
MouseUp("left")
Sleep(100)
MouseMove(938,311)
MouseDown("right")
MouseUp("right")
Sleep(100)
MouseMove(987,362)
MouseDown("left")
MouseUp("left")
Sleep(100)
; make all your event tickets tradable.
MouseMove(214,341)
MouseDown("left")
MouseUp("left")
Sleep(100)
MouseMove(245,134)
MouseDown("left")
MouseUp("left")
Sleep(100)
MouseMove(180,211)
MouseDown("left")
MouseUp("left")
Sleep(100)
MouseMove(927,340)
MouseDown("right")
MouseMove(927,339)
MouseUp("right")
Sleep(100)
MouseMove(947,374)
MouseDown("left")
MouseUp("left")
Sleep(100)
call("innerloop")
EndFunc

func ticketfilter()
;filter to show boosters
MouseMove(125,78)
MouseDown("left")
MouseUp("left")
Sleep(100)
MouseMove(246,345)
MouseDown("left")
MouseMove(245,345)
MouseUp("left")
Sleep(100)
MouseMove(251,160)
MouseDown("left")
MouseUp("left")
Sleep(100)
MouseMove(189,209)
MouseDown("left")
MouseUp("left")
Sleep(100)
MouseMove(135,311)
MouseDown("left")
MouseUp("left")
Sleep(100)
;search for 'event'
Send("event{ENTER}")
;switch back to the trade box
MouseMove(195,76)
MouseDown("left")
MouseUp("left")
Sleep(100)
EndFunc

func pulltix()
while pixelchecksum(481,122,586,139) = 366956196
    mouseclick("left",529,252)
    mousemove(427,159)
    sleep(100)
WEnd
sleep(1000)
if pixelchecksum(481,122,586,139) = 366956196 Then
    call("pulltix")
EndIf
EndFunc

it all works, except for the recursion problem.

Because of the amount of work required to fix this, I was wondering if anyone has techniques to make it easier.. I don't want you to do it for me, because I won't learn much and its going to take a long time to fix.

oh.. and just so you know..

I'm a university student - Thankfully I don't get paid to code, which probably explains the gigantic mess I've created.

Anyone know why it hasn't kept the indentations from the editior when I pasted it across?

Share this post


Link to post
Share on other sites

Makes you feel any better, im a coder and i get paid to code... im not laughing at your code... its more like "Holy Shit" thats a gigantic program in AutoIt. Good Work... accept for the crashing ofcourse. :-P


Ooo Ëxçã¿îbúr ooO"Information Is Not Knowledge." ~Albert Einstein

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Thanks. ;)

Some background on how its works:

- Cards in MTGO appear in the trade window in a certain position. the cards stack so that the top of each card is 12 pixels below the top of the card before it (like this)

{^^^^^}

{^^^^^}

- Each card is exactly 12 pixels tall when stacked in 1600x1200 res. I had to use that resolution to fit 32 cards into the trade without a scrollbar.

- 32 cards is the maximum that can be included in a trade.

- Each card will have a unique pixel checksum that can be used to identify the card. This pixel checksum is generated using the function hashacard() and is stored in botdata.csv

in all honesty, I don't think this could be understood without knowlege of magic the gathering online. The problem however, is very simple:

func loop1()
call ("loop2")
endfunc

func loop2()
call ("loop1")
endfunc

fixing it is another matter entirely. Please dont submit this to www.thedailywtf.com :P

Edited by The_Lorax

Share this post


Link to post
Share on other sites

Makes you feel any better, im a coder and i get paid to code... im not laughing at your code... its more like "Holy Shit" thats a gigantic program in AutoIt. Good Work... accept for the crashing ofcourse. :-P

I dont get paid but.... DIDO to Excalibur

ok... one at a time

will this work????

Func pulltix()
    Do
        While PixelChecksum(481, 122, 586, 139) = 366956196
            MouseClick("left", 529, 252)
            MouseMove(427, 159)
            Sleep(100)
        WEnd
        Sleep(1000)
    Until Not PixelChecksum(481, 122, 586, 139) = 366956196
EndFunc  ;==>pulltix

????

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

ok...

first

excellent job!!!!!!

second

there should be a "body" of the program. in your script that would be the function you call "aqui". so i removed that as a function and set the functions to "run" from the "body"

third

the code

#include <Array.au3>
#include <Date.au3>
#include <GuiConstants.au3>
HotKeySet("{ESC}", "Terminate")
Dim $tradernametime, $traderlog[1], $logtimer, $boardtimer, $lastspam = TimerInit(), $startoftrade, $nameabovebot = 0, $botname, $botpass, $msgbrdspam, $mktplcespam, $1stwelcome, $2ndwelcome, $3rdwelcome, $buddylist = 0, $morecards = 0, $cardcounter, $spamcounter = 1
Const $DELIMITER = ","

    Dim $line, $file, $i = 1, $array[1], $b, $buttonval
    GUICreate("MTGbot Control Panel", 520, 367, (@DesktopWidth - 520) / 2, (@DesktopHeight - 367) / 2)
    $save = GUICtrlCreateButton("Save Settings", 40, 330, 90, 30)
    $export = GUICtrlCreateButton("Export Collection", 140, 330, 110, 30)
    $hash = GUICtrlCreateButton("Hash Cards", 260, 330, 70, 30)
    $run = GUICtrlCreateButton("Run Bot", 340, 330, 70, 30)
    $inputname = GUICtrlCreateInput("Name", 120, 10, 390, 20)
    $Label_30 = GUICtrlCreateLabel("Botname", 10, 10, 80, 20)
    $Label_31 = GUICtrlCreateLabel("Password", 10, 40, 80, 20)
    $inputpass = GUICtrlCreateInput("Password", 120, 40, 390, 20)
    $chkreconnect = GUICtrlCreateCheckbox("I want MTGbot to reconnect on disconnection", 10, 70, 240, 20)
    $chkbuddylist = GUICtrlCreateCheckbox("The bot has a buddylist", 10, 100, 130, 20)
    $Label_39 = GUICtrlCreateLabel("Welcome Message", 10, 200, 100, 20)
    $inputwelcome1 = GUICtrlCreateInput("Line 1", 120, 230, 390, 20)
    $inputwelcome2 = GUICtrlCreateInput("Line 2", 120, 260, 390, 20)
    $inputwelcome3 = GUICtrlCreateInput("Line 3", 120, 290, 390, 20)
    $Label_43 = GUICtrlCreateLabel("Line 1", 10, 230, 60, 20)
    $Label_44 = GUICtrlCreateLabel("Line 2", 10, 260, 60, 20)
    $Label_45 = GUICtrlCreateLabel("Line 3", 10, 290, 60, 20)
    $file = FileOpen("c:\program files\MTGbot\buysettings.dat", 0)
    While $i = 1
    ;read a line
        $line = FileReadLine($file)
        If @error = -1 Then
            ExitLoop
        EndIf
    ;split it into a temporary array
        _ArrayAdd($array, $line)
    WEnd
    GUICtrlSetData($inputname, $array[1])
    If $array[2] = "," Then
        $array[2] = ","
    Else
        GUICtrlSetData($inputpass, $array[2])
        GUICtrlSetState($chkreconnect, $GUI_CHECKED)
    EndIf
    GUICtrlSetData($inputpass, $array[2])
    GUICtrlSetState($inputpass, $GUI_DISABLE)
    If $array[3] = "1" Then
        GUICtrlSetState($chkbuddylist, $GUI_CHECKED)
    Else
        GUICtrlSetState($chkbuddylist, $GUI_UNCHECKED)
    EndIf
    GUICtrlSetData($inputwelcome1, $array[6])
    GUICtrlSetData($inputwelcome2, $array[7])
    GUICtrlSetData($inputwelcome3, $array[8])
    GUISetState()
    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                Exit 0
            Case $msg = $chkreconnect
                GUICtrlSetState($inputpass, $GUI_ENABLE)
            Case $msg = $hash
                GUISetState(@SW_HIDE)
                Call("hashacard")
            Case $msg = $run
                $botname = GUICtrlRead($inputname)
                $msgbrdspam = "^qs^qv^qv BOT BUYING YOUR CARDS ^qv ALL CARDS ^qv ALL PRICES ^qv^qv^qv"
                $mktplcespam = "BOT BUYING CARDS FOR ALL PRICES FAST  FAIR"
                $1stwelcome = GUICtrlRead($inputwelcome1) & "{ENTER}"
                $2ndwelcome = GUICtrlRead($inputwelcome2) & "{ENTER}"
                $3rdwelcome = GUICtrlRead($inputwelcome3) & "{ENTER}"
                If GUICtrlRead($chkreconnect) = $GUI_CHECKED Then
                    $botpass = GUICtrlRead($inputpass)
                Else
                    $botpass = ""
                EndIf
                If GUICtrlRead($chkbuddylist) = $GUI_CHECKED Then
                    $buddylist = 154
                Else
                    $buddylist = 0
                EndIf
                GUISetState(@SW_HIDE)
                Call("firstlogin")
            Case $msg = $export
                GUISetState(@SW_HIDE)
                Call("export")
            Case $msg = $save
                $file = FileOpen("c:\program files\MTGbot\buysettings.dat", 2)
                FileWriteLine($file, GUICtrlRead($inputname))
                If GUICtrlRead($chkreconnect) = $GUI_CHECKED Then
                    FileWriteLine($file, GUICtrlRead($inputpass))
                Else
                    FileWriteLine($file, ",")
                EndIf
                FileWriteLine($file, GUICtrlRead($chkbuddylist))
                FileWriteLine($file, "empty")
                FileWriteLine($file, "empty")
                FileWriteLine($file, GUICtrlRead($inputwelcome1))
                FileWriteLine($file, GUICtrlRead($inputwelcome2))
                FileWriteLine($file, GUICtrlRead($inputwelcome3))
                FileClose($file)
                MsgBox(0, "", "saved")
        EndSelect
    WEnd
    

; ------------------------------------------ Functions ------------------------------------------------------

Func innerloop(); the main loop the bot runs when it isn't trading.
    Dim $lagtimer
    Dim $i = 1
    $cardcounter = 0
    While $i = 1
    ;if a trade request is recieved
        If PixelGetColor(786, 641) = 7917693 Then
        ;accept the trade and then..
            MouseClick("left", 786, 641)
        ; wait for the user to load in.
            $lagtimer = TimerInit()
            While TimerDiff($lagtimer) < 40000
            ;select the place where the second name will appear
                MouseClick("left", 1572, 1088)
            ;if the customer has loaded in, end the loop
                If PixelGetColor(1582, 1085) = 8224125 Then
                    ExitLoop
                EndIf
                Sleep(500)
            WEnd
        ;if the customer hasnt loaded into the trade within 40 seconds, exit the trade and restart the inner loop
            If TimerDiff($lagtimer) > 40000 Then
                MouseClick("left", 546, 1135)
                MouseClick("left", 1348, 1043)
                Call("innerloop")
            EndIf
        ;when they load in:
        ; close any open PM's
            Call("PM")
        ;close any open marketplace windows
            If PixelGetColor(697, 150) = 16776152 Then
                If PixelGetColor(709, 150) = 16770742 Then
                    If PixelGetColor(709, 162) = 9204540 Then
                        MouseClick("left", 685, 155)
                    EndIf
                EndIf
            EndIf
        ;close any open messageboard windows
            If PixelGetColor(757, 150) = 16776152 Then
                If PixelGetColor(769, 150) = 16770742 Then
                    MouseClick("left", 744, 157)
                EndIf
            EndIf
        ; copy the name to the clipboard
            Send("^c", 0)
        ;parse the name into a string
            $tradernametime = ClipGet()
        ;trim the funny character off the end
            $tradernametime = StringTrimRight($tradernametime, 1)
        ; if this name is the name of the bot
            If $tradernametime = $botname Then
            ; click the customer's name
                MouseClick("left", 1440, 1069)
            ;copy it onto the clipboard
                Send("^c", 0)
            ;parse it into a string
                $tradernametime = ClipGet()
            ;trim the funny character off the end
                $tradernametime = StringTrimRight($tradernametime, 1)
            ; set variable to true. used for later banning
                $nameabovebot = 1
            Else
            ;set variable to false. used for later banning
                $nameabovebot = 0
            EndIf
            If $tradernametime = "TraderBob{s}" Then
                Call("botowner")
            EndIf
        ; add the current date / time to the customers name, seperated with a comma
            $tradernametime = $tradernametime & "," & _NowCalc()
        ; if the log is empty add the name to the first position
            If $traderlog[0] = "0" Then
                $traderlog[0] = $tradernametime
            ; if the log isn't empty
            Else
            ;add it to the end of the log
                _ArrayAdd($traderlog, $tradernametime)
            ; sort the log
                _ArraySort($traderlog, 0, 0)
            ; check for old entries in the log
                oldentries($traderlog, 30)
            EndIf
        ; sort the log
            _ArraySort($traderlog, 0, 0)
        ;check the log for abuse
            tard_checker($traderlog, 6)
        ;send welcome message
            MouseClick("left", 546, 1135)
            Sleep(100)
            Send($1stwelcome, 0)
            Send($2ndwelcome, 0)
            Send($3rdwelcome, 0)
        ; set the filters to show number owned =<1
            MouseClick("left", 121, 70)
            Sleep(50)
            MouseClick("left", 207, 203)
            Sleep(50)
            MouseClick("left", 187, 235)
            Sleep(50)
            MouseClick("left", 248, 194)
            Sleep(50)
            MouseMove(255, 154)
            MouseDown("left")
            MouseUp("left")
            Sleep(50)
            MouseMove(190, 194)
            MouseDown("left")
            MouseUp("left")
            Sleep(50)
            MouseClick("left", 199, 72)
            Sleep(50)
        ;initialize a trade timer and enter the main loop
            $startoftrade = TimerInit()
            Call("trade")
        EndIf
    ;check to see if a 'withdrawn from trade' or 'after trade' message is onscreen and close it if nessecary
        Call("checkwithdraw")
    ;check for the new cards window and close it if nessecary
        Call("newcardscheck")
    ;check if a duel request is recieved and close it if nessecary
        Call("duel_request")
    ;check if a PM is recieved and tell them to enter a trade with you.
        Call("PM")
    ;check if the log contains old entries
        Call("checklogtimer")
    ;check if the bot has been disconnected from the server.
        Call("checkdisconnect")
    ; if you havnt spammed the marketplace in 62 seconds, do it again
        If TimerDiff($lastspam) > 62000 Then
        ;this will be replaced with the marketplace spam entered in the GUI
            Spam($mktplcespam)
            $lastspam = TimerInit()
        EndIf
        If TimerDiff($boardtimer) > 7200000 Then; if the marketplace ad has timed out, update it.
        ;this will be replaced with the trade message entered in the GUI.
            boardupdate($msgbrdspam)
            $boardtimer = TimerInit()
        EndIf
    ;delay to reduce CPU usage before looping again
        Sleep(1000)
    WEnd
EndFunc  ;==>innerloop
; the loop the bot runs when it is in a trade
Func trade()
    Call("intradecheck")
;check if a duel request is recieved, decline if nessecary
    Call("duel_request")
;check if a PM is recieved, tell them to enter a trade with you instead
    Call("PM")
;check to see if theyve been in the trade for longer than 5min.
    Call("tradetimer")
    $buystr = "I'm buying: "
;check if a card is present in the top left corner of the binder (look for a white / black / green border)
    If PixelGetColor(465, 120) = 16777215 Then
        Call("pullcards")
    ElseIf PixelGetColor(465, 120) = 0 Then
        Call("pullcards")
    ElseIf PixelGetColor(465, 120) = 65280 Then
        Call("pullcards")
    EndIf
; if they didnt have anything you wanted, exit the trade.
    If $cardcounter = 0 Then
    ;if they dont have cards you want marked tradable
    ; tell them
        MouseClick("left", 546, 1135)
        Sleep(100)
        Send("I can't see any cards that I need. If you have others for sale, please mark them tradable.{ENTER}", 0)
        $p = TimerInit()
    ;loop around for 8 seconds waiting for a card you want to appear. if it happens, rerun trade.
        While TimerDiff($p) < 8000
            If PixelGetColor(465, 120) = 16777215 Then
                Call("trade")
            ElseIf PixelGetColor(465, 120) = 0 Then
                Call("trade")
            ElseIf PixelGetColor(465, 120) = 65280 Then
                Call("trade")
            EndIf
            Call("intradecheck")
        ;check if a duel request is recieved, decline if nessecary
            Call("duel_request")
        ;check if a PM is recieved, tell them to enter a trade with you instead
            Call("PM")
        WEnd
    ;if they still havnt put cards up, exit the trade.
        MouseClick("left", 546, 1135)
        Sleep(100)
        Send("I still can't see any cards that I need. Thanks for trading with me.{ENTER}", 0)
        Sleep(2000)
        MouseClick("left", 1348, 1043)
        Call("innerloop")
    EndIf
    Call("ID_cards")
EndFunc  ;==>trade
;check for a duel request and decline it.
Func duel_request()
;if a duel request is recived, decline it.
    If PixelChecksum(637, 470, 772, 487) = 747246472 Then
        MouseClick("left", 928, 640)
    EndIf
EndFunc  ;==>duel_request
;check for a PM and tell them to enter a trade with you.
Func PM()
; loop around for all 49 possible PM window locations
    For $i = 1 To 49
    ; if a pm window is open
        If PixelGetColor((665+ ($i * 12)) , (112+ ($i * 18))) = 16776152 Then
            If PixelGetColor((677+ ($i * 12)) , (112+ ($i * 18))) = 16770742 Then
                If PixelGetColor((677+ ($i * 12)) , (124+ ($i * 18))) = 9204540 Then
                ;select it
                    MouseClick("left", (571+ ($i * 12)) , (117+ ($i * 18)))
                    Sleep(100)
                ;click the textbox
                    MouseClick("left", (526+ ($i * 12)) , (295+ ($i * 18)))
                    Sleep(100)
                ;tell the user to enter a trade instead
                    Send("I'm an automated bot that buys cards. Please open a trade if you want to sell me cards ^qs", 0); ask the user to send a trade request instead of a PM
                    If PixelGetColor(786, 641) = 7917693 Then
                        Call("innerloop")
                    EndIf
                    Send("{ENTER}", 0)
                    Sleep(1000)
                ;close the window
                    MouseClick("left", (678+ ($i * 12)) , (114+ ($i * 18)))
                    Sleep(1000)
                EndIf
            EndIf
        EndIf
    Next
    
EndFunc  ;==>PM
; spam the marketplace with an ad
Func Spam($a)
;if left = messageboard then click right
    If PixelChecksum(1221 - $buddylist, 1157, 1375 - $buddylist, 1169) = 3061995020 Then
        MouseClick("left", 1430 - $buddylist, 1159)
    Else
    ; if right = messageboard then click left.
        MouseClick("left", 1308 - $buddylist, 1161)
    EndIf
    Sleep(1000)
;spam it
    MouseMove(240, 371)
    MouseDown("left")
    MouseUp("left")
    Sleep(100)
    If $spamcounter = 1 Then
        Send("III " & $a & " III", 0)
        $spamcounter = $spamcounter + 1
    ElseIf $spamcounter = 2 Then
        Send("ZZZ " & $a & " ZZZ", 0)
        $spamcounter = $spamcounter + 1
    ElseIf $spamcounter = 3 Then
        Send("--- " & $a & " ---", 0)
        $spamcounter = $spamcounter + 1
    ElseIf $spamcounter = 4 Then
        Send("lll " & $a & " lll", 0)
        $spamcounter = $spamcounter + 1
    ElseIf $spamcounter = 5 Then
        Send("-+- " & $a & " -+-", 0)
        $spamcounter = 1
    EndIf
    If PixelGetColor(786, 641) = 7917693 Then
        Call("innerloop")
    EndIf
    Send("{ENTER}", 0)
    MouseMove(687, 156)
    MouseDown("left")
    MouseUp("left")
;update the timer
    $lastspam = TimerInit()
EndFunc  ;==>Spam
;check for old entries in the log every minute.
Func checklogtimer()
;if the log hasnt been checked in a minute, check it again
    If TimerDiff($logtimer) > 60000 Then
        oldentries($traderlog, 10)
    EndIf
EndFunc  ;==>checklogtimer
; remove old entries from the log if they are older than $b
Func oldentries(ByRef $a, $b)
; check for entries older than $b min
    Local $value
    Local $datetime
    Local $diff
    For $i = UBound($a) To 1 Step - 1
        $value = $a[ ($i - 1) ]
        $datetime = StringTrimLeft($value, StringInStr($value, ","))
        $diff = _DateDiff('n', $datetime, _NowCalc())
    ; if it is older than $b, delete it
        If $diff > $b Then
            if ($i - 1) = 0 Then
                $a[0] = "0"
            Else
                _ArrayDelete($a, ($i - 1))
            EndIf
        EndIf
        If $a[0] = "0" And UBound($a) > 1 Then
            _ArrayDelete($a, 0)
        EndIf
    Next
    Return ""
EndFunc  ;==>oldentries
;search the logs for abuse.
Func tard_checker($array, $MaxCount)
;if someone appears in the logs more than $maxcount, call the block function
    $MaxCount = $MaxCount - 1
    $name = get_name($array[0])
    $occurance = 0
    For $n = 1 To UBound($array) - 1
        If get_name($array[$n]) = $name Then
            $occurance = $occurance + 1
            If $occurance >= $MaxCount Then
                Call("block_user")
            EndIf
        Else
            $name = get_name($array[$n])
            $occurance = 0
        EndIf
    Next
EndFunc  ;==>tard_checker
; block a tard
Func block_user()
;if their name appears above yours, click the top name and block them
    If $nameabovebot = 1 Then
        MouseMove(1285, 1073)
        MouseDown("left")
        MouseUp("left")
        Sleep(100)
        MouseMove(1352, 1075)
        MouseDown("right")
        MouseUp("right")
        Sleep(100)
        MouseMove(1374, 1155)
        MouseDown("left")
        MouseUp("left")
        Sleep(100)
        MouseMove(1350, 1078)
        MouseDown("right")
        MouseUp("right")
        Sleep(100)
        MouseMove(1361, 1107)
        MouseDown("left")
        MouseUp("left")
        Sleep(100)
    ;if their name appears below yours, click the top name and block them
    Else
        MouseMove(1301, 1086)
        MouseDown("left")
        MouseUp("left")
        Sleep(100)
        MouseDown("right")
        MouseUp("right")
        Sleep(100)
        MouseMove(1322, 1161)
        MouseDown("left")
        MouseUp("left")
        Sleep(100)
        MouseMove(1290, 1092)
        MouseDown("right")
        MouseUp("right")
        Sleep(100)
        MouseMove(1311, 1107)
        MouseDown("left")
        MouseUp("left")
        Sleep(100)
    EndIf
; tell them they have been owned.
    MouseClick("left", 145, 304)
    Sleep(100)
    Send("You have been blocked for sending me excessive trade requests.{ENTER}", 0)
    MouseMove(688, 140)
    MouseDown("left")
    MouseUp("left")
    Sleep(100)
    MouseMove(1348, 1043)
    MouseDown("left")
    MouseUp("left")
EndFunc  ;==>block_user
;part of tard_checker
Func get_name($text)
    
    Local $items = StringSplit($text, $DELIMITER)
    Return $items[1]
EndFunc  ;==>get_name
;part of tard_checker
Func get_time($text)
    Local $items = StringSplit($text, $DELIMITER)
    Return $items[2]
EndFunc  ;==>get_time
;post your ad on the messageboard.
Func boardupdate($a)
    If PixelChecksum(1221 - $buddylist, 1157, 1375 - $buddylist, 1169) = 3061995020 Then;if left = messageboard then click left
        MouseClick("left", 1308 - $buddylist, 1161)
    Else;if right = messageboard then click right
        MouseClick("left", 1430 - $buddylist, 1159)
    EndIf
;spam $a message on the message board and minimize it.
    Sleep(1000)
    MouseMove(275, 468)
    MouseDown("left")
    MouseUp("left")
    Sleep(100)
    Send($a, 0)
    If PixelGetColor(786, 641) = 7917693 Then
        Call("innerloop")
    EndIf
    Send("{ENTER}", 0)
    MouseMove(745, 155)
    MouseDown("left")
    MouseUp("left")
    Sleep(1000)
    $boardtimer = TimerInit()
EndFunc  ;==>boardupdate
;check to see if there is a 'withdraw' prompt onscreen and close it if nessecary.
Func checkwithdraw()
;if a withdraw prompt is onscreen
    If PixelChecksum(637, 470, 772, 487) = 2078928619 Then
    ;close it
        MouseClick("left", 891, 633)
    EndIf
EndFunc  ;==>checkwithdraw
; calculate the selling price for the cards the user chose.
Func ID_cards()
    Dim $file, $line, $linearray[4], $tradestr, $buytotal = 0, $atimer, $tradeok = 1, $tradearray[3][32], $1mintimer
    For $i = 1 To 32
        Call("intradecheck")
    ;check if a duel request is recieved, decline if nessecary
        Call("duel_request")
    ;check if a PM is recieved, tell them to enter a trade with you instead
        Call("PM")
    ;check to see if theyve been in the trade for longer than 5min.
    ;generate a checksum for the top part of the card. store this in $traderarray[0][X]
        $tradearray[0][$i - 1] = PixelChecksum(156, (95+ (12 * $i)), 229, (106+ (12 * $i)))
        $file = FileOpen("c:\program files\MTGbot\botdata.csv", 0)
    ;Loop until end of file.
        While 1
            $line = FileReadLine($file)
            If @error = -1 Then ExitLoop
            $linearray = StringSplit($line, ",")
        ; if the checksum matches the checksum in the csv file, copy the price and name into $traderarray[1&2][x] and add to the total.
            If $linearray[1] = $tradearray[0][$i - 1] Then
                $tradearray[2][$i - 1] = $linearray [4]
                $buytotal = $buytotal + $tradearray[2][$i - 1]
                If $buytotal > 32 Then
                    $buytotal = $buytotal - $tradearray[2][$i - 1]
                    While 1
                        If PixelChecksum(156, (197+ (12* ($i - 1))), 229, (197+ (12* ($i - 1)))) = 1456332067 Then
                            ExitLoop
                        ElseIf PixelChecksum(156, (197+ (12* ($i - 1))), 229, (197+ (12* ($i - 1)))) = 14548993 Then
                            ExitLoop
                        ElseIf PixelChecksum(156, (197+ (12* ($i - 1))), 229, (197+ (12* ($i - 1)))) = 495143351 Then
                            ExitLoop
                            
                        EndIf
                        MouseClick("left", 195, (99+ (12 * $i)))
                        Sleep(200)
                    WEnd
                    ExitLoop 2
                EndIf
                $tradearray[1][$i - 1] = $linearray[2]
            EndIf
        WEnd
        If $tradearray[1][$i - 1] = "0" Then
            $tradearray[1][$i - 1] = "0"
        ; generate a transaction summary for the customer.
        ; if its the first time through the loop, don't put a comma between 'you have selected:' and the name of the first card.
        ElseIf $i = 1 Then
            $tradestr = $tradearray[1][$i - 1] & " for " & $tradearray[2][$i - 1]
        ; if it isn't the first time through, add a comma in between.
        Else
            $tradestr = $tradestr & " ," & $tradearray[1][$i - 1] & " for " & $tradearray[2][$i - 1]
        EndIf
        FileClose($file)
    Next
    $tradestr = $tradestr & " TOTAL = " & $buytotal & " Event Tickets."
    MouseClick("left", 546, 1135)
    Sleep(100)
    Send("I'm interested in buying these cards:{ENTER}", 0)
    Send($tradestr & "{ENTER}", 0)
    Send("Make any cards you don't want to sell for these prices untradable{ENTER}", 0)
    Send("or please take " & Int($buytotal) & " ticket(s) and confirm the trade.{ENTER}", 0)
    If PixelGetColor(465, 120) = 0 Then
        $morecards = 1
    ElseIf PixelGetColor(465, 120) = 16777215 Then
        $morecards = 1
    EndIf
    $atimer = TimerInit()
    tix(Int($buytotal), $atimer)
EndFunc  ;==>ID_cards

Func tradecheck($total, $1mintimer)
    Dim $tradearray[3][32], $file, $line, $newtotal, $linearray[4], $tradeok, $c, $notenoughtickets, $ticketcount
;perform the hashcheck again.
;loop around for each card in the trade window
    For $i = 1 To 32
        Call("intradecheck")
    ;check if a duel request is recieved, decline if nessecary
        Call("duel_request")
    ;check if a PM is recieved, tell them to enter a trade with you instead
        Call("PM")
    ;generate a checksum for the top part of the card. store this in $traderarray[0][X]
        $tradearray[0][$i - 1] = PixelChecksum(156, (95+ (12 * $i)), 229, (106+ (12 * $i)))
        $file = FileOpen("c:\program files\MTGbot\botdata.csv", 0)
    ;Loop until end of file.
        While 1
            $line = FileReadLine($file)
            If @error = -1 Then ExitLoop
            $linearray = StringSplit($line, ",")
        ; if the checksum matches the checksum in the csv file, copy the price and name into $traderarray[1&2][x] and add to the total.
            If $linearray[1] = $tradearray[0][$i - 1] Then
                $newtotal = $newtotal + $linearray[4]
            EndIf
        WEnd
        FileClose($file)
    Next
;if the trade is still the same
    If Int($newtotal) = $total Then
    ;and there are enough tickets in the trade
        $ticketcount = 0
        For $x = 1 To 32
            If PixelGetColor(50, (96+ ($x * 12))) = 1247493 Then
                $ticketcount = $ticketcount + 1
            Else
                ExitLoop
            EndIf
        Next
        If $ticketcount = $total Then
            confirm($total)
        ElseIf $ticketcount < $total Then
            MouseClick("left", 546, 1135)
            Sleep(100)
            Send("Please take " & ($total - $ticketcount) & " more event tickets and confirm the trade.{ENTER}", 0)
        ;unconfirm the customers trade.
            MouseMove(340, 41)
            MouseDown("left")
            MouseUp("left")
            Sleep(50)
            MouseMove(249, 219)
            MouseDown("left")
            MouseMove(249, 218)
            MouseUp("left")
            Sleep(50)
            MouseMove(159, 297)
            MouseDown("left")
            MouseUp("left")
            Sleep(50)
            MouseMove(547, 369)
            MouseDown("left")
            MouseUp("left")
            Sleep(50)
            MouseMove(547, 375)
            MouseDown("left")
            MouseUp("left")
            Sleep(50)
            MouseMove(448, 41)
            MouseDown("left")
            MouseUp("left")
            While PixelChecksum(57, 739, 115, 758) = 1600235646
                Sleep(50)
            WEnd
            tix($total, $1mintimer)
        ElseIf $ticketcount > $total Then
            MouseClick("left", 546, 1135)
            Sleep(100)
            Send("Please remove " & ($ticketcount - $total) & " event tickets and confirm the trade.{ENTER}", 0)
        ;unconfirm the customers trade.
            MouseMove(340, 41)
            MouseDown("left")
            MouseUp("left")
            Sleep(50)
            MouseMove(249, 219)
            MouseDown("left")
            MouseMove(249, 218)
            MouseUp("left")
            Sleep(50)
            MouseMove(159, 297)
            MouseDown("left")
            MouseUp("left")
            Sleep(50)
            MouseMove(547, 369)
            MouseDown("left")
            MouseUp("left")
            Sleep(50)
            MouseMove(547, 375)
            MouseDown("left")
            MouseUp("left")
            Sleep(50)
            MouseMove(448, 41)
            MouseDown("left")
            MouseUp("left")
            While PixelChecksum(57, 739, 115, 758) = 1600235646
                Sleep(50)
            WEnd
            tix($total, $1mintimer)
        EndIf
    Else
    ;inform the customer
        MouseClick("left", 546, 1135)
        Sleep(100)
        Send("You have removed some cards in the trade. Recalculating the trade.{ENTER}", 0)
    ;update $cardcounter to reflect the number of cards in the trade window
        $cardcounter = 0
        For $t = 1 To 32
            Call("intradecheck")
        ;check if a duel request is recieved, decline if nessecary
            Call("duel_request")
        ;check if a PM is recieved, tell them to enter a trade with you instead
            Call("PM")
            If PixelChecksum(156, (95+ ($t * 12)), 229, (95+ ($t * 12))) = 1456332067 Then
                $cardcounter = $cardcounter + 1
            ElseIf PixelChecksum(156, (95+ ($t * 12)), 229, (95+ ($t * 12))) = 14548993 Then
                $cardcounter = $cardcounter + 1
            Else
                ExitLoop
            EndIf
        Next
    ; if newtotal is less than 19, go back to the main trade loop. this may add new cards to the trade window.
    ; if its above 19, recalculate the trade instead.
        If $newtotal > 19 Then
            Call("ID_cards")
        Else
            Call("trade")
        EndIf
    EndIf
EndFunc  ;==>tradecheck
;complete the trade.
Func confirm($total)
    Dim $30sectimer, $10sectimer
    Call("intradecheck")
;check if a duel request is recieved, decline if nessecary
    Call("duel_request")
;check if a PM is recieved, tell them to enter a trade with you instead
    Call("PM")
;confirm the trade
    MouseMove(248, 742)
    MouseDown("left")
    MouseUp("left")
    Sleep(200)
    MouseMove(205, 764)
    MouseDown("left")
    MouseUp("left")
    Sleep(200)
    MouseMove(310, 1142)
    MouseDown("left")
    MouseUp("left")
    Sleep(200)
    $30sectimer = TimerInit()
    While TimerDiff($30sectimer) < 30000
    ;check for them removing cards
        tradechange($total)
    ;check to see if you are still in a trade, head back to inner loop if you arn't
        Call("intradecheck")
    ;check if a duel request is recieved, decline if nessecary
        Call("duel_request")
    ;check if a PM is recieved, tell them to enter a trade with you instead
        Call("PM")
    ; if the confirm trade button is onscreen
        If PixelChecksum(1219, 1028, 1374, 1037) = 2336066960 Then
        ;thank them
            MouseClick("left", 546, 1135)
            Sleep(100)
            Send("Thanks for selling some cards to me! ^qs{ENTER}", 0)
            If $morecards = 1 Then
                Send("I want to buy more cards from your collection. Please open a trade after this if you want to sell more cards.{ENTER}", 0)
                $morecards = 0
            EndIf
            Sleep(1000)
        ; click the trade button
            MouseClick("left", 1273, 1029)
            $10sectimer = TimerInit()
            While TimerDiff($10sectimer) < 10000
                Sleep(300)
            WEnd
        ;if they back out of the trade, go on to the next step
            If PixelGetColor(436, 35) = 6600129 Then
                ExitLoop
            EndIf
        EndIf
        Sleep(500)
    WEnd
; if still in a trade (customer didn't click it)
    If PixelGetColor(436, 35) = 6600129 Then
        MouseClick("left", 546, 1135)
        Sleep(100)
        Send("You aborted the trade. Recalculating.{ENTER}", 0)
    ;go back to the start of the trade loop
        Call("trade")
    Else
    ;trade has ended, so go back to the 'waiting for a trade' loop
        Call("innerloop")
    EndIf
EndFunc  ;==>confirm
;this checks for the new cards window, and closes it if nessecary.
Func newcardscheck()
;the window can be in 3 places. check for its presence and close it if nessecary.
    If PixelChecksum(321, 61, 386, 70) = 4069852983 Then
        If PixelChecksum(791, 59, 805, 72) = 182725946 Then
            MouseClick("left", 798, 65)
        ElseIf PixelChecksum(745, 59, 759, 72) = 182725946 Then
            MouseClick("left", 752, 65)
        ElseIf PixelChecksum(803, 59, 817, 72) = 182725946 Then
            MouseClick("left", 810, 65)
        EndIf
    EndIf
EndFunc  ;==>newcardscheck

Func tix($total, $1mintimer)
    Dim $ticketcount = 0
    While 1
    ;check to see if the trade has changed since the confirm button was clicked
        tradechange($total)
    ;check to see if you are still in a trade, head back to inner loop if you arn't
        Call("intradecheck")
    ;check if a duel request is recieved and decline if nessecary
        Call("duel_request")
    ;check if a PM is recieved, and tell them to open a trade
        Call("PM")
    ;if they have taken an event ticket, loop around until they select $total tickets
        If PixelChecksum(57, 739, 115, 758) = 1600235646 Then
            tradecheck($total, $1mintimer)
        EndIf
        If TimerDiff($1mintimer) > 60000 Then
            MouseClick("left", 385, 1141)
            Sleep(100)
            Send("You havn't confirmed the trade. Recalculating.{ENTER}", 0)
            Call("trade")
        EndIf
    WEnd
EndFunc  ;==>tix

Func tradechange($total)
    Dim $tradearray[3][32], $file, $line, $newtotal, $linearray[4], $10sectimer
    For $i = 1 To 32
    ;generate a checksum for the top part of the card. store this in $traderarray[0][X]
        $tradearray[0][$i - 1] = PixelChecksum(156, (95+ (12 * $i)), 229, (106+ (12 * $i)))
        $file = FileOpen("c:\program files\MTGbot\botdata.csv", 0)
    ;Loop until end of file.
        While 1
            $line = FileReadLine($file)
            If @error = -1 Then ExitLoop
            $linearray = StringSplit($line, ",")
        ; if the checksum matches the checksum in the csv file, copy the price into $traderarray[1&2][x] and add to the total.
            If $linearray[1] = $tradearray[0][$i - 1] Then
                $newtotal = $newtotal + $linearray[4]
            EndIf
        WEnd
        FileClose($file)
    Next
;if the trade has changed
    If Int($newtotal) <> $total Then
    ;inform the customer
        MouseClick("left", 546, 1135)
        Sleep(100)
        Send("You have removed some cards in the trade. Recalculating.{ENTER}", 0)
    ;update $cardcounter to reflect the number of cards in the trade window
        $cardcounter = 0
        For $t = 1 To 32
            If PixelChecksum(156, (95+ ($t * 12)), 229, (95+ ($t * 12))) = 1456332067 Then
                $cardcounter = $cardcounter + 1
            ElseIf PixelChecksum(156, (95+ ($t * 12)), 229, (95+ ($t * 12))) = 14548993 Then
                $cardcounter = $cardcounter + 1
            Else
                ExitLoop
            EndIf
        Next
    ; if newtotal is less than 19, go back to the main trade loop. this may add new cards to the trade window.
    ; if its above 19, recalculate the trade instead.
        If $newtotal > 19 Then
            Call("ID_cards")
        Else
            Call("trade")
        EndIf
    EndIf
EndFunc  ;==>tradechange
;used to close the bot by hitting esc.
Func Terminate()
;when escape is hit, stop the bot.
    MsgBox(0, "", "MTGbot stopped")

EndFunc  ;==>Terminate
;check if the bot is still in a trade. if not, return to the inner loop
Func intradecheck()
    If PixelGetColor(415, 36) = 0 Then
        Call("innerloop")
    EndIf
EndFunc  ;==>intradecheck
;if the bot gets disconnected, start the reconnection process
Func checkdisconnect()
;if the user refused to provide a password in the gui, end the function
    If $botpass = "" Then
        $botpass = ""
    ;if disconnected box is onscreen
    ElseIf PixelChecksum(637, 470, 857, 487) = 2808774430 Then
    ;close it
        MouseClick("left", 892, 631)
        Sleep(100)
        Call("dologin")
    EndIf
EndFunc  ;==>checkdisconnect
;try and log in
Func dologin()
;input username
    MouseClick("left", 764, 582)
    Sleep(100)
    Send($botname)
    Sleep(100)
;input password
    MouseClick("left", 760, 632)
    Sleep(100)
    Send($botpass)
    MouseClick("left", 800, 660)
;attempt to login
    Call("loginattempt")
EndFunc  ;==>dologin
;handle the login attempt
Func loginattempt()
    Dim $10sectimer, $logintimer
    $logintimer = TimerInit()
;loop round for 3min waiting for the login attempt.
    While TimerDiff($logintimer) < 180000
    ;if the 'no connection to server' error appears
        If PixelChecksum(622, 491, 976, 603) = 2151702803 Then
        ;close it
            MouseClick("left", 925, 678)
            Sleep(100)
        ;erase the username field
            MouseClick("left", 764, 582)
            Sleep(100)
            $10sectimer = TimerInit()
            While TimerDiff($10sectimer) < 4000
                Send("{BACKSPACE}", 0)
                Sleep(10)
            WEnd
            $10sectimer = TimerInit()
            While TimerDiff($10sectimer) < 4000
                Send("{DELETE}", 0)
                Sleep(10)
            WEnd
        ;erase the password field
            Sleep(200)
            MouseClick("left", 760, 632)
            Sleep(100)
            $10sectimer = TimerInit()
            While TimerDiff($10sectimer) < 4000
                Send("{BACKSPACE}", 0)
                Sleep(10)
            WEnd
            $10sectimer = TimerInit()
            While TimerDiff($10sectimer) < 4000
                Send("{DELETE}", 0)
                Sleep(10)
            WEnd
            Sleep(200)
        ;try to login again
            Call("dologin")
        ElseIf PixelChecksum(131, 61, 203, 70) = 2666305482 Then
        ;if MTGO has logged in
        ;open the marketplace and message board
            Call("firstlogin")
        ; if the 'this user is allready logged in' box appears
        ElseIf PixelChecksum(654, 532, 962, 541) = 2905472228 Then
        ; close it
            MouseClick("left", 809, 647)
            Sleep(200)
        ;erase the username field
            MouseClick("left", 764, 582)
            Sleep(100)
            $10sectimer = TimerInit()
            While TimerDiff($10sectimer) < 4000
                Send("{BACKSPACE}", 0)
                Sleep(10)
            WEnd
            $10sectimer = TimerInit()
            While TimerDiff($10sectimer) < 4000
                Send("{DELETE}", 0)
                Sleep(10)
            WEnd
            Sleep(200)
        ;erase the password field
            MouseClick("left", 760, 632)
            Sleep(100)
            $10sectimer = TimerInit()
            While TimerDiff($10sectimer) < 4000
                Send("{BACKSPACE}", 0)
                Sleep(10)
            WEnd
            $10sectimer = TimerInit()
            While TimerDiff($10sectimer) < 4000
                Send("{DELETE}", 0)
                Sleep(10)
            WEnd
            Sleep(200)
        ;try to login again
            Call("dologin")
        EndIf
        Sleep(5000)
    WEnd
; if after 3 minutes you still havn't logged in, try again
    Call("dologin")
EndFunc  ;==>loginattempt
;this function opens the marketplace and message board, spams the message board and runs the bot.
Func firstlogin()
    Dim $y = 1, $z = 1
; if MTGO is sitting on the 'main room'
    If PixelChecksum(131, 61, 203, 70) = 2666305482 Then
    ;click the trade button
        MouseClick("left", 618, 567)
    ;loop around waiting for it to appear
        While PixelChecksum(131, 61, 203, 70) = 2666305482
            Sleep(500)
        WEnd
    ;open the message board
        MouseClick("left", 835, 531)
    ;loop around waiting for it to appear
        While $y = 1
        ;when it does appear, minimize it and exitloop
            If PixelGetColor(274, 460) = 9802661 Then
                MouseClick("left", 745, 157)
                ExitLoop
            EndIf
        WEnd
    ;open the marketplace
        MouseClick("left", 1043, 554)
    ;wait for it to appear
        While $z = 1
        ;when it does appear, minimize it and exitloop
            If PixelGetColor(182, 371) = 9802661 Then
                MouseClick("left", 683, 151)
                Sleep(2000)
                ExitLoop
            EndIf
        WEnd
        Sleep(200)
    ;update the message board
        boardupdate($msgbrdspam)
    ;start the bots inner loop.
        Call("innerloop")
    EndIf
EndFunc  ;==>firstlogin
; this function generates a checksum for the card in the 'you get' trade window.

; this function generates a checksum for the card in the 'you get' trade window.
Func hashacard()
    Dim $inputstr, $line, $file, $i = 1
    $file = FileOpen("c:\program files\MTGbot\botdata.csv", 1)
    While $i = 1
    ; ask the user to enter the card name, selling price and buying price
        $inputstr = InputBox("card details", "enter the card name,selling price,buying price seperated by commas. Make sure the card you want to hash is visibile in the 'you get' trade box.")
        If @error = 1 Then
            Call("Terminate")
        EndIf
    ; write the hash,name,sellprice,buyprice to the end of the bot datafile.
        $line = PixelChecksum(156, 107, 229, 118) & "," & $inputstr
        FileWriteLine($file, $line)
    WEnd
    FileClose($file)

EndFunc  ;==>hashacard
; this function exports the bots collection to owned.csv
Func export()
; select the collection tab
    MouseClick("left", 353, 40)
    Sleep(100)
;reset all filters
    MouseClick("left", 215, 340)
;change the filter to rare cards.
    MouseMove(256, 225)
    MouseDown("left")
    MouseUp("left")
    Sleep(100)
    MouseMove(213, 291)
    MouseDown("left")
    MouseUp("left")
    Sleep(100)
;sort by set, collector number.
    MouseMove(248, 266)
    MouseDown("left")
    Sleep(100)
    MouseMove(200, 300)
    MouseDown("left")
    MouseUp("left")
    Sleep(100)
; if the collection isnt on the text style display, click the button to change to the text display.
    if (PixelChecksum(1564, 59, 1584, 72)) = 1694229323 Then
        MouseMove(1579, 69)
        MouseDown("left")
        MouseUp("left")
        Sleep(100)
    EndIf
; right click
    MouseMove(392, 150)
    MouseDown("right")
; seleect all
    MouseMove(387, 152)
    MouseUp("right")
    Sleep(100)
    MouseMove(412, 180)
    MouseDown("left")
    MouseUp("left")
    Sleep(100)
;export as csv
    MouseMove(399, 187)
    MouseDown("right")
    MouseUp("right")
    Sleep(100)
    MouseMove(428, 232)
    MouseDown("left")
    MouseUp("left")
    Sleep(100)
    WinWait("Export as CSV", "")
    If Not WinActive("Export as CSV", "") Then WinActivate("Export as CSV", "")
    WinWaitActive("Export as CSV", "")
; save as owned.csv
    Send("owned.csv")
    MouseMove(507, 398)
    MouseDown("left")
    MouseUp("left")
    Sleep(100)
    WinWait("Magic Online V2.0.001.522", "")
    If Not WinActive("Magic Online V2.0.001.522", "") Then WinActivate("Magic Online V2.0.001.522", "")
    WinWaitActive("Magic Online V2.0.001.522", "")
;close prompt
    MouseMove(789, 645)
    MouseDown("left")
    MouseUp("left")
    Sleep(100)
    MsgBox(0, "", "export completed")

EndFunc  ;==>export

Func pullcards()
    Dim $z = 1, $crdpixl
    While $z = 1
        $crdpixl = PixelGetColor(465, 120)
        If $crdpixl = 16777215 Then
            $cardcounter = $cardcounter + 1
            If $cardcounter < 32 Then
                MouseClick("left", 533, 202)
            EndIf
        ElseIf $crdpixl = 0 Then
            $cardcounter = $cardcounter + 1
            If $cardcounter < 32 Then
                MouseClick("left", 533, 202)
            EndIf
        ElseIf $crdpixl = 65280 Then
            $cardcounter = $cardcounter + 1
            If $cardcounter < 32 Then
                MouseClick("left", 533, 202)
            EndIf
        Else
            Sleep(200)
            Call("trade")
        EndIf
    ;check if a duel request is recieved and decline if nessecary
        Call("duel_request")
    ;check if a PM is recieved and tell them to enter a trade
        Call("PM")
    ;check to see if you are still in the trade.
        Call("intradecheck")
        MouseMove(376, 130, 3)
    WEnd
EndFunc  ;==>pullcards

Func tradetimer()
    If TimerDiff($startoftrade) > 300000 Then
        MouseClick("left", 385, 1141)
        Sleep(100)
        Send("You have been inactive for five minutes. If you want to sell cards to me you'll need to send another trade request.{ENTER}", 0)
        Send(" Now closing inactive trade{ENTER}", 0)
        Sleep(2000)
        MouseClick("left", 1348, 1043)
        Call("innerloop")
    EndIf
EndFunc  ;==>tradetimer

Func botowner()
    Dim $i = 1
; if the bot owner trades with the bot
; filter all cards where number owned > 1
    MouseClick("left", 331, 39)
    Sleep(100)
    MouseMove(214, 332)
    MouseDown("left")
    MouseUp("left")
    Sleep(100)
    MouseMove(254, 169)
    MouseDown("left")
    MouseUp("left")
    Sleep(100)
    MouseMove(250, 136)
    MouseDown("left")
    MouseUp("left")
    Sleep(100)
    MouseMove(167, 164)
    MouseDown("left")
    MouseUp("left")
    Sleep(100)
    MouseMove(917, 259)
    MouseDown("right")
    MouseMove(916, 259)
    MouseUp("right")
    Sleep(100)
    MouseMove(938, 289)
    MouseDown("left")
    MouseUp("left")
    Sleep(100)
    MouseClick("left", 433, 37)
    Sleep(100)
    Call("ticketfilter")
    Call("pulltix")
;wait here for the owner to confirm the trade.
    While $i = 1
        If PixelChecksum(57, 739, 115, 758) = 1600235646 Then
            ExitLoop
        Else
            Sleep(100)
        EndIf
    WEnd
;confirm the trade
    MouseMove(248, 742)
    MouseDown("left")
    MouseUp("left")
    Sleep(200)
    MouseMove(205, 764)
    MouseDown("left")
    MouseUp("left")
    Sleep(200)
    MouseMove(310, 1142)
    MouseDown("left")
    MouseUp("left")
    Sleep(100)
    $30sectimer = TimerInit()
    While TimerDiff($30sectimer) < 30000
    ; if the confirm trade button is onscreen
        If PixelChecksum(1219, 1028, 1374, 1037) = 2336066960 Then
        ; click the trade button
            MouseClick("left", 1273, 1029)
            ExitLoop
        EndIf
        Sleep(100)
    WEnd
    Sleep(10000)
    Send("{ENTER}", 0)
    Call("newcardscheck")
; make all the cards in your collection untradable.
    MouseMove(220, 341)
    MouseDown("left")
    MouseMove(220, 342)
    MouseUp("left")
    Sleep(100)
    MouseMove(251, 130)
    MouseDown("left")
    MouseUp("left")
    Sleep(100)
    MouseMove(177, 176)
    MouseDown("left")
    MouseUp("left")
    Sleep(100)
    MouseMove(938, 311)
    MouseDown("right")
    MouseUp("right")
    Sleep(100)
    MouseMove(987, 362)
    MouseDown("left")
    MouseUp("left")
    Sleep(100)
; make all your event tickets tradable.
    MouseMove(214, 341)
    MouseDown("left")
    MouseUp("left")
    Sleep(100)
    MouseMove(245, 134)
    MouseDown("left")
    MouseUp("left")
    Sleep(100)
    MouseMove(180, 211)
    MouseDown("left")
    MouseUp("left")
    Sleep(100)
    MouseMove(927, 340)
    MouseDown("right")
    MouseMove(927, 339)
    MouseUp("right")
    Sleep(100)
    MouseMove(947, 374)
    MouseDown("left")
    MouseUp("left")
    Sleep(100)
    Call("innerloop")
EndFunc  ;==>botowner

Func ticketfilter()
;filter to show boosters
    MouseMove(125, 78)
    MouseDown("left")
    MouseUp("left")
    Sleep(100)
    MouseMove(246, 345)
    MouseDown("left")
    MouseMove(245, 345)
    MouseUp("left")
    Sleep(100)
    MouseMove(251, 160)
    MouseDown("left")
    MouseUp("left")
    Sleep(100)
    MouseMove(189, 209)
    MouseDown("left")
    MouseUp("left")
    Sleep(100)
    MouseMove(135, 311)
    MouseDown("left")
    MouseUp("left")
    Sleep(100)
;search for 'event'
    Send("event{ENTER}")
;switch back to the trade box
    MouseMove(195, 76)
    MouseDown("left")
    MouseUp("left")
    Sleep(100)
EndFunc  ;==>ticketfilter

Func pulltix()
    Do
        While PixelChecksum(481, 122, 586, 139) = 366956196
            MouseClick("left", 529, 252)
            MouseMove(427, 159)
            Sleep(100)
        WEnd
        Sleep(1000)
    Until Not PixelChecksum(481, 122, 586, 139) = 366956196
EndFunc  ;==>pulltix

check that out

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

That works.

while checking something twice with pixelchecksum seems redundant I need to allow for lag.

I have a main loop - innerloop that runs while the bot isn't in a trade. It advertises in the marketplace and waits for a trade request. When one arrives, trade() is run.

The main problem is that the customer can leave the trade at any time during these functions:

trade

id_cards

tradecheck

tradechange

pullcards

confirm

tix

when this happens, the bot needs to go back to 'innerloop'. I was using the function "intradecheck" for this, which called innerloop if the customer left the trade. Over time this exceeds the 384 recursion limit. I need to modify the program so that if pixelgetcolor(415,36) becomes 0 at any time, the bot needs to:

1. stop whatever it is doing

2. end the function its currently in

3. return to the function that originally called it

4. go to 2 until it gets back to the innerloop.

5. continue with the innerloop as normal.

With the number of functions I have, this is proving to be a headache. I think i'm going to need to rewrite the functions like this:

func FUNCNAME()
if pixelgetcolor(415,36) <> 0 then
; SNIP: code for the function
endif
endfunc

if they exit the trade, the function will end and then return to whatever called it.

Edited by The_Lorax

Share this post


Link to post
Share on other sites

The main problem is that the customer can leave the trade at any times during these functions:

trade

id_cards

tradecheck

tradechange

pullcards

confirm

tix

when this happens, the bot needs to go back to 'innerloop'. I was just using call("innerloop") for this, which of course caused the recursion problem. Now I need to modify the program so that if pixelgetcolor(415,36) becomes 0 at any time, the bot needs to:

1. stop whatever it is doing

2. end the function its currently in

3. return to the function that originally called it

4. keep doing 2 until it gets back to the innerloop.

5. continue with the innerloop as normal.

this should do the trick.... place this throughout the functions to return to the interloop.... but not in the interloop

If PixelGetColor(415, 36) = 0 Then Return

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

the return statement!

I feel so stupid!

thanks - now to make the changes.

Share this post


Link to post
Share on other sites

replaced all of the Call("innerloop")

with $Call_innerloop = 0 (or 1 to call it from the body)

#include <Array.au3>
#include <Date.au3>
#include <GuiConstants.au3>
HotKeySet("{ESC}", "Terminate")
Dim $tradernametime, $traderlog[1], $logtimer, $boardtimer, $lastspam = TimerInit(), $startoftrade, $nameabovebot = 0, $botname, $botpass, $msgbrdspam, $mktplcespam, $1stwelcome, $2ndwelcome, $3rdwelcome, $buddylist = 0, $morecards = 0, $cardcounter, $spamcounter = 1
Const $DELIMITER = ","

Dim $Call_interloop = 0

    Dim $line, $file, $i = 1, $array[1], $b, $buttonval
    GUICreate("MTGbot Control Panel", 520, 367, (@DesktopWidth - 520) / 2, (@DesktopHeight - 367) / 2)
    $save = GUICtrlCreateButton("Save Settings", 40, 330, 90, 30)
    $export = GUICtrlCreateButton("Export Collection", 140, 330, 110, 30)
    $hash = GUICtrlCreateButton("Hash Cards", 260, 330, 70, 30)
    $run = GUICtrlCreateButton("Run Bot", 340, 330, 70, 30)
    $inputname = GUICtrlCreateInput("Name", 120, 10, 390, 20)
    $Label_30 = GUICtrlCreateLabel("Botname", 10, 10, 80, 20)
    $Label_31 = GUICtrlCreateLabel("Password", 10, 40, 80, 20)
    $inputpass = GUICtrlCreateInput("Password", 120, 40, 390, 20)
    $chkreconnect = GUICtrlCreateCheckbox("I want MTGbot to reconnect on disconnection", 10, 70, 240, 20)
    $chkbuddylist = GUICtrlCreateCheckbox("The bot has a buddylist", 10, 100, 130, 20)
    $Label_39 = GUICtrlCreateLabel("Welcome Message", 10, 200, 100, 20)
    $inputwelcome1 = GUICtrlCreateInput("Line 1", 120, 230, 390, 20)
    $inputwelcome2 = GUICtrlCreateInput("Line 2", 120, 260, 390, 20)
    $inputwelcome3 = GUICtrlCreateInput("Line 3", 120, 290, 390, 20)
    $Label_43 = GUICtrlCreateLabel("Line 1", 10, 230, 60, 20)
    $Label_44 = GUICtrlCreateLabel("Line 2", 10, 260, 60, 20)
    $Label_45 = GUICtrlCreateLabel("Line 3", 10, 290, 60, 20)
    $file = FileOpen("c:\program files\MTGbot\buysettings.dat", 0)
    While $i = 1
    ;read a line
        $line = FileReadLine($file)
        If @error = -1 Then
            ExitLoop
        EndIf
    ;split it into a temporary array
        _ArrayAdd($array, $line)
    WEnd
    GUICtrlSetData($inputname, $array[1])
    If $array[2] = "," Then
        $array[2] = ","
    Else
        GUICtrlSetData($inputpass, $array[2])
        GUICtrlSetState($chkreconnect, $GUI_CHECKED)
    EndIf
    GUICtrlSetData($inputpass, $array[2])
    GUICtrlSetState($inputpass, $GUI_DISABLE)
    If $array[3] = "1" Then
        GUICtrlSetState($chkbuddylist, $GUI_CHECKED)
    Else
        GUICtrlSetState($chkbuddylist, $GUI_UNCHECKED)
    EndIf
    GUICtrlSetData($inputwelcome1, $array[6])
    GUICtrlSetData($inputwelcome2, $array[7])
    GUICtrlSetData($inputwelcome3, $array[8])
    GUISetState()
    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                Exit 0
            Case $msg = $chkreconnect
                GUICtrlSetState($inputpass, $GUI_ENABLE)
            Case $msg = $hash
                GUISetState(@SW_HIDE)
                Call("hashacard")
            Case $msg = $run
                $botname = GUICtrlRead($inputname)
                $msgbrdspam = "^qs^qv^qv BOT BUYING YOUR CARDS ^qv ALL CARDS ^qv ALL PRICES ^qv^qv^qv"
                $mktplcespam = "BOT BUYING CARDS FOR ALL PRICES FAST  FAIR"
                $1stwelcome = GUICtrlRead($inputwelcome1) & "{ENTER}"
                $2ndwelcome = GUICtrlRead($inputwelcome2) & "{ENTER}"
                $3rdwelcome = GUICtrlRead($inputwelcome3) & "{ENTER}"
                If GUICtrlRead($chkreconnect) = $GUI_CHECKED Then
                    $botpass = GUICtrlRead($inputpass)
                Else
                    $botpass = ""
                EndIf
                If GUICtrlRead($chkbuddylist) = $GUI_CHECKED Then
                    $buddylist = 154
                Else
                    $buddylist = 0
                EndIf
                GUISetState(@SW_HIDE)
                Call("firstlogin")
            Case $msg = $export
                GUISetState(@SW_HIDE)
                Call("export")
            Case $msg = $save
                $file = FileOpen("c:\program files\MTGbot\buysettings.dat", 2)
                FileWriteLine($file, GUICtrlRead($inputname))
                If GUICtrlRead($chkreconnect) = $GUI_CHECKED Then
                    FileWriteLine($file, GUICtrlRead($inputpass))
                Else
                    FileWriteLine($file, ",")
                EndIf
                FileWriteLine($file, GUICtrlRead($chkbuddylist))
                FileWriteLine($file, "empty")
                FileWriteLine($file, "empty")
                FileWriteLine($file, GUICtrlRead($inputwelcome1))
                FileWriteLine($file, GUICtrlRead($inputwelcome2))
                FileWriteLine($file, GUICtrlRead($inputwelcome3))
                FileClose($file)
                MsgBox(0, "", "saved")
            EndSelect
    If $Call_interloop = 1 Then
        $Call_interloop = 0
        Call("innerloop")
    EndIf
    WEnd
    

; ------------------------------------------ Functions ------------------------------------------------------

Func innerloop(); the main loop the bot runs when it isn't trading.
    Dim $lagtimer
    Dim $i = 1
    $cardcounter = 0
    While $i = 1
    ;if a trade request is recieved
        If PixelGetColor(786, 641) = 7917693 Then
        ;accept the trade and then..
            MouseClick("left", 786, 641)
        ; wait for the user to load in.
            $lagtimer = TimerInit()
            While TimerDiff($lagtimer) < 40000
            ;select the place where the second name will appear
                MouseClick("left", 1572, 1088)
            ;if the customer has loaded in, end the loop
                If PixelGetColor(1582, 1085) = 8224125 Then
                    ExitLoop
                EndIf
                Sleep(500)
            WEnd
        ;if the customer hasnt loaded into the trade within 40 seconds, exit the trade and restart the inner loop
            If TimerDiff($lagtimer) > 40000 Then
                MouseClick("left", 546, 1135)
                MouseClick("left", 1348, 1043)
                $Call_interloop = 1
                Return
            EndIf
        ;when they load in:
        ; close any open PM's
            Call("PM")
        ;close any open marketplace windows
            If PixelGetColor(697, 150) = 16776152 Then
                If PixelGetColor(709, 150) = 16770742 Then
                    If PixelGetColor(709, 162) = 9204540 Then
                        MouseClick("left", 685, 155)
                    EndIf
                EndIf
            EndIf
        ;close any open messageboard windows
            If PixelGetColor(757, 150) = 16776152 Then
                If PixelGetColor(769, 150) = 16770742 Then
                    MouseClick("left", 744, 157)
                EndIf
            EndIf
        ; copy the name to the clipboard
            Send("^c", 0)
        ;parse the name into a string
            $tradernametime = ClipGet()
        ;trim the funny character off the end
            $tradernametime = StringTrimRight($tradernametime, 1)
        ; if this name is the name of the bot
            If $tradernametime = $botname Then
            ; click the customer's name
                MouseClick("left", 1440, 1069)
            ;copy it onto the clipboard
                Send("^c", 0)
            ;parse it into a string
                $tradernametime = ClipGet()
            ;trim the funny character off the end
                $tradernametime = StringTrimRight($tradernametime, 1)
            ; set variable to true. used for later banning
                $nameabovebot = 1
            Else
            ;set variable to false. used for later banning
                $nameabovebot = 0
            EndIf
            If $tradernametime = "TraderBob{s}" Then
                Call("botowner")
            EndIf
        ; add the current date / time to the customers name, seperated with a comma
            $tradernametime = $tradernametime & "," & _NowCalc()
        ; if the log is empty add the name to the first position
            If $traderlog[0] = "0" Then
                $traderlog[0] = $tradernametime
            ; if the log isn't empty
            Else
            ;add it to the end of the log
                _ArrayAdd($traderlog, $tradernametime)
            ; sort the log
                _ArraySort($traderlog, 0, 0)
            ; check for old entries in the log
                oldentries($traderlog, 30)
            EndIf
        ; sort the log
            _ArraySort($traderlog, 0, 0)
        ;check the log for abuse
            tard_checker($traderlog, 6)
        ;send welcome message
            MouseClick("left", 546, 1135)
            Sleep(100)
            Send($1stwelcome, 0)
            Send($2ndwelcome, 0)
            Send($3rdwelcome, 0)
        ; set the filters to show number owned =<1
            MouseClick("left", 121, 70)
            Sleep(50)
            MouseClick("left", 207, 203)
            Sleep(50)
            MouseClick("left", 187, 235)
            Sleep(50)
            MouseClick("left", 248, 194)
            Sleep(50)
            MouseMove(255, 154)
            MouseDown("left")
            MouseUp("left")
            Sleep(50)
            MouseMove(190, 194)
            MouseDown("left")
            MouseUp("left")
            Sleep(50)
            MouseClick("left", 199, 72)
            Sleep(50)
        ;initialize a trade timer and enter the main loop
            $startoftrade = TimerInit()
            Call("trade")
        EndIf
    ;check to see if a 'withdrawn from trade' or 'after trade' message is onscreen and close it if nessecary
        Call("checkwithdraw")
    ;check for the new cards window and close it if nessecary
        Call("newcardscheck")
    ;check if a duel request is recieved and close it if nessecary
        Call("duel_request")
    ;check if a PM is recieved and tell them to enter a trade with you.
        Call("PM")
    ;check if the log contains old entries
        Call("checklogtimer")
    ;check if the bot has been disconnected from the server.
        Call("checkdisconnect")
    ; if you havnt spammed the marketplace in 62 seconds, do it again
        If TimerDiff($lastspam) > 62000 Then
        ;this will be replaced with the marketplace spam entered in the GUI
            Spam($mktplcespam)
            $lastspam = TimerInit()
        EndIf
        If TimerDiff($boardtimer) > 7200000 Then; if the marketplace ad has timed out, update it.
        ;this will be replaced with the trade message entered in the GUI.
            boardupdate($msgbrdspam)
            $boardtimer = TimerInit()
        EndIf
    ;delay to reduce CPU usage before looping again
        Sleep(1000)
    WEnd
EndFunc  ;==>innerloop
; the loop the bot runs when it is in a trade
Func trade()
    Call("intradecheck")
;check if a duel request is recieved, decline if nessecary
    Call("duel_request")
;check if a PM is recieved, tell them to enter a trade with you instead
    Call("PM")
;check to see if theyve been in the trade for longer than 5min.
    Call("tradetimer")
    $buystr = "I'm buying: "
;check if a card is present in the top left corner of the binder (look for a white / black / green border)
    If PixelGetColor(465, 120) = 16777215 Then
        Call("pullcards")
    ElseIf PixelGetColor(465, 120) = 0 Then
        Call("pullcards")
    ElseIf PixelGetColor(465, 120) = 65280 Then
        Call("pullcards")
    EndIf
; if they didnt have anything you wanted, exit the trade.
    If $cardcounter = 0 Then
    ;if they dont have cards you want marked tradable
    ; tell them
        MouseClick("left", 546, 1135)
        Sleep(100)
        Send("I can't see any cards that I need. If you have others for sale, please mark them tradable.{ENTER}", 0)
        $p = TimerInit()
    ;loop around for 8 seconds waiting for a card you want to appear. if it happens, rerun trade.
        While TimerDiff($p) < 8000
            If PixelGetColor(465, 120) = 16777215 Then
                Call("trade")
            ElseIf PixelGetColor(465, 120) = 0 Then
                Call("trade")
            ElseIf PixelGetColor(465, 120) = 65280 Then
                Call("trade")
            EndIf
            Call("intradecheck")
        ;check if a duel request is recieved, decline if nessecary
            Call("duel_request")
        ;check if a PM is recieved, tell them to enter a trade with you instead
            Call("PM")
        WEnd
    ;if they still havnt put cards up, exit the trade.
        MouseClick("left", 546, 1135)
        Sleep(100)
        Send("I still can't see any cards that I need. Thanks for trading with me.{ENTER}", 0)
        Sleep(2000)
        MouseClick("left", 1348, 1043)
        $Call_interloop = 1
        Return
    EndIf
    Call("ID_cards")
EndFunc  ;==>trade
;check for a duel request and decline it.
Func duel_request()
;if a duel request is recived, decline it.
    If PixelChecksum(637, 470, 772, 487) = 747246472 Then
        MouseClick("left", 928, 640)
    EndIf
EndFunc  ;==>duel_request
;check for a PM and tell them to enter a trade with you.
Func PM()
; loop around for all 49 possible PM window locations
    For $i = 1 To 49
    ; if a pm window is open
        If PixelGetColor((665+ ($i * 12)) , (112+ ($i * 18))) = 16776152 Then
            If PixelGetColor((677+ ($i * 12)) , (112+ ($i * 18))) = 16770742 Then
                If PixelGetColor((677+ ($i * 12)) , (124+ ($i * 18))) = 9204540 Then
                ;select it
                    MouseClick("left", (571+ ($i * 12)) , (117+ ($i * 18)))
                    Sleep(100)
                ;click the textbox
                    MouseClick("left", (526+ ($i * 12)) , (295+ ($i * 18)))
                    Sleep(100)
                ;tell the user to enter a trade instead
                    Send("I'm an automated bot that buys cards. Please open a trade if you want to sell me cards ^qs", 0); ask the user to send a trade request instead of a PM
                    If PixelGetColor(786, 641) = 7917693 Then
                        $Call_interloop = 0
                        Return
                    EndIf
                    Send("{ENTER}", 0)
                    Sleep(1000)
                ;close the window
                    MouseClick("left", (678+ ($i * 12)) , (114+ ($i * 18)))
                    Sleep(1000)
                EndIf
            EndIf
        EndIf
    Next
    
EndFunc  ;==>PM
; spam the marketplace with an ad
Func Spam($a)
;if left = messageboard then click right
    If PixelChecksum(1221 - $buddylist, 1157, 1375 - $buddylist, 1169) = 3061995020 Then
        MouseClick("left", 1430 - $buddylist, 1159)
    Else
    ; if right = messageboard then click left.
        MouseClick("left", 1308 - $buddylist, 1161)
    EndIf
    Sleep(1000)
;spam it
    MouseMove(240, 371)
    MouseDown("left")
    MouseUp("left")
    Sleep(100)
    If $spamcounter = 1 Then
        Send("III " & $a & " III", 0)
        $spamcounter = $spamcounter + 1
    ElseIf $spamcounter = 2 Then
        Send("ZZZ " & $a & " ZZZ", 0)
        $spamcounter = $spamcounter + 1
    ElseIf $spamcounter = 3 Then
        Send("--- " & $a & " ---", 0)
        $spamcounter = $spamcounter + 1
    ElseIf $spamcounter = 4 Then
        Send("lll " & $a & " lll", 0)
        $spamcounter = $spamcounter + 1
    ElseIf $spamcounter = 5 Then
        Send("-+- " & $a & " -+-", 0)
        $spamcounter = 1
    EndIf
    If PixelGetColor(786, 641) = 7917693 Then
        $Call_interloop = 0
        Return
    EndIf
    Send("{ENTER}", 0)
    MouseMove(687, 156)
    MouseDown("left")
    MouseUp("left")
;update the timer
    $lastspam = TimerInit()
EndFunc  ;==>Spam
;check for old entries in the log every minute.
Func checklogtimer()
;if the log hasnt been checked in a minute, check it again
    If TimerDiff($logtimer) > 60000 Then
        oldentries($traderlog, 10)
    EndIf
EndFunc  ;==>checklogtimer
; remove old entries from the log if they are older than $b
Func oldentries(ByRef $a, $b)
; check for entries older than $b min
    Local $value
    Local $datetime
    Local $diff
    For $i = UBound($a) To 1 Step - 1
        $value = $a[ ($i - 1) ]
        $datetime = StringTrimLeft($value, StringInStr($value, ","))
        $diff = _DateDiff('n', $datetime, _NowCalc())
    ; if it is older than $b, delete it
        If $diff > $b Then
            if ($i - 1) = 0 Then
                $a[0] = "0"
            Else
                _ArrayDelete($a, ($i - 1))
            EndIf
        EndIf
        If $a[0] = "0" And UBound($a) > 1 Then
            _ArrayDelete($a, 0)
        EndIf
    Next
    Return ""
EndFunc  ;==>oldentries
;search the logs for abuse.
Func tard_checker($array, $MaxCount)
;if someone appears in the logs more than $maxcount, call the block function
    $MaxCount = $MaxCount - 1
    $name = get_name($array[0])
    $occurance = 0
    For $n = 1 To UBound($array) - 1
        If get_name($array[$n]) = $name Then
            $occurance = $occurance + 1
            If $occurance >= $MaxCount Then
                Call("block_user")
            EndIf
        Else
            $name = get_name($array[$n])
            $occurance = 0
        EndIf
    Next
EndFunc  ;==>tard_checker
; block a tard
Func block_user()
;if their name appears above yours, click the top name and block them
    If $nameabovebot = 1 Then
        MouseMove(1285, 1073)
        MouseDown("left")
        MouseUp("left")
        Sleep(100)
        MouseMove(1352, 1075)
        MouseDown("right")
        MouseUp("right")
        Sleep(100)
        MouseMove(1374, 1155)
        MouseDown("left")
        MouseUp("left")
        Sleep(100)
        MouseMove(1350, 1078)
        MouseDown("right")
        MouseUp("right")
        Sleep(100)
        MouseMove(1361, 1107)
        MouseDown("left")
        MouseUp("left")
        Sleep(100)
    ;if their name appears below yours, click the top name and block them
    Else
        MouseMove(1301, 1086)
        MouseDown("left")
        MouseUp("left")
        Sleep(100)
        MouseDown("right")
        MouseUp("right")
        Sleep(100)
        MouseMove(1322, 1161)
        MouseDown("left")
        MouseUp("left")
        Sleep(100)
        MouseMove(1290, 1092)
        MouseDown("right")
        MouseUp("right")
        Sleep(100)
        MouseMove(1311, 1107)
        MouseDown("left")
        MouseUp("left")
        Sleep(100)
    EndIf
; tell them they have been owned.
    MouseClick("left", 145, 304)
    Sleep(100)
    Send("You have been blocked for sending me excessive trade requests.{ENTER}", 0)
    MouseMove(688, 140)
    MouseDown("left")
    MouseUp("left")
    Sleep(100)
    MouseMove(1348, 1043)
    MouseDown("left")
    MouseUp("left")
EndFunc  ;==>block_user
;part of tard_checker
Func get_name($text)
    
    Local $items = StringSplit($text, $DELIMITER)
    Return $items[1]
EndFunc  ;==>get_name
;part of tard_checker
Func get_time($text)
    Local $items = StringSplit($text, $DELIMITER)
    Return $items[2]
EndFunc  ;==>get_time
;post your ad on the messageboard.
Func boardupdate($a)
    If PixelChecksum(1221 - $buddylist, 1157, 1375 - $buddylist, 1169) = 3061995020 Then;if left = messageboard then click left
        MouseClick("left", 1308 - $buddylist, 1161)
    Else;if right = messageboard then click right
        MouseClick("left", 1430 - $buddylist, 1159)
    EndIf
;spam $a message on the message board and minimize it.
    Sleep(1000)
    MouseMove(275, 468)
    MouseDown("left")
    MouseUp("left")
    Sleep(100)
    Send($a, 0)
    If PixelGetColor(786, 641) = 7917693 Then
        $Call_interloop = 0
        Return
    EndIf
    Send("{ENTER}", 0)
    MouseMove(745, 155)
    MouseDown("left")
    MouseUp("left")
    Sleep(1000)
    $boardtimer = TimerInit()
EndFunc  ;==>boardupdate
;check to see if there is a 'withdraw' prompt onscreen and close it if nessecary.
Func checkwithdraw()
;if a withdraw prompt is onscreen
    If PixelChecksum(637, 470, 772, 487) = 2078928619 Then
    ;close it
        MouseClick("left", 891, 633)
    EndIf
EndFunc  ;==>checkwithdraw
; calculate the selling price for the cards the user chose.
Func ID_cards()
    Dim $file, $line, $linearray[4], $tradestr, $buytotal = 0, $atimer, $tradeok = 1, $tradearray[3][32], $1mintimer
    For $i = 1 To 32
        Call("intradecheck")
    ;check if a duel request is recieved, decline if nessecary
        Call("duel_request")
    ;check if a PM is recieved, tell them to enter a trade with you instead
        Call("PM")
    ;check to see if theyve been in the trade for longer than 5min.
    ;generate a checksum for the top part of the card. store this in $traderarray[0][X]
        $tradearray[0][$i - 1] = PixelChecksum(156, (95+ (12 * $i)), 229, (106+ (12 * $i)))
        $file = FileOpen("c:\program files\MTGbot\botdata.csv", 0)
    ;Loop until end of file.
        While 1
            $line = FileReadLine($file)
            If @error = -1 Then ExitLoop
            $linearray = StringSplit($line, ",")
        ; if the checksum matches the checksum in the csv file, copy the price and name into $traderarray[1&2][x] and add to the total.
            If $linearray[1] = $tradearray[0][$i - 1] Then
                $tradearray[2][$i - 1] = $linearray [4]
                $buytotal = $buytotal + $tradearray[2][$i - 1]
                If $buytotal > 32 Then
                    $buytotal = $buytotal - $tradearray[2][$i - 1]
                    While 1
                        If PixelChecksum(156, (197+ (12* ($i - 1))), 229, (197+ (12* ($i - 1)))) = 1456332067 Then
                            ExitLoop
                        ElseIf PixelChecksum(156, (197+ (12* ($i - 1))), 229, (197+ (12* ($i - 1)))) = 14548993 Then
                            ExitLoop
                        ElseIf PixelChecksum(156, (197+ (12* ($i - 1))), 229, (197+ (12* ($i - 1)))) = 495143351 Then
                            ExitLoop
                            
                        EndIf
                        MouseClick("left", 195, (99+ (12 * $i)))
                        Sleep(200)
                    WEnd
                    ExitLoop 2
                EndIf
                $tradearray[1][$i - 1] = $linearray[2]
            EndIf
        WEnd
        If $tradearray[1][$i - 1] = "0" Then
            $tradearray[1][$i - 1] = "0"
        ; generate a transaction summary for the customer.
        ; if its the first time through the loop, don't put a comma between 'you have selected:' and the name of the first card.
        ElseIf $i = 1 Then
            $tradestr = $tradearray[1][$i - 1] & " for " & $tradearray[2][$i - 1]
        ; if it isn't the first time through, add a comma in between.
        Else
            $tradestr = $tradestr & " ," & $tradearray[1][$i - 1] & " for " & $tradearray[2][$i - 1]
        EndIf
        FileClose($file)
    Next
    $tradestr = $tradestr & " TOTAL = " & $buytotal & " Event Tickets."
    MouseClick("left", 546, 1135)
    Sleep(100)
    Send("I'm interested in buying these cards:{ENTER}", 0)
    Send($tradestr & "{ENTER}", 0)
    Send("Make any cards you don't want to sell for these prices untradable{ENTER}", 0)
    Send("or please take " & Int($buytotal) & " ticket(s) and confirm the trade.{ENTER}", 0)
    If PixelGetColor(465, 120) = 0 Then
        $morecards = 1
    ElseIf PixelGetColor(465, 120) = 16777215 Then
        $morecards = 1
    EndIf
    $atimer = TimerInit()
    tix(Int($buytotal), $atimer)
EndFunc  ;==>ID_cards

Func tradecheck($total, $1mintimer)
    Dim $tradearray[3][32], $file, $line, $newtotal, $linearray[4], $tradeok, $c, $notenoughtickets, $ticketcount
;perform the hashcheck again.
;loop around for each card in the trade window
    For $i = 1 To 32
        Call("intradecheck")
    ;check if a duel request is recieved, decline if nessecary
        Call("duel_request")
    ;check if a PM is recieved, tell them to enter a trade with you instead
        Call("PM")
    ;generate a checksum for the top part of the card. store this in $traderarray[0][X]
        $tradearray[0][$i - 1] = PixelChecksum(156, (95+ (12 * $i)), 229, (106+ (12 * $i)))
        $file = FileOpen("c:\program files\MTGbot\botdata.csv", 0)
    ;Loop until end of file.
        While 1
            $line = FileReadLine($file)
            If @error = -1 Then ExitLoop
            $linearray = StringSplit($line, ",")
        ; if the checksum matches the checksum in the csv file, copy the price and name into $traderarray[1&2][x] and add to the total.
            If $linearray[1] = $tradearray[0][$i - 1] Then
                $newtotal = $newtotal + $linearray[4]
            EndIf
        WEnd
        FileClose($file)
    Next
;if the trade is still the same
    If Int($newtotal) = $total Then
    ;and there are enough tickets in the trade
        $ticketcount = 0
        For $x = 1 To 32
            If PixelGetColor(50, (96+ ($x * 12))) = 1247493 Then
                $ticketcount = $ticketcount + 1
            Else
                ExitLoop
            EndIf
        Next
        If $ticketcount = $total Then
            confirm($total)
        ElseIf $ticketcount < $total Then
            MouseClick("left", 546, 1135)
            Sleep(100)
            Send("Please take " & ($total - $ticketcount) & " more event tickets and confirm the trade.{ENTER}", 0)
        ;unconfirm the customers trade.
            MouseMove(340, 41)
            MouseDown("left")
            MouseUp("left")
            Sleep(50)
            MouseMove(249, 219)
            MouseDown("left")
            MouseMove(249, 218)
            MouseUp("left")
            Sleep(50)
            MouseMove(159, 297)
            MouseDown("left")
            MouseUp("left")
            Sleep(50)
            MouseMove(547, 369)
            MouseDown("left")
            MouseUp("left")
            Sleep(50)
            MouseMove(547, 375)
            MouseDown("left")
            MouseUp("left")
            Sleep(50)
            MouseMove(448, 41)
            MouseDown("left")
            MouseUp("left")
            While PixelChecksum(57, 739, 115, 758) = 1600235646
                Sleep(50)
            WEnd
            tix($total, $1mintimer)
        ElseIf $ticketcount > $total Then
            MouseClick("left", 546, 1135)
            Sleep(100)
            Send("Please remove " & ($ticketcount - $total) & " event tickets and confirm the trade.{ENTER}", 0)
        ;unconfirm the customers trade.
            MouseMove(340, 41)
            MouseDown("left")
            MouseUp("left")
            Sleep(50)
            MouseMove(249, 219)
            MouseDown("left")
            MouseMove(249, 218)
            MouseUp("left")
            Sleep(50)
            MouseMove(159, 297)
            MouseDown("left")
            MouseUp("left")
            Sleep(50)
            MouseMove(547, 369)
            MouseDown("left")
            MouseUp("left")
            Sleep(50)
            MouseMove(547, 375)
            MouseDown("left")
            MouseUp("left")
            Sleep(50)
            MouseMove(448, 41)
            MouseDown("left")
            MouseUp("left")
            While PixelChecksum(57, 739, 115, 758) = 1600235646
                Sleep(50)
            WEnd
            tix($total, $1mintimer)
        EndIf
    Else
    ;inform the customer
        MouseClick("left", 546, 1135)
        Sleep(100)
        Send("You have removed some cards in the trade. Recalculating the trade.{ENTER}", 0)
    ;update $cardcounter to reflect the number of cards in the trade window
        $cardcounter = 0
        For $t = 1 To 32
            Call("intradecheck")
        ;check if a duel request is recieved, decline if nessecary
            Call("duel_request")
        ;check if a PM is recieved, tell them to enter a trade with you instead
            Call("PM")
            If PixelChecksum(156, (95+ ($t * 12)), 229, (95+ ($t * 12))) = 1456332067 Then
                $cardcounter = $cardcounter + 1
            ElseIf PixelChecksum(156, (95+ ($t * 12)), 229, (95+ ($t * 12))) = 14548993 Then
                $cardcounter = $cardcounter + 1
            Else
                ExitLoop
            EndIf
        Next
    ; if newtotal is less than 19, go back to the main trade loop. this may add new cards to the trade window.
    ; if its above 19, recalculate the trade instead.
        If $newtotal > 19 Then
            Call("ID_cards")
        Else
            Call("trade")
        EndIf
    EndIf
EndFunc  ;==>tradecheck
;complete the trade.
Func confirm($total)
    Dim $30sectimer, $10sectimer
    Call("intradecheck")
;check if a duel request is recieved, decline if nessecary
    Call("duel_request")
;check if a PM is recieved, tell them to enter a trade with you instead
    Call("PM")
;confirm the trade
    MouseMove(248, 742)
    MouseDown("left")
    MouseUp("left")
    Sleep(200)
    MouseMove(205, 764)
    MouseDown("left")
    MouseUp("left")
    Sleep(200)
    MouseMove(310, 1142)
    MouseDown("left")
    MouseUp("left")
    Sleep(200)
    $30sectimer = TimerInit()
    While TimerDiff($30sectimer) < 30000
    ;check for them removing cards
        tradechange($total)
    ;check to see if you are still in a trade, head back to inner loop if you arn't
        Call("intradecheck")
    ;check if a duel request is recieved, decline if nessecary
        Call("duel_request")
    ;check if a PM is recieved, tell them to enter a trade with you instead
        Call("PM")
    ; if the confirm trade button is onscreen
        If PixelChecksum(1219, 1028, 1374, 1037) = 2336066960 Then
        ;thank them
            MouseClick("left", 546, 1135)
            Sleep(100)
            Send("Thanks for selling some cards to me! ^qs{ENTER}", 0)
            If $morecards = 1 Then
                Send("I want to buy more cards from your collection. Please open a trade after this if you want to sell more cards.{ENTER}", 0)
                $morecards = 0
            EndIf
            Sleep(1000)
        ; click the trade button
            MouseClick("left", 1273, 1029)
            $10sectimer = TimerInit()
            While TimerDiff($10sectimer) < 10000
                Sleep(300)
            WEnd
        ;if they back out of the trade, go on to the next step
            If PixelGetColor(436, 35) = 6600129 Then
                ExitLoop
            EndIf
        EndIf
        Sleep(500)
    WEnd
; if still in a trade (customer didn't click it)
    If PixelGetColor(436, 35) = 6600129 Then
        MouseClick("left", 546, 1135)
        Sleep(100)
        Send("You aborted the trade. Recalculating.{ENTER}", 0)
    ;go back to the start of the trade loop
        Call("trade")
    Else
    ;trade has ended, so go back to the 'waiting for a trade' loop
        $Call_interloop = 0
        Return
    EndIf
EndFunc  ;==>confirm
;this checks for the new cards window, and closes it if nessecary.
Func newcardscheck()
;the window can be in 3 places. check for its presence and close it if nessecary.
    If PixelChecksum(321, 61, 386, 70) = 4069852983 Then
        If PixelChecksum(791, 59, 805, 72) = 182725946 Then
            MouseClick("left", 798, 65)
        ElseIf PixelChecksum(745, 59, 759, 72) = 182725946 Then
            MouseClick("left", 752, 65)
        ElseIf PixelChecksum(803, 59, 817, 72) = 182725946 Then
            MouseClick("left", 810, 65)
        EndIf
    EndIf
EndFunc  ;==>newcardscheck

Func tix($total, $1mintimer)
    Dim $ticketcount = 0
    While 1
    ;check to see if the trade has changed since the confirm button was clicked
        tradechange($total)
    ;check to see if you are still in a trade, head back to inner loop if you arn't
        Call("intradecheck")
    ;check if a duel request is recieved and decline if nessecary
        Call("duel_request")
    ;check if a PM is recieved, and tell them to open a trade
        Call("PM")
    ;if they have taken an event ticket, loop around until they select $total tickets
        If PixelChecksum(57, 739, 115, 758) = 1600235646 Then
            tradecheck($total, $1mintimer)
        EndIf
        If TimerDiff($1mintimer) > 60000 Then
            MouseClick("left", 385, 1141)
            Sleep(100)
            Send("You havn't confirmed the trade. Recalculating.{ENTER}", 0)
            Call("trade")
        EndIf
    WEnd
EndFunc  ;==>tix

Func tradechange($total)
    Dim $tradearray[3][32], $file, $line, $newtotal, $linearray[4], $10sectimer
    For $i = 1 To 32
    ;generate a checksum for the top part of the card. store this in $traderarray[0][X]
        $tradearray[0][$i - 1] = PixelChecksum(156, (95+ (12 * $i)), 229, (106+ (12 * $i)))
        $file = FileOpen("c:\program files\MTGbot\botdata.csv", 0)
    ;Loop until end of file.
        While 1
            $line = FileReadLine($file)
            If @error = -1 Then ExitLoop
            $linearray = StringSplit($line, ",")
        ; if the checksum matches the checksum in the csv file, copy the price into $traderarray[1&2][x] and add to the total.
            If $linearray[1] = $tradearray[0][$i - 1] Then
                $newtotal = $newtotal + $linearray[4]
            EndIf
        WEnd
        FileClose($file)
    Next
;if the trade has changed
    If Int($newtotal) <> $total Then
    ;inform the customer
        MouseClick("left", 546, 1135)
        Sleep(100)
        Send("You have removed some cards in the trade. Recalculating.{ENTER}", 0)
    ;update $cardcounter to reflect the number of cards in the trade window
        $cardcounter = 0
        For $t = 1 To 32
            If PixelChecksum(156, (95+ ($t * 12)), 229, (95+ ($t * 12))) = 1456332067 Then
                $cardcounter = $cardcounter + 1
            ElseIf PixelChecksum(156, (95+ ($t * 12)), 229, (95+ ($t * 12))) = 14548993 Then
                $cardcounter = $cardcounter + 1
            Else
                ExitLoop
            EndIf
        Next
    ; if newtotal is less than 19, go back to the main trade loop. this may add new cards to the trade window.
    ; if its above 19, recalculate the trade instead.
        If $newtotal > 19 Then
            Call("ID_cards")
        Else
            Call("trade")
        EndIf
    EndIf
EndFunc  ;==>tradechange
;used to close the bot by hitting esc.
Func Terminate()
;when escape is hit, stop the bot.
    MsgBox(0, "", "MTGbot stopped")

EndFunc  ;==>Terminate
;check if the bot is still in a trade. if not, return to the inner loop
Func intradecheck()
    If PixelGetColor(415, 36) = 0 Then
        $Call_interloop = 0
        Return
    EndIf
EndFunc  ;==>intradecheck
;if the bot gets disconnected, start the reconnection process
Func checkdisconnect()
;if the user refused to provide a password in the gui, end the function
    If $botpass = "" Then
        $botpass = ""
    ;if disconnected box is onscreen
    ElseIf PixelChecksum(637, 470, 857, 487) = 2808774430 Then
    ;close it
        MouseClick("left", 892, 631)
        Sleep(100)
        Call("dologin")
    EndIf
EndFunc  ;==>checkdisconnect
;try and log in
Func dologin()
;input username
    MouseClick("left", 764, 582)
    Sleep(100)
    Send($botname)
    Sleep(100)
;input password
    MouseClick("left", 760, 632)
    Sleep(100)
    Send($botpass)
    MouseClick("left", 800, 660)
;attempt to login
    Call("loginattempt")
EndFunc  ;==>dologin
;handle the login attempt
Func loginattempt()
    Dim $10sectimer, $logintimer
    $logintimer = TimerInit()
;loop round for 3min waiting for the login attempt.
    While TimerDiff($logintimer) < 180000
    ;if the 'no connection to server' error appears
        If PixelChecksum(622, 491, 976, 603) = 2151702803 Then
        ;close it
            MouseClick("left", 925, 678)
            Sleep(100)
        ;erase the username field
            MouseClick("left", 764, 582)
            Sleep(100)
            $10sectimer = TimerInit()
            While TimerDiff($10sectimer) < 4000
                Send("{BACKSPACE}", 0)
                Sleep(10)
            WEnd
            $10sectimer = TimerInit()
            While TimerDiff($10sectimer) < 4000
                Send("{DELETE}", 0)
                Sleep(10)
            WEnd
        ;erase the password field
            Sleep(200)
            MouseClick("left", 760, 632)
            Sleep(100)
            $10sectimer = TimerInit()
            While TimerDiff($10sectimer) < 4000
                Send("{BACKSPACE}", 0)
                Sleep(10)
            WEnd
            $10sectimer = TimerInit()
            While TimerDiff($10sectimer) < 4000
                Send("{DELETE}", 0)
                Sleep(10)
            WEnd
            Sleep(200)
        ;try to login again
            Call("dologin")
        ElseIf PixelChecksum(131, 61, 203, 70) = 2666305482 Then
        ;if MTGO has logged in
        ;open the marketplace and message board
            Call("firstlogin")
        ; if the 'this user is allready logged in' box appears
        ElseIf PixelChecksum(654, 532, 962, 541) = 2905472228 Then
        ; close it
            MouseClick("left", 809, 647)
            Sleep(200)
        ;erase the username field
            MouseClick("left", 764, 582)
            Sleep(100)
            $10sectimer = TimerInit()
            While TimerDiff($10sectimer) < 4000
                Send("{BACKSPACE}", 0)
                Sleep(10)
            WEnd
            $10sectimer = TimerInit()
            While TimerDiff($10sectimer) < 4000
                Send("{DELETE}", 0)
                Sleep(10)
            WEnd
            Sleep(200)
        ;erase the password field
            MouseClick("left", 760, 632)
            Sleep(100)
            $10sectimer = TimerInit()
            While TimerDiff($10sectimer) < 4000
                Send("{BACKSPACE}", 0)
                Sleep(10)
            WEnd
            $10sectimer = TimerInit()
            While TimerDiff($10sectimer) < 4000
                Send("{DELETE}", 0)
                Sleep(10)
            WEnd
            Sleep(200)
        ;try to login again
            Call("dologin")
        EndIf
        Sleep(5000)
    WEnd
; if after 3 minutes you still havn't logged in, try again
    Call("dologin")
EndFunc  ;==>loginattempt
;this function opens the marketplace and message board, spams the message board and runs the bot.
Func firstlogin()
    Dim $y = 1, $z = 1
; if MTGO is sitting on the 'main room'
    If PixelChecksum(131, 61, 203, 70) = 2666305482 Then
    ;click the trade button
        MouseClick("left", 618, 567)
    ;loop around waiting for it to appear
        While PixelChecksum(131, 61, 203, 70) = 2666305482
            Sleep(500)
        WEnd
    ;open the message board
        MouseClick("left", 835, 531)
    ;loop around waiting for it to appear
        While $y = 1
        ;when it does appear, minimize it and exitloop
            If PixelGetColor(274, 460) = 9802661 Then
                MouseClick("left", 745, 157)
                ExitLoop
            EndIf
        WEnd
    ;open the marketplace
        MouseClick("left", 1043, 554)
    ;wait for it to appear
        While $z = 1
        ;when it does appear, minimize it and exitloop
            If PixelGetColor(182, 371) = 9802661 Then
                MouseClick("left", 683, 151)
                Sleep(2000)
                ExitLoop
            EndIf
        WEnd
        Sleep(200)
    ;update the message board
        boardupdate($msgbrdspam)
    ;start the bots inner loop.
        $Call_interloop = 0
        Return
    EndIf
EndFunc  ;==>firstlogin
; this function generates a checksum for the card in the 'you get' trade window.

; this function generates a checksum for the card in the 'you get' trade window.
Func hashacard()
    Dim $inputstr, $line, $file, $i = 1
    $file = FileOpen("c:\program files\MTGbot\botdata.csv", 1)
    While $i = 1
    ; ask the user to enter the card name, selling price and buying price
        $inputstr = InputBox("card details", "enter the card name,selling price,buying price seperated by commas. Make sure the card you want to hash is visibile in the 'you get' trade box.")
        If @error = 1 Then
            Call("Terminate")
        EndIf
    ; write the hash,name,sellprice,buyprice to the end of the bot datafile.
        $line = PixelChecksum(156, 107, 229, 118) & "," & $inputstr
        FileWriteLine($file, $line)
    WEnd
    FileClose($file)

EndFunc  ;==>hashacard
; this function exports the bots collection to owned.csv
Func export()
; select the collection tab
    MouseClick("left", 353, 40)
    Sleep(100)
;reset all filters
    MouseClick("left", 215, 340)
;change the filter to rare cards.
    MouseMove(256, 225)
    MouseDown("left")
    MouseUp("left")
    Sleep(100)
    MouseMove(213, 291)
    MouseDown("left")
    MouseUp("left")
    Sleep(100)
;sort by set, collector number.
    MouseMove(248, 266)
    MouseDown("left")
    Sleep(100)
    MouseMove(200, 300)
    MouseDown("left")
    MouseUp("left")
    Sleep(100)
; if the collection isnt on the text style display, click the button to change to the text display.
    if (PixelChecksum(1564, 59, 1584, 72)) = 1694229323 Then
        MouseMove(1579, 69)
        MouseDown("left")
        MouseUp("left")
        Sleep(100)
    EndIf
; right click
    MouseMove(392, 150)
    MouseDown("right")
; seleect all
    MouseMove(387, 152)
    MouseUp("right")
    Sleep(100)
    MouseMove(412, 180)
    MouseDown("left")
    MouseUp("left")
    Sleep(100)
;export as csv
    MouseMove(399, 187)
    MouseDown("right")
    MouseUp("right")
    Sleep(100)
    MouseMove(428, 232)
    MouseDown("left")
    MouseUp("left")
    Sleep(100)
    WinWait("Export as CSV", "")
    If Not WinActive("Export as CSV", "") Then WinActivate("Export as CSV", "")
    WinWaitActive("Export as CSV", "")
; save as owned.csv
    Send("owned.csv")
    MouseMove(507, 398)
    MouseDown("left")
    MouseUp("left")
    Sleep(100)
    WinWait("Magic Online V2.0.001.522", "")
    If Not WinActive("Magic Online V2.0.001.522", "") Then WinActivate("Magic Online V2.0.001.522", "")
    WinWaitActive("Magic Online V2.0.001.522", "")
;close prompt
    MouseMove(789, 645)
    MouseDown("left")
    MouseUp("left")
    Sleep(100)
    MsgBox(0, "", "export completed")

EndFunc  ;==>export

Func pullcards()
    Dim $z = 1, $crdpixl
    While $z = 1
        $crdpixl = PixelGetColor(465, 120)
        If $crdpixl = 16777215 Then
            $cardcounter = $cardcounter + 1
            If $cardcounter < 32 Then
                MouseClick("left", 533, 202)
            EndIf
        ElseIf $crdpixl = 0 Then
            $cardcounter = $cardcounter + 1
            If $cardcounter < 32 Then
                MouseClick("left", 533, 202)
            EndIf
        ElseIf $crdpixl = 65280 Then
            $cardcounter = $cardcounter + 1
            If $cardcounter < 32 Then
                MouseClick("left", 533, 202)
            EndIf
        Else
            Sleep(200)
            Call("trade")
        EndIf
    ;check if a duel request is recieved and decline if nessecary
        Call("duel_request")
    ;check if a PM is recieved and tell them to enter a trade
        Call("PM")
    ;check to see if you are still in the trade.
        Call("intradecheck")
        MouseMove(376, 130, 3)
    WEnd
EndFunc  ;==>pullcards

Func tradetimer()
    If TimerDiff($startoftrade) > 300000 Then
        MouseClick("left", 385, 1141)
        Sleep(100)
        Send("You have been inactive for five minutes. If you want to sell cards to me you'll need to send another trade request.{ENTER}", 0)
        Send(" Now closing inactive trade{ENTER}", 0)
        Sleep(2000)
        MouseClick("left", 1348, 1043)
        $Call_interloop = 0
        Return
    EndIf
EndFunc  ;==>tradetimer

Func botowner()
    Dim $i = 1
; if the bot owner trades with the bot
; filter all cards where number owned > 1
    MouseClick("left", 331, 39)
    Sleep(100)
    MouseMove(214, 332)
    MouseDown("left")
    MouseUp("left")
    Sleep(100)
    MouseMove(254, 169)
    MouseDown("left")
    MouseUp("left")
    Sleep(100)
    MouseMove(250, 136)
    MouseDown("left")
    MouseUp("left")
    Sleep(100)
    MouseMove(167, 164)
    MouseDown("left")
    MouseUp("left")
    Sleep(100)
    MouseMove(917, 259)
    MouseDown("right")
    MouseMove(916, 259)
    MouseUp("right")
    Sleep(100)
    MouseMove(938, 289)
    MouseDown("left")
    MouseUp("left")
    Sleep(100)
    MouseClick("left", 433, 37)
    Sleep(100)
    Call("ticketfilter")
    Call("pulltix")
;wait here for the owner to confirm the trade.
    While $i = 1
        If PixelChecksum(57, 739, 115, 758) = 1600235646 Then
            ExitLoop
        Else
            Sleep(100)
        EndIf
    WEnd
;confirm the trade
    MouseMove(248, 742)
    MouseDown("left")
    MouseUp("left")
    Sleep(200)
    MouseMove(205, 764)
    MouseDown("left")
    MouseUp("left")
    Sleep(200)
    MouseMove(310, 1142)
    MouseDown("left")
    MouseUp("left")
    Sleep(100)
    $30sectimer = TimerInit()
    While TimerDiff($30sectimer) < 30000
    ; if the confirm trade button is onscreen
        If PixelChecksum(1219, 1028, 1374, 1037) = 2336066960 Then
        ; click the trade button
            MouseClick("left", 1273, 1029)
            ExitLoop
        EndIf
        Sleep(100)
    WEnd
    Sleep(10000)
    Send("{ENTER}", 0)
    Call("newcardscheck")
; make all the cards in your collection untradable.
    MouseMove(220, 341)
    MouseDown("left")
    MouseMove(220, 342)
    MouseUp("left")
    Sleep(100)
    MouseMove(251, 130)
    MouseDown("left")
    MouseUp("left")
    Sleep(100)
    MouseMove(177, 176)
    MouseDown("left")
    MouseUp("left")
    Sleep(100)
    MouseMove(938, 311)
    MouseDown("right")
    MouseUp("right")
    Sleep(100)
    MouseMove(987, 362)
    MouseDown("left")
    MouseUp("left")
    Sleep(100)
; make all your event tickets tradable.
    MouseMove(214, 341)
    MouseDown("left")
    MouseUp("left")
    Sleep(100)
    MouseMove(245, 134)
    MouseDown("left")
    MouseUp("left")
    Sleep(100)
    MouseMove(180, 211)
    MouseDown("left")
    MouseUp("left")
    Sleep(100)
    MouseMove(927, 340)
    MouseDown("right")
    MouseMove(927, 339)
    MouseUp("right")
    Sleep(100)
    MouseMove(947, 374)
    MouseDown("left")
    MouseUp("left")
    Sleep(100)
    $Call_interloop = 0
EndFunc  ;==>botowner

Func ticketfilter()
;filter to show boosters
    MouseMove(125, 78)
    MouseDown("left")
    MouseUp("left")
    Sleep(100)
    MouseMove(246, 345)
    MouseDown("left")
    MouseMove(245, 345)
    MouseUp("left")
    Sleep(100)
    MouseMove(251, 160)
    MouseDown("left")
    MouseUp("left")
    Sleep(100)
    MouseMove(189, 209)
    MouseDown("left")
    MouseUp("left")
    Sleep(100)
    MouseMove(135, 311)
    MouseDown("left")
    MouseUp("left")
    Sleep(100)
;search for 'event'
    Send("event{ENTER}")
;switch back to the trade box
    MouseMove(195, 76)
    MouseDown("left")
    MouseUp("left")
    Sleep(100)
EndFunc  ;==>ticketfilter

Func pulltix()
    Do
        While PixelChecksum(481, 122, 586, 139) = 366956196
            MouseClick("left", 529, 252)
            MouseMove(427, 159)
            Sleep(100)
        WEnd
        Sleep(1000)
    Until Not PixelChecksum(481, 122, 586, 139) = 366956196
EndFunc  ;==>pulltix


If PixelGetColor(415, 36) = 0 Then Return

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

Thanks very very much Valuater!

I modified your code slightly to get it to work, but you helped get me thinking about a solution. The code now looks like this:

these two lines are in the functions trade,id_cards,tradecheck,tradechange,pullcards,confirm and tix:

Call("intradecheck")
if $Call_interloop = 0 then Return

I also had to modify the function 'firstlogin' so that it would run the innerloop on completion:

$Call_interloop = 1
Return

I also need to thank you for not providing me with a complete solution. It forced me to analyse your changes and figure them out rather than simply copy - pasting the code and learning nothing.

I'm going to go make these changes to my selling bot as well.

Tim

EDIT: It's all fixed and working.

Edited by The_Lorax

Share this post


Link to post
Share on other sites

I feel so stupid!

There's no reason to feel stupid. It happens to me all the time that I make a silly mistake or oversight like yours. Then when I show the problem to someone else, they either immediately spot the cause of the problem or I spot it myself while trying to explain. And I'm paid to code, too.

Ignorance is strength.

Share this post


Link to post
Share on other sites

The_Lorax, please explain to me because I honestly do not understand. What logic leads you to use "Call()" all over the place? Call should never be used with a string literal and in reality, Call() should never be used by 80% of the users of AutoIt. So my question is, what made you use it or think you needed to use it because this is a serious issue that needs addressed.

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

Valik:

I used it because I thought it would do what I needed. There was no tutorial on programming using functions, so I looked through the help file for a statement that would work and then used it.

When coding this the first thing I did was to get the bot accepting trade requests, handing private messages, duel requests and trade withdrawls. I diagrammed exactly what I wanted then just went straight to the helpfile to find code that would work. Because there was no one showing me the best way to do something some of my code is probably strange, but at least it works.

what should I have used instead of call("function"), and why?

Edited by The_Lorax

Share this post


Link to post
Share on other sites

what should I have used instead of call("function"), and why?

Just the function name. See help file: AutoIT -> Language Reference -> Functions

Like this:

func _MyFunc($text)
   msgbox(0,"",$text)
endfunc

_MyFunc("Hello #1")
_MyFunc("Hello #2")

You can't pass arguments to a function with call().

Cheers

Kurt


__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Share this post


Link to post
Share on other sites

Sorry about the UP.

Can you plz send me the updated code at Email(amirr_l@walla.co.il) or PM or here.

i started bild one and i had lot of problem so i

wanted to ask here then in search i saw this msg.

TY Verrry mutch!

Share this post


Link to post
Share on other sites

Hello I have been searching and searching for something very similar to this.

Could you please tell me about this section of your code:

; if the checksum matches the checksum in the csv file, copy the price and name into $traderarray[1&2][x] and add to the total.

Do you mean to say you have all 13k of cards pixel check in a cvs?


I have never killed a man, but I have read many obituaries with a smile.Arguing on the enternet is like running in the special olympics. Even if you win your still retarded.If I like it I will use it, if I dont it keeps me warm when I burn it.

Share this post


Link to post
Share on other sites

Hello I have been searching and searching for something very similar to this.

Could you please tell me about this section of your code:

; if the checksum matches the checksum in the csv file, copy the price and name into $traderarray[1&2][x] and add to the total.

Do you mean to say you have all 13k of cards pixel check in a cvs?

about 7000 cards, then all the foils, all the different artworks, oh, and don't forget all the lands. I guess around 20k.

Care to share the CSV ?

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