Forum in READ ONLY mode! All questions and discussions on Discord official server, invite link: https://discord.gg/VxsGzJ7

помогите исправить скрипт

тут можно задать вопрос по скриптингу
Post Reply
kifirkin
Posts: 3
Joined: 25.10.2008 11:51

помогите исправить скрипт

Post by kifirkin »

Люди добрые!проблема такая,в шахте 3 или 4 разных видов тайлов,начиная с 1339 по 43 или 44...пытался исправить,но после этого скрипт начинал глючить и пр...помогите пожалуйста,заранее спасибо!

Code: Select all

program mining;

{$Include 'all.inc'}

const
xa		=	6;
ya		=	6;
xb		=	-6;
yb		=	-6;
pixt		=	$0e85;
bcheese	= 	$097e;
mcheese	=	$097d;
scheese	=	$097c;
guardmode	=	0;
tilenum		=	1339;
tilenummax	=	1344;

var
posx,posy	:	array[1..250] of integer;
PickaxeID	:	cardinal;
stime,gtime	:	TDateTime; 
c,max		:	integer;
Exitflag		:	boolean;
stx,sty		:	integer;

// ----------------------------------------------------------------
// 2)
procedure RestoreStamina; 
// если стамины мало, восстанавливаем ее чару до половины 
begin 
   if (connected) and (Stam < 5) then 
   begin 
      repeat
         wait(1000); 
         waitconnection(10000); 
      until Stam > 25; 
   end; 
end;

// 1)
procedure GotoXY(x,y,prec : integer; runflag : boolean); 
   // x,y - координаты, в которые идем 
   // prec - точность подхода 
   // runflag - бежать или идти 
   // v. 1.04 (с) Edred, скрипт портирован с инжекта 
   // оригинальная версия Yoko с доработкой AGRS и Edred. 
   var ld, ldc, dx, dy, mx, my : Integer; 
   begin 
      ld := 0; ldc := 0; 
      while true do 
      begin 
         dx := GetX(self) - x; if dx < 0 then dx := 0 - dx; 
         dy := GetY(self) - y; if dy < 0 then dy := 0 - dy; 
         if dy > dx then dx := dy; 
         if dx <= prec then exit; 
         mx := GetX(self); my := GetY(self); 
         dx := mx - x; if dx < 0 then dx := 0 - dx; 
         dy := my - y; if dy < 0 then dy := 0 - dy; 
         if dy > dx then dx := dy; 
         if dx <= prec then exit; 
         if ld = dx then begin 
	RestoreStamina;
            ldc := ldc + 1; 
            if ldc > 10 then begin addtosystemjournal( 'GotoXY: Cannot reach location!' ); exit; end; 
         end 
         else ld := dx; 
         waitconnection(10000); 
         if mx = x then begin 
            if my = y then exit; 
            // North 
            if my > y then begin Raw_Move(0,runflag); continue; end; 
            // South 
            Raw_Move(4,runflag); continue; 
         end; 
         if mx < x then begin 
            // Northeast 
            if my > y then begin Raw_Move(1,runflag); continue; end; 
            // East 
            if my = y then begin Raw_Move(2,runflag); continue; end; 
            // Southeast 
            Raw_Move(3,runflag); continue; 
         end; 
         // Southwest 
         if my < y then begin Raw_Move(5,runflag); continue; end; 
         // West 
         if my = y then begin Raw_Move(6,runflag); continue; end; 
         // Nortwest 
         Raw_Move(7,runflag); continue; 
      end; 
   end;

// 3)
procedure checkpix;
 begin
  waitconnection(10000);
  if (GetType(ObjAtLayer(RhandLayer)) <> pixt) then
   begin
    if (ObjAtLayer(RhandLayer) <> 0) then 
     begin 
      waitconnection(10000);
      checksave;
      Disarm; 
      wait(2000); 
     end;
    WaitConnection(10000);
    PickaxeID:=FindTypeEx(pixt,$FFFF,backpack,true);
    if findcount < 1 then begin exitflag:=true; Exit; end;
    CheckSave();
    equip(RhandLayer,PickaxeID);
    wait(2000);
    CheckSave();
    WaitConnection(10000);
   end
   else
    begin
     CheckSave();
     WaitConnection(20000)
    end;
  end;

// 4)
procedure guards;
 var n		:	integer;
 begin
  if (guardmode = 0) then Exit;
  n:=injournal('attacking you');
  if (n <> -1) then
   begin
    uosay('.guards');
    gtime:=now;
    SetJournalLine(n,' ');
   end;
  if (not dead) and (maxlife-life>7) and (now-stime > EncodeTime(0,0,7,0)) then 
   begin 
    uosay('.guards'); 
    gtime:=now; 
   end;
 end;

// 5)
procedure checkandset;
 begin
  Exitflag:=false;
  gtime:=now-EncodeTime(0,0,10,0);

  if (xb>xa) or (yb>ya) then 
   begin
    AddToSystemJournal('Wrong coords, exiting!');
    Exitflag:=true;
   end;

  stx:=getx(self);
  sty:=gety(self);
 end;

// 6)
procedure minearound;
 var kx,ky,k,i,j : integer;
 begin
  kx:=getx(self);
  ky:=gety(self);

  for i:=-2 to 2 do
  for j:=-2 to 2 do
   begin
    checkpix;
    if (connected) and ((Exitflag) or (dead)) then Exit;
    waitconnection(10000);
    if TargetPresent then CancelTarget;
    stime := Now; 
    useobject(PickaxeID);
    WaitForTarget(5000);
    TargetToTile(tilenum, (kx+i), (ky+j), getz(self));

    k := 0; 

    repeat 
     guards;
//	 if (InJournal('пойти добывать')<>-1) or (k > 300) then begin 
//		useobject(PickaxeID);
//        	WaitForTarget(5000);
//  		TargetToTile(tilenummax, (kx+i), (ky+j), getz(self));
//	 end;
     wait(1000);
     k := k + 1; 
     checksave; 
     CheckTargetError(2,2);
    until (InJournalBetweenTimes('инструмент|прекратили|слишком',stime, Now)<>-1) or (k > 300) or (not connected) or (dead); 
   end;
 end;

// 7)
procedure razbienie;
var sx,sy	:	integer;
 begin
  sx:=getx(self)+xb;
  sy:=gety(self)+yb;
  max:=1;
  while sy<sty+ya do begin
   while sx<stx+xa do        
    begin
     posx[max]:=sx+2;
     posy[max]:=sy+2;
     sx:=sx+5;
     max:=max+1;
    end; 
   sx:=getx(self)+xb;
   sy:=sy+5;
  end;
 end;

// ----------------------------------------------  

Begin

 Disarm;
 wait(500);
 checkandset;
 razbienie;
 while (true) do
  begin

   if (connected) and ((Exitflag) or (dead)) then Exit;

   for c:=1 to max-1 do
    begin
     if (connected) and ((Exitflag) or (dead)) then Exit;
     waitconnection(10000);
     checksave;
     GotoXY(posx[c],posy[c],0,false); 
     wait(500);
     waitconnection(10000);
     checksave;
     minearound;
    end;
  end;
 AddToSystemJournal('End of script');
End.
Alexej
Novice
Novice
Posts: 79
Joined: 06.06.2008 11:55
Contact:

Post by Alexej »

надо делать проверку типа тайла перед копанием:
http://stealth.od.ua/forum/viewtopic.php?t=1041

как у меня реализована процедура копания:

Code: Select all

Procedure Kopalka;
  begin 
    
    WaitConnection(3000);
    CheckSave;

    Addtosystemjournal('копаем');
    if (not dead) then 
    begin 
      Hide;
      for x := -1 to 1 do 
      begin 
	      for y := -1 to 1 do 
          begin  
	    CheckDead
	    stime := Now;
	    k := 0;
      kk := 0;
	    UseObject(BackPack);
 	    CheckTools;
 	    CheckShovels;
      checksave;
	    wait(500);
	    GetTileData((getx(self)+x),(gety(self)+y), 0, 1, tile, z1);
	    wait(100);
	    if (tile >= 1338) and (tile <= 1348) then
	      begin
		repeat
		  Hide;

      WaitConnection(3000);
      CheckSave;

 		  wait(100);
      If (LastContainer <> BackPack) Then UseObject(BackPack);
      If (InJournalBetweenTimes('Welcome,',stime,Now)<>-1) Then UseObject(BackPack);
// 		  Addtosystemjournal('тайл = '+inttostr(Tile));
//      FindTypeEx(shovel, $ffff, backpack, false);
      FindType(shovel,backpack);
// 		  Addtosystemjournal('lopat '+ inttostr(CountEx(shovel, $FFFF, backpack)));
		  if TargetPresent then CancelTarget;
      checksave;
      If (InJournalBetweenTimes('Welcome,',stime,Now)<>-1) Then UseObject(BackPack);
// 		  Addtosystemjournal('прицела нет ');
// 		  UseObject(finditem);
      If (FindType(shovel,backpack) <= 0) Then 
      begin 
        UseObject(BackPack);
        wait(1500);
        FindType(shovel,backpack);
        UseType(shovel,$FFFF);
      end;
      UseType(shovel,$FFFF);
      If (FindType(shovel,backpack) <= 0) Then 
      begin 
        
        WaitConnection(3000);
        CheckSave;

        UseObject(BackPack);
        wait(1500);
        FindType(shovel,backpack);
      end;
// 		  Addtosystemjournal('юзаем лопату ');
//  		  WaitJournalLine(Now,'cliloc# 0xACF9',1000);
      WaitForTarget(3000);
      if TargetPresent then 
      begin
        TargetToTile(Tile,getx(self)+x,gety(self)+y,getz(self)); 
// 		    Addtosystemjournal('прицел есть, копаем '+inttostr(Tile)+','+inttostr(getx(self)+x)+','+inttostr(gety(self)+y)+','+inttostr(getz(self)));
// 		  CheckTargetError(5,2); 
		  w := Weight;
      wait(500);
		repeat
		  wait(100);
      k := k + 1;
      
      WaitConnection(3000);
      CheckSave;

// 		  Addtosystemjournal('k = ' +inttostr(k));
		until (InJournalBetweenTimes(Cli[0],stime,Now)<>-1) or 
		      (InJournalBetweenTimes(Cli[1],stime,Now)<>-1) or 
		      (InJournalBetweenTimes(Cli[2],stime,Now)<>-1) or 
		      (InJournalBetweenTimes(Cli[3],stime,Now)<>-1) or 
		      (InJournalBetweenTimes(Cli[4],stime,Now)<>-1) or 
		      (InJournalBetweenTimes(Cli[5],stime,Now)<>-1) or 
		      (InJournalBetweenTimes(Cli[6],stime,Now)<>-1) or 
		      (InJournalBetweenTimes(Cli[7],stime,Now)<>-1) or 
		      (InJournalBetweenTimes(Cli[8],stime,Now)<>-1) or 
		      (InJournalBetweenTimes(Cli[9],stime,Now)<>-1) or 
		      (InJournalBetweenTimes(Cli[10],stime,Now)<>-1) or 
		      (InJournalBetweenTimes(Cli[11],stime,Now)<>-1) or 
		      (InJournalBetweenTimes(Cli[12],stime,Now)<>-1) or 
		      (InJournalBetweenTimes(Cli[13],stime,Now)<>-1) or 
		      (InJournalBetweenTimes(Cli[14],stime,Now)<>-1) or 
		      (InJournalBetweenTimes(Cli[15],stime,Now)<>-1) or 
		      (InJournalBetweenTimes(Cli[16],stime,Now)<>-1) or 
		      (InJournalBetweenTimes(Cli[17],stime,Now)<>-1) or 
		      (InJournalBetweenTimes(Cli[18],stime,Now)<>-1) or
          (InJournalBetweenTimes(Cli[19],stime,Now)<>-1) or 
		      (InJournalBetweenTimes(Cli[20],stime,Now)<>-1) or 
		      (InJournalBetweenTimes(Cli[21],stime,Now)<>-1) or 
		      (InJournalBetweenTimes(Cli[22],stime,Now)<>-1) or 
		      (InJournalBetweenTimes(Cli[23],stime,Now)<>-1) or 
		      (InJournalBetweenTimes(Cli[24],stime,Now)<>-1) or 
		      (InJournalBetweenTimes(Cli[25],stime,Now)<>-1) or 
		      (InJournalBetweenTimes(Cli[26],stime,Now)<>-1) or 
		      (InJournalBetweenTimes(Cli[27],stime,Now)<>-1) or 
		      (InJournalBetweenTimes(Cli[28],stime,Now)<>-1) or
          (InJournalBetweenTimes(Cli[29],stime,Now)<>-1) or 
		      (InJournalBetweenTimes(Cli[30],stime,Now)<>-1) or 
		      (InJournalBetweenTimes(Cli[31],stime,Now)<>-1) or 
		      (InJournalBetweenTimes(Cli[32],stime,Now)<>-1) or 
          (InJournalBetweenTimes('You put some',stime,Now)<>-1) or
          (w < Weight) or (k > 200);
		      If (Weight >= MaxWeight) then Plavka;
		      wait(100);
          checksave;
          kk := kk + 1;
      end;
		until (InJournalBetweenTimes(Cli[0],stime,Now)<>-1) or 
		      (InJournalBetweenTimes(Cli[1],stime,Now)<>-1) or 
		      (InJournalBetweenTimes(Cli[27],stime,Now)<>-1) or 
		      (InJournalBetweenTimes(Cli[28],stime,Now)<>-1) or 
		      (InJournalBetweenTimes(Cli[29],stime,Now)<>-1) or
		      (InJournalBetweenTimes(Cli[32],stime,Now)<>-1) or 
          (kk > 7);
		      wait(100);
        end;
	  end;
      end; 
    end;
  end;
алгоритм - проверяем тип тайла из мула, если подходит по списку - копаем, пробывай...
kifirkin
Posts: 3
Joined: 25.10.2008 11:51

Re: помогите исправить скрипт

Post by kifirkin »

этот скрипт завести так и не удалось :(
спасибо за ответ, я более ли менее допер че куда, нарыв такой вот скрипт на питоне
я его достаточно сильно перепилил, и появились новые проблемы...
теперь когда на нем копает много чаров, при дисконнекте одного из них вылетают ошибки и дико все портят :(

Code: Select all

Call stack:
  (002C7200){Stealth.exe } [006C8200] uData.TData.GetClilocMessage (Line 315, "uData.pas" + 1) + $9
  (00273EE3){Stealth.exe } [00674EE3] ClassCharacter.TCharacter.GetInfoFromPacket_0xD6 (Line 9501, "ClassCharacter.pas" + 20) + $28
  (0026A4EB){Stealth.exe } [0066B4EB] ClassCharacter.TCharacter.RedirectGamePacket (Line 5960, "ClassCharacter.pas" + 341) + $9
  (00268A21){Stealth.exe } [00669A21] ClassCharacter.TCharacter.GameClientOnRead (Line 5286, "ClassCharacter.pas" + 125) + $F
  (000BEDBE){Stealth.exe } [004BFDBE] ScktComp.TCustomSocket.Event (Line 1868, "common\ScktComp.pas" + 20) + $10
  (000BD57E){Stealth.exe } [004BE57E] ScktComp.TCustomWinSocket.Event (Line 980, "common\ScktComp.pas" + 1) + $11
  (000BDAD9){Stealth.exe } [004BEAD9] ScktComp.TCustomWinSocket.WndProc (Line 1168, "common\ScktComp.pas" + 2) + $5
  (0002C1F0){Stealth.exe } [0042D1F0] Classes.StdWndProc (Line 11583, "common\Classes.pas" + 8) + $0

An exception raised at <<1 Март>>, 04:16:51:186
Access violation at address 006C8200 in module 'Stealth.exe'. Read of address 00000014
(002C7200){Stealth.exe } [006C8200] uData.TData.GetClilocMessage (Line 315, "uData.pas" + 1) + $9

Code: Select all

from datetime import datetime
import random

bad_points = []
pickaxe = 0x0E85
drop = 0x14ED
allmsg = "You dig|You put|is no |It seems|too far|Try|Can't"
trymsg = "You loosen|You dig"
endmsg = "There is no|It seems"
artime = 25000
SetARStatus(True)

def checklag(time):
    if Connected():
        now = datetime.now()
        ClearJournal()
        ClickOnObject(Backpack())
        WaitJournalLine(now,'backpack',time)
        Wait(50)
        return True
    Wait(time)
    return True    
        
def FindTiles(center_x, center_y, radius):
    min_x, min_y = center_x-radius, center_y-radius
    max_x, max_y = center_x+radius, center_y+radius
    tiles_coords = []
    for tile in range(1339,1359):
        tiles_coords += GetStaticTilesArray(min_x,min_y,max_x,max_y,WorldNum(),tile)
        checklag(artime)
    return tiles_coords
    
while True and checklag(artime):
    for t,x,y,z in FindTiles(GetX(Self()),GetY(Self()), 2):
        if checklag(artime) and ([x,y] not in bad_points): # and MoveXY(x,y,True,2,False):
            now = datetime.now()
            if (ObjAtLayerEx(RhandLayer(), Self()) == 0) and Connected():
                equip(RhandLayer(), FindType(pickaxe, Backpack()))
                Wait(500)
            if TargetPresent():
                CancelTarget()
                CancelWaitTarget()                    
            UseObject(ObjAtLayerEx(RhandLayer(), Self()))
            WaitJournalLine(now,'Where do you wish to dig?',artime)
            WaitTargetTile(t,x,y,0)
            WaitJournalLine(now,'You stop mining.|You cannot see that|You cannot mine here.|That is too far away.',160000)
            if InJournalBetweenTimes('Saving World State.', now, datetime.now()) >=0:
                Wait(12000)
            if InJournalBetweenTimes('That is too far away.|You cannot see that|You cannot mine here.', now, datetime.now()) >=0:
                if [x,y] not in bad_points:
                    bad_points.append([x,y])
            checklag(artime)
            FindTypeEx(drop,0,Backpack(),False)
            if FindCount() > 0:
                MoveItem(FindItem(),0,Ground(),0,0,0)
                Wait(500)     
    if checklag(artime):
        offset = 3
        x,y = GetX(Self()), GetY(Self())
        while x == GetX(Self()) and y == GetY(Self()) and checklag(artime):
            rdx = random.choice([-offset,offset])
            rdy = random.choice([-offset,offset])
            newMoveXY(x+rdx,y+rdy,False,0,True)
            Wait(5000)
               
User avatar
Vizit0r
Developer
Developer
Posts: 3958
Joined: 24.03.2005 17:05
Contact:

Re: помогите исправить скрипт

Post by Vizit0r »

kifirkin - в асю мне напиши
"Пишите код так, как будто сопровождать его будет склонный к насилию психопат, который знает, где вы живете". (с) Макконнелл, "Совершенный код".
Post Reply