тока ходилка нужна чтобы обходила припядствия
плиз помогите....
заранея спасиба

Moderators: Murderator+, Murderator
Azzi wrote:Плиз подскожите как поставить ходинку в мининг скрипт
тока ходилка нужна чтобы обходила припядствия
плиз помогите....
заранея спасиба
Code: Select all
uo.GetX("к чему подходим")
uo.GetY("к чему подходим")
Azzi wrote:Плиз подскожите как поставить ходинку в мининг скрипт
тока ходилка нужна чтобы обходила припядствия
плиз помогите....
заранея спасиба
Code: Select all
(C) SerrouS
sub InitStack()
uo.SetGlobal('STACK', '0')
end sub
sub Push( param )
var Check=val(uo.GetGlobal('STACK')) ; количество элементов в стеке
uo.SetGlobal('STACK',str(Check + 1))
uo.SetGlobal('STACK_'+str(Check), param)
end sub
sub Pop ()
var Check=val(uo.GetGlobal('STACK')) ; количество элементов в стеке
if Check then
uo.SetGlobal('STACK',str(Check - 1))
return uo.GetGlobal('STACK_'+str(Check - 1))
else
return ''
end if
end sub
sub GoToXY(X,Y,prec)
dim Turn[8] ; индекс - ГетДир, значение поворот направо под 45 градусов
Turn[0] = 39
Turn[1] = 34
Turn[2] = 40
Turn[3] = 35
Turn[4] = 37
Turn[5] = 36
Turn[6] = 38
Turn[7] = 33
dim DeltaX[8]; индекс - аналогично, значение - изменение координаты при проходе стенки
dim DeltaY[8]
DeltaX[0] = 1
DeltaX[1] = 1
DeltaX[2] = 1
DeltaX[3] = 0
DeltaX[4] = -1
DeltaX[5] = -1
DeltaX[6] = -1
DeltaX[7] = 0
DeltaY[0] = -1
DeltaY[1] = 0
DeltaY[2] = 1
DeltaY[3] = 1
DeltaY[4] = 1
DeltaY[5] = 0
DeltaY[6] = -1
DeltaY[7] = -1
var MoveX,MoveY
var CurrentX,CurrentY
var LastX=0,LastY=0,LastD=-1
var pathFind=0
var Index
var recursInd=0
var fout=0
var stepdelay=1000
InitStack()
repeat
CurrentX=uo.GetX()
CurrentY=uo.GetY()
MoveX=CurrentX-X
if MoveX<0 then
MoveX=0-dx
end if
dy=CurrentY-Y
if MoveY<0 then
MoveY=0-MoveY
end if
if MoveY>MoveX then
MoveX=MoveY
end if
if MoveX<=prec then
return
end if
if CurrentX==X and CurrentY==Y then
return
end if
LastX=CurrentX
LastY=CurrentY
LastD=uo.GetDir()
if CurrentX==X and Current>Y then
uo.Press(33)
end if
if CurrentX==X and CurrentY<Y then
uo.Press(35)
end if
if CurrentX<X and CurrentY==Y then
uo.Press(34)
end if
if CurrentX<X and CurrentY>Y then
uo.Press(39)
end if
if CurrentX<X and CurrentY<Y then
uo.Press(40)
end if
if CurrentX>X and CurrentY==Y then
uo.Press(36)
end if
if CurrentX>X and CurrentY>Y then
uo.Press(38)
end if
if CurrentX>X and CurrentY<Y then
uo.Press(37)
end if
uo.Print('KeyPressed')
wait(stepdelay)
if LastX==uo.GetX() and LastY==uo.GetY() and LastD==uo.GetDir() then
uo.Print('PathFind')
recursInd=0
repeat
#################################################
Index=LastD
uo.Print(str(Index))
fout=0
repeat ; идем в обход пока не упремся снова или не кончится стена
uo.Print('Iteration')
CurrentX=uo.GetX()
CurrentY=uo.GetY()
LastD=uo.GetDir()
uo.Press(Turn[ Index ])
wait(stepdelay)
if (uo.GetX()==LastX and uo.GetY()==LastY and LastD==uo.GetDir()) then
fout=1 ; уперлись
else
MoveX=uo.GetX()-CurrentX
MoveY=uo.GetY()-CurrentY
uo.Print('deltas '+str(MoveX)+' '+str(MoveY))
if DeltaX[ Index ]==MoveX and DeltaY[ Index ]==MoveY then
fout=2 ; препятствие пройдено
end if
end if
until fout
uo.Print('fout '+ str(fout))
if fout==1 then ; уходим на следующий поворот
recursInd=recursInd+1
Push(str( ind ))
;ld = ind
else ; fout == 2
; надо попытаться восстановить контекст из стека, или выйти из обхода
uo.Print('Iter '+ str(recursInd))
pathFind=0
if recursInd then ; восстановление
pathFind=1
recursInd=recursInd-1
LastD=val(Pop())-1
if LastD==-1 then
LastD=7
end if
uo.Press(turn[LastD])
wait(stepdelay) ; в сиkу того, что ондо нажатие меняет напрваление
end if
end if
#################################################
until not recursInd and not pathFind
uo.Print('PathFind END')
end if
until 0
end sub
Code: Select all
GoToTile( 1913, 276, 1, False )
Code: Select all
Sub GoToTile( OX, OY, N, S )
VAR myx, myy, MD, J
VAR Lx1, Ly1
VAR Lx2, Ly2
VAR Sx, Sy
VAR T
VAR Des = N
VAR MoveDelay = 100
J = 1
MD = MoveDelay * 1.5
myx = uo.getx()
myy = uo.gety()
MoveOnce( GetDir( uo.getx(), uo.gety(), ox, oy), MD, False)
Sx = 0
Sy = 0
Lx1 = uo.getx() / 2
Ly1 = uo.gety() / 2
Lx2 = Lx1 / 2
Ly2 = Ly1 / 2
T = UO.Timer()
If (GetDistance(ox, oy) <> N) OR ( (NOT S) AND GetDistance(ox, oy) > N ) Then
UO.Exec('exec PermResend')
EndIf
While ( (GetDistance(ox, oy) <> N) OR ((NOT S) and GetDistance(ox, oy) > N) ) and ( OX >= 0 ) and ( OY >= 0 )
If ( (UO.Timer() - T) * 15 > MoveDelay ) Then
T = UO.Timer()
Lx2 = Lx1
Ly2 = Ly1
Lx1 = myx
Ly1 = myy
myx = uo.getx()
myy = uo.gety()
endIf
MD=MoveDelay
If ((OX-uo.getx())*(OX-uo.getx())+(OY-uo.gety())*(OY-uo.gety())>0) Then
MD = MD * 3 / GetDistance( ox, oy )
EndIf
wait(MD)
If GetDistance( OX, OY ) > Des Then
MoveOnce(GetDir(uo.GetX(),uo.GetY(),ox,oy),MD,False)
Else
If S Then
If GetDistance(OX,OY)<Des Then
If GetDistance(OX,OY)<>0 Then
MoveOnce(GetDir(ox,oy,uo.GetX(),uo.GetY()),MD,False)
Else
MoveOnce(GetDir(uo.GetX(),uo.GetY(),Lx2,Ly2),MD,False)
EndIf
EndIf
EndIf
EndIf
If GetDistance(OX,OY)<>Des Then
If (Lx2==uo.getx()) and (Ly2==uo.gety()) Then
If (Sx<>uo.getx()) or (Sy<>uo.gety()) Then
J=1
EndIf
J=J+1
UO.Resend()
Sx = uo.getx()
Sy = uo.gety()
Stun(ox,oy,J)
EndIf
EndIf
Wend
UO.Exec( 'terminate PermResend' )
endsub
;
; ============ MOVEONCE ===
; Процедура MoveOnce - хождение в определённую сторону
; Направления:
; Система направлений по клавишам Нумпада
; 8 = 1 | 2 = -1
; 9 = 2 | 1 = -2
; 6 = 3 | 4 = -3
; 3 = 4 | 7 = -4
;
; Такая система позволяет с лёгкостью получать направление, обратное
; данному...
;
Sub MoveOnce( Dir, Del, Rev )
VAR Num
Var MoveNumber = 1
If Rev Then
Num = MoveNumber + 1
Else
Num = MoveNumber
EndIf
If ( Num > 0 ) and ( Dir <> 0 ) Then
If Dir == 1 Then
UO.Press( 38, Num, Del )
EndIf
If Dir == 2 Then
UO.Press( 33, Num, Del )
EndIf
If Dir == 3 Then
UO.Press( 39, Num, Del )
EndIf
If Dir == 4 Then
UO.Press( 34, Num, Del )
EndIf
If Dir == -1 Then
UO.Press( 40, Num-1, Del )
EndIf
If Dir == -2 Then
UO.Press( 35, Num, Del )
EndIf
If Dir == -3 Then
UO.Press( 37, Num, Del )
EndIf
If Dir == -4 Then
UO.Press( 36, Num, Del )
EndIf
If Rev Then
If Dir <> -1 Then
UO.Press( 40, 1, Del )
EndIf
EndIf
EndIf
endsub
;
; ============== GETDIR ===
; Функция GetDir возвращает направление, по которому надо идти
; к координате
;
Sub GetDir( myx, myy, ox, oy )
VAR I, J
J = 0
VAR X = ox - myx
VAR Y = oy - myy
I = GetQDir( Abs(X), Abs(Y) )
If X >= 0 Then
If Y >= 0 Then
If I == 1 Then
J = -2
Else
If I == 2 Then
J = -1
Else
If I == 3 Then
J = 4
EndIf
EndIf
EndIf
Else
If I == 1 Then
J = 2
Else
If I == 2 Then
J = 3
Else
If I == 3 Then
J = 4
EndIf
EndIf
EndIf
EndIf
Else
If Y >= 0 Then
If I == 1 Then
J = -2
Else
If I == 2 Then
J = -3
Else
If I == 3 Then
J = -4
EndIf
EndIf
EndIf
Else
If I == 1 Then
J = 2
Else
If I == 2 Then
J = 1
Else
If I == 3 Then
J = -4
EndIf
EndIf
EndIf
EndIf
EndIf
RETURN J
endsub
;
; =============== GETQDIR ===
;
;
Sub GetQDir( x, y )
VAR Ep = 0.172
VAR J = 0
If X == 0 Then
J = 1
Else
If ( Y / X ) < Ep Then
J = 3
Else
If ( X / Y ) < Ep Then
J = 1
Else
J = 2
EndIf
EndIf
EndIf
RETURN J
endsub
;
; ============== GETDISTANCE ===
; Функция GetDistance возвращает расстояние до координат
; (как UO.GetDistance - до объекта)
;
; Почему так - потому что учим математику :)
;
Sub GetDistance( X, Y )
VAR A, B, C
A = abs( X - UO.GetX() )
B = abs( Y - UO.GetY() )
If A > B Then
C = A
Else
C = B
EndIf
Return C
endsub
;
; ============= PERP ===
; Функция Perp возвращает направление, перпендикулярное введённому
;
Sub Perp( Dir )
VAR D = Dir
If Dir == 1 Then
D = 3
EndIf
If Dir == 2 Then
D = 4
EndIf
If Dir == 3 Then
D = -1
EndIf
If Dir == 4 Then
D = -2
EndIf
If Dir == -1 Then
D = -3
EndIf
If Dir == -2 Then
D = -4
EndIf
If Dir == -3 Then
D = 1
EndIf
If Dir == -4 Then
D = 2
EndIf
RETURN D
endsub
;
; =============== STUN ===
; Обход препятствий
;
Sub Stun( X, Y, N )
VAR I
VAR myx
VAR myy
VAR MoveDelay = 100
myx = uo.getx()
myy = uo.gety()
For I=1 to N
MoveOnce(perp(GetDir(myx,myy,x,y)),MoveDelay,False)
Next
Wait(MoveDelay)
UO.Resend()
If (myx==uo.getx()) and (myy==uo.gety()) Then
For I=1 to N
MoveOnce(-perp(GetDir(myx,myy,x,y)),MoveDelay,False)
Next
Wait(MoveDelay)
UO.Resend()
EndIf
If (myx==uo.getx()) and (myy==uo.gety()) Then
For I=1 to N
MoveOnce(-GetDir(myx,myy,x,y),MoveDelay,False)
Next
Wait(MoveDelay)
Stun(x,y,N)
EndIf
endsub
;
; ============= ABS ===
; Убирает знак минуса в отрицательных числах
;
Sub abs( a )
VAR b
If a < 0 Then
b = -a
Else
b = a
endif
return b
endsub
;
; ============== PERMRESEND ===
;
Sub PermResend()
Var Mn = 9
VAR MoveDelay = 100
Repeat
UO.Resend()
Wait( MoveDelay * Mn )
Until ( 1 > 2 )
Endsub
Code: Select all
GoToTile( 1913, 276, 1, False )