Results 1 to 3 of 3

Thread: Scipt is able to detect colour accurately one desktop, fails on laptop

  1. #1
    Join Date
    Mar 2019
    Posts
    3
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default Scipt is able to detect colour accurately one desktop, fails on laptop

    Code:
    program new;
    {$i SRL\osr.simba}
    
    const
      MSX1 = 400;
      MSY1 = 200;
      MSX2 = 675;
      MSY2 = 500;
    
    var
     x, y:integer;
    
    function rsps_getUpText(text: string): boolean;
    var
      yellowTPA: tpointarray;
      yellowATPA: t2dpointarray;
      upText: string;
    begin
      FindColorsTolerance(yellowTPA, 65535, 0, 0, 350, 200, 0);
      if (length(yellowTPA) > 1) then
        yellowATPA := splitTPAEx(yellowTPA, 1, 10);
        sortATPAFromFirstPointX(yellowATPA, point(0, 0));
        upText:= getTextATPA(yellowATPA, 5, 'UpChars07');
    
        if (upText = text) then
        begin
          result := true;
        end else
          result := false;
    end;
    
    function IsWalking(): boolean;
    var
      BMPA, BMPB, w, h: Int32;
    begin
      try
        BMPA := BitmapFromClient(MSX1, MSY1, MSX2, MSY2);
        Wait(69);
        BMPB := BitmapFromClient(MSX1, MSY1, MSX2, MSY2);
        GetBitmapSize(BMPA, w, h);
        Result := (CalculatePixelShift(BMPA, BMPB, [0, 0, w-1, h-1]) > 50000);
      finally
        if BitmapExists(BMPA) then FreeBitmap(BMPA);
        if BitmapExists(BMPB) then FreeBitmap(BMPB);
      end;
    end;
    
    function findPikachu: boolean;
    var
      TPAA: T2DPointArray;
      TPA: TPointArray;
      CTS, clicked, I: Integer;
    begin
      CTS := GetToleranceSpeed();
      SetColorToleranceSpeed(2);
      SetToleranceSpeed2Modifiers(0.03, 1.11);
      FindColorsSpiralTolerance(400, 200, TPA, 4701409, 0, 0, MSX2, 500, 12);
      SetColorToleranceSpeed(CTS);
      TPAA := TPAToATPAEx(TPA, 30, 30);
      SortATPASize(TPAA, True);
      WriteLn(TPAA);
    
      For I := 0 To High(TPAA) do
      If (GetArraylength(TPAA[i]) > 100) Then
      begin
        MiddleTPAEx(TPAA[i], x, y);
        MoveMouse(X, Y);
        writeln(TPAA[i]);
        Wait(250);
        If (rsps_getUpText('Pikachu')) Then
        begin
          while IsWalking() do Wait(500);
          ClickMouse(x, y, mouse_left);
          Wait(4800);
          exit;
        end;
      end;
    
    
      result := true;
    end;
    
    begin
      repeat
        findPikachu;
      until(false);
    end.
    I have written the above script by plagiarising different scripts and putting them together.

    I wrote this with my Laptop plugged into my PC Monitor and it works perfectly, it accurately selects the colour and identifies the NPCs. However, when I run it on my laptop it is consistently off by about 50-100 px. It can still see the colours etc but each coordinate returned by FindColorsSpiralTolerance is off by 50-100.

    The resolution of my monitor and laptop is the same 1920x1080. Is there some configuration I need to do with the script to make it work on different screens?

  2. #2
    Join Date
    May 2012
    Location
    Glorious Nippon
    Posts
    1,011
    Mentioned
    50 Post(s)
    Quoted
    505 Post(s)

    Default

    Is your scale 100% on both computers?

  3. #3
    Join Date
    Mar 2019
    Posts
    3
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Nope that was the issue, thanks.

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
  •