Results 1 to 1 of 1

Thread: Wierd problem

  1. #1
    Join Date
    Aug 2008
    Location
    Finland
    Posts
    2,851
    Mentioned
    3 Post(s)
    Quoted
    2 Post(s)

    Default Wierd problem

    I'm writing a Karamja lobby fisher, but when I run this script it only prints "Trying to fish..." and then nothing! The wierdest thing is that it doesn't terminate either.
    It should print "Fishing spots found: <insert number here>" if it finds fishing spots and "No fishingspots found!" if it doesn't, but it doesn't print neither of these. It also doesn't move the mouse anywhere.

    SCAR Code:
    program Karamja;
    {.include srl/srl.scar}
    {.include srl/srl/skill/fishing.scar}

    function PixelShift(x1, y1, x2, y2, t: integer): integer;
    var
      bmp, bmp2, x, y: integer;
    begin
      bmp := BitmapFromString((x2 -x1), (y2 - y1), '');
      bmp2 := BitmapFromString((x2 -x1), (y2 - y1), '');
      SafeCopyCanvas(GetClientCanvas, GetBitmapCanvas(bmp), x1, y1, x2, y2, 0, 0, (x2 - x1), (y2 -  y1));
      wait(t);
      SafeCopyCanvas(GetClientCanvas, GetBitmapCanvas(bmp2), x1, y1, x2, y2, 0, 0, (x2 - x1), (y2 -  y1));
      for x := 1 to (x2 - x1) do
       for y := 1 to (y2 - y1) do
        if FastGetPixel(bmp2, x, y) <> FastGetPixel(bmp, x, y) then
         Inc(result);
      FreeBitmap(bmp);
      FreeBitmap(bmp2);
    end;

    procedure WaitWhileMoving;
    var
      T: Integer;
    begin
      if (not LoggedIn) then Exit;
      T := GetSystemTime + 40000 + Random(5000);
      while (PixelShift(MMCX-30, MMCY-30, MMCX+30, MMCY+30, 500) > 200) and (GetSystemTime < T) do
        if (Random(3) = 0) then
          SleepAndMoveMouse(500 + Random(200))
        else
          Wait(500 + Random(200));
    end;

    procedure WaitWhileFishing;
    var
      StillFishing: Boolean;
      T, MaxT, FishingCage, X, Y: Integer;
    begin
      if (not LoggedIn) then Exit;
      FishingCage := BitmapFromString(9, 8, 'beNpVzFsKwzAMRNHlhlq' +
           'v0Tg1Xn4U14EU7sfAQQLRp0f/iJt3z2EYx6FNs/lDzXVRVaNIgtnn' +
           'rfiqc5OxKX6UD0WOeNM5q5tskxlFoEGes/JcVxyV/lMsAkdVox4qN' +
           'uFF5hSFXRprXtg=');
      MaxT := GetSystemTime + RandomRange(180000, 25000);
      repeat
        T := GetSystemTime + 7000 + Random(1000);
        repeat
          WriteLn('Searching cage...');
          if FindBitmapToleranceIn(FishingCage, X, Y, 215, 200, 275, 260, 35) then
          begin
            StillFishing := True;
            Break;
          end;
          if (GetSystemTime > T) then
          begin
            StillFishing := False;
            Break;
          end;
          Wait(10);
          Disguise('Still fishing');
        until(False);
        if StillFishing then
          if Random(3) = 0 then
            SleepAndMoveMouse(500 + Random(500))
          else
            Wait(500 + Random(500));
      until((not StillFishing) or (GetSystemTime > MaxT));
      Disguise('Not fishing!');
      FreeBitmap(FishingCage);
    end;

    function Fish: Boolean;
    var
      Left: Boolean;
      I, Hi: Integer;
      FP: TPointArray;
    begin
      if (not LoggedIn) then Exit;
      if FindFishSpotsTPA(FP) then
      begin
        WriteLn('Fishing spots found: '+IntToStr(Length(FP)));
        SortTPAFrom(FP, Point(245, 275));
        Hi := High(FP);
        for I := 0 to Hi do
        begin
          MMouse(FP[I].X, FP[I].Y, 0, 0);
          if WaitUpText('Cage', 450 + Random(100)) then
          begin
            Left := RBool;
            Mouse(FP[I].X, FP[I].Y, 0, 0, Left);
            if ((DidRedClick)and(Left)) or (WaitOption('Cage', 450 + Random(100))and(not Left)) then
            begin
              Result := True;
              WaitWhileMoving;
              WaitWhileFishing;
            end;
            Exit;
          end;
        end;
      end else
        WriteLn('No fishingspots found!');
    end;


    begin
      ActivateClient;
      Wait(300);
      SetupSRL;
      WriteLn('Trying to fish...');
      if Fish then
        WriteLn('yea!');
    end.

    The problem might be in FindFishSpotTPA but I didn't see anything wrong there:
    I also tried taking away whirlpool check, didnt' help.
    SCAR Code:
    {*******************************************************************************
    Function FindFishSpotsTPA(var VTPA:TPointArray):boolean;
    By: Rasta Magician
    Description: Finds all possible Fish Spots and stores them in the given TPA
                 Returns true if found at least one, false if none
    *******************************************************************************}

    Function FindFishSpotsTPA(var VTPA:TPointArray):boolean;
    var
      TPA:  TPointArray;
      ATPA: T2DPointArray;
      i, tmpCTS, VTPASize: Integer;
      TP: TPoint;
    begin
      Result := False;
      if (not LoggedIn) then exit;

      tmpCTS := GetColorToleranceSpeed;
      ColorToleranceSpeed(2);
      SetColorSpeed2Modifiers(0.12, 0.27);

      FindColorsSpiralTolerance(MSCX, MSCY, TPA, 11379611, MSX1, MSY1, MSX2, MSY2, 11);

      ColorToleranceSpeed(tmpCTS);
      SetColorSpeed2Modifiers(0.2, 0.2);

      if (Length(TPA) < 1) then exit;

      VTPASize := 1;
      SetLength(VTPA, 1);

      ATPA := SplitTPA(TPA, 10);
      SortATPAFrom(ATPA, Point(MSCX, MSCY));
      for i := 0 to High(ATPA) do
      begin
        TP := MiddleTPA(ATPA[i]);

        if FindWhirlPoolXY(TP.x, TP.y) then Continue;

        VTPA[VTPASize - 1] := TP;
        Inc(VTPASize);
        SetLength(VTPA, VTPASize);
      end;

      Result := (VTPASize > 1);
    end;

    EDIT: I debugged more and found that the probelm is in line
    ATPA := SplitTPA(TPA, 10);
    what what what?

    EDIT: Problem solved. I believe SplitTPA takes a very long time when it's processing TPA that covers half the client
    Last edited by marpis; 10-04-2009 at 06:41 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •