Jump to content
Sign in to follow this  
Supreme1012

Teleporting Function for Diablo II

Recommended Posts

Supreme1012

Ive spent alot of time on trying to come up with the best possible autoit function for teleporting in diablo II. Heres the function as well as an example teleporting to Pindle from the portal. So far it can read if the screen is black and if the char has not moved from the spot, but I cant figure out how to recognize if the char gets knocked out of position w/o actually teleporting(since he changes positions and the screen isnt black but doesnt tele to the position). I'd appreciate any input anyone could give

I believe you have to be using Windows 16 Bit Color mode to test this in D2

WinActivate("Diablo II")
WinMove("Diablo II","",0,0)
opt("PixelCoordMode", 2)
opt("MouseCoordMode", 2)
opt("ColorMode", 1)
#Include <Array.Au3>
#Include <File.Au3>

$MinTele_Delay = 300
$TeleScan_Delay = 50
$TeleportTimeout = 3000;nothing lower than 1100

;example
Teleport(780,75)
Teleport(780,75)
Teleport(700,30)
EXIT(1)
;===========================Function===========================
Func Teleport($XCoord,$YCoord)
$Check1 = PixelChecksum(790,560,795,565)
$Check2 = PixelChecksum(70,35,75,40)
$Check3 = PixelChecksum(790,35,795,40)
$Check4 = PixelChecksum(10,560,15,565)
$TeleRetry = 0
Do
MouseClick("Right",$XCoord,$YCoord,1,4)
Sleep($MinTele_Delay)
If CheckIfBlackScreen() = 1 Then
   If $Check1 <> PixelChecksum(790,560,795,565) Or $Check2 <> PixelChecksum(70,35,75,40) Or $Check3 <> PixelChecksum(790,35,795,40) Or $Check4 <> PixelChecksum(10,560,15,565) Then
      _FileWriteLog(@ScriptDir & "\Teleport.log","Teleport Successful")
      ExitLoop
   Else
      ContinueLoop
   EndIf
Else
   _FileWriteLog(@ScriptDir & "\Teleport.log","CheckTele() TimedOut. Retrying a Missed Teleport.")
   ContinueLoop
EndIf
$TeleRetry = $TeleRetry + 1
Until $TeleRetry = 7
EndFunc

Func CheckIfBlackScreen()
$TimeStart = TimerInit()
Do
Sleep($TeleScan_Delay)
$Color1 = PixelGetColor(10,35)
$Color2 = PixelGetColor(790,560)
$Color3 = PixelGetColor(35,790)
$Color4 = PixelGetColor(10,560)
$Color5 = PixelGetColor(400,545)
$Color6 = PixelGetColor(400,35)
$Color7 = PixelGetColor(10,300)
$Color8 = PixelGetColor(790,300)
$Color9 = PixelGetColor(300,300)
$Color10 = PixelGetColor(300,500)
$Color11 = PixelGetColor(400,200)
$Color12 = PixelGetColor(400,400)

$Color = ($Color1 + $Color2 + $Color3 + $Color4 + $Color5 + $Color6 + $Color7 + $Color8 + $Color9 + $Color10 + $Color11 + $Color12) / 12
;_FileWriteLog(@ScriptDir & "\Teleport.log","Color = " & $Color )
$RoundedColor = Round($Color, 0)
_FileWriteLog(@ScriptDir & "\Teleport.log","RoundedColor = " & $RoundedColor )
If $RoundedColor > 1100000 Then
   _FileWriteLog(@ScriptDir & "\Teleport.log","RoundedColor > 1100000")
   Return 1
   ExitLoop
Else
   Sleep($MinTele_Delay)
   _FileWriteLog(@ScriptDir & "\Teleport.log","RoundedColor is NOT > 1100000")
   ContinueLoop
EndIf
Until TimerDiff($TimeStart) > $TeleportTimeout
EndFunc

Share this post


Link to post
Share on other sites
Supreme1012

I came up with a little bit different function. Its a Do.. Until inside of another Do.. Until, which I never thought of doing at first. Makes it less likely to right click multiple times

WinActivate("Diablo II")
WinMove("Diablo II","",0,0)
opt("PixelCoordMode", 2)
opt("MouseCoordMode", 2)
opt("ColorMode", 1)
#Include <Array.Au3>
#Include <File.Au3>

HotKeySet("{END}", "KillScript")

$MinTele_Delay = 300
$TeleScan_Delay = 50
$TeleportTimeout = 3000;nothing lower than 1100
$MaxTeleRetries = 6

;example
Teleport(200,290)
Teleport(600,290)
Teleport(200,290)
Teleport(600,290)
Teleport(200,290)
Teleport(600,290)
Teleport(200,290)
Teleport(600,290)
Teleport(200,290)
Teleport(600,290)
EXIT(1)
;===========================Function===========================
Func Teleport($XCoord,$YCoord)
$Check1 = PixelChecksum(790,560,795,565)
$Check2 = PixelChecksum(70,35,75,40)
$Check3 = PixelChecksum(790,35,795,40)
$Check4 = PixelChecksum(10,560,15,565)

$TeleRetry = 0
Do
MouseClick("Right",$XCoord,$YCoord,1,4)
_FileWriteLog(@ScriptDir & "\Teleport.log","Right Click.")
Sleep($MinTele_Delay)
    $TimeStart = TimerInit()
    Do
    If CheckIfBlackScreen() = 1 Then
        If $Check1 <> PixelChecksum(790,560,795,565) Or $Check2 <> PixelChecksum(70,35,75,40) Or $Check3 <> PixelChecksum(790,35,795,40) Or $Check4 <> PixelChecksum(10,560,15,565) Then
            _FileWriteLog(@ScriptDir & "\Teleport.log","Teleport Successful")
            ExitLoop
        Else
        ;_FileWriteLog(@ScriptDir & "\Teleport.log","CheckIfBlackScreen()=1, but waiting for teleport to finish")
            ContinueLoop
        EndIf
    Else
        _FileWriteLog(@ScriptDir & "\Teleport.log","CheckIfBlackScreen() doesnt = 1. Retrying Scan.")
        ContinueLoop
    EndIf
    Until TimerDiff($TimeStart) > $TeleportTimeout
If TimerDiff($TimeStart) > $TeleportTimeout Then
    ContinueLoop
Else
    ExitLoop
EndIf
$TeleRetry = $TeleRetry + 1
Until $TeleRetry = $MaxTeleRetries
EndFunc

Func CheckIfBlackScreen()
Sleep($TeleScan_Delay)
$Color1 = PixelGetColor(10,35)
$Color2 = PixelGetColor(790,560)
$Color3 = PixelGetColor(35,790)
$Color4 = PixelGetColor(10,560)
$Color5 = PixelGetColor(400,545)
$Color6 = PixelGetColor(400,35)
$Color7 = PixelGetColor(10,300)
$Color8 = PixelGetColor(790,300)
$Color9 = PixelGetColor(300,300)
$Color10 = PixelGetColor(300,500)
$Color11 = PixelGetColor(400,200)
$Color12 = PixelGetColor(400,400)
$Color = ($Color1 + $Color2 + $Color3 + $Color4 + $Color5 + $Color6 + $Color7 + $Color8 + $Color9 + $Color10 + $Color11 + $Color12) / 12
$RoundedColor = Round($Color, 0)
;_FileWriteLog(@ScriptDir & "\Teleport.log","RoundedColor = " & $RoundedColor )
If $RoundedColor > 1100000 Then
;_FileWriteLog(@ScriptDir & "\Teleport.log","RoundedColor > 1100000")
    Return 1
Else
    _FileWriteLog(@ScriptDir & "\Teleport.log","RoundedColor is NOT > 1100000")
    Return 0
EndIf
EndFunc

Func KillScript()
    _FileWriteLog(@ScriptDir & "\Teleport.log","User has stopped the Script!")
    Exit(1)
EndFunc

Share this post


Link to post
Share on other sites
Smorg

I'll look at this later.

Might want to put this on EON or mmbot. This place isn't for d2 specific help ^^

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  

×