Results 1 to 4 of 4

Thread: Some FastGetColor help...

  1. #1
    Join Date
    Apr 2007
    Location
    Perth, Australia
    Posts
    3,926
    Mentioned
    3 Post(s)
    Quoted
    2 Post(s)

    Default Some FastGetColor help...

    Ok so I'm making a yew cutter and I'm making the Ent finding function right now. I was thinking of doing something that I saw in a thread a while back.

    What I'm trying to do is get a bitmap of the yew tree (or just get the position of points of a particular colour) then checking a bit later to see if the points have changed. This is what I have so far:

    SCAR Code:
    function FindEnt(ax, ay: Integer): Boolean;
    var
      TempBMP, NoPts, CTS, x1, y1, x2, y2, Dist: Integer;
      Pts, CPts: TPointArray;
      TP: TPoint;
      TempBool: Boolean;
    begin
      Dist := 50;  //Dist either side, up or down of the centre point
      if (not(LoggedIn)) then Exit;
      CTS := GetColorToleranceSpeed;
      ColorToleranceSpeed(2);
      NoPts := 0;
      x1 := ax - Dist; y1 := ay - Dist; x2 := ax + Dist; y2 := ay + Dist;
      if (x1 < 0) then x1 := 0; if (y1 < 0) then y1 := 0;
      TempBMP := BitmapFromString(x2 - x1, y2 - y1, '');
      CopyClientToBitmap(TempBMP, x1, y1, x2, y2);
      {FindColorsTolerance(Pts, YewColour, ax - 25, ay - 25, ax + 25, ay + 25, 20);
      if (Length(Pts) = 0) then
      begin
        WriteLn('Something wrong with this colour/range/tolerance Zeph...');
        FreeBitmap(TempBMP);
        Exit;
      end;
      for i := 0 to High(Pts) do
      begin
        TP := Pts[i];
        FastSetPixel(TempBMP, TP.x, TP.y, GetColor(TP.x, TP.y));
      end; }

      Wait(100);
      FindColorsTolerance(CPts, YewColour, x1, y1, x2, y2, 20);
      for i := 0 to High(CPts) do
      begin
        TP := CPts[i];
        if (not(FastGetPixel(TempBMP, TP.x, TP.y) = GetColor(TP.x, TP.y))) then  //Why do I get an access violation error???
          Inc(NoPts);
      end;
      try
        if (NoPts / Length(CPts) * 100 > 50) then TempBool := True; //if 50% of the pixels have changed
      except TempBool := True; end;
      if (TempBool) then
      begin
        WriteDebug('Possible Ent detected...');
        if (not(IsUpText('ew'))) then MMouse(ax, ay, 5, 5);
        Result :=  (IsUpTextYellow('ew')) and (IsEntInClosestSymbol); //if the uptext is yellow or if the yellow NPC dot is in the tree symbol
      end;
      FreeBitmap(TempBMP);
      ColorToleranceSpeed(CTS);
    end;

    The problem is that I keep getting an access violation error on the line with the FastGetColor. I have no idea why. Could someone please help or suggest a better way of doing this.

    I thank you in advance...

    Zeph

  2. #2
    Join Date
    Feb 2006
    Location
    Amsterdam
    Posts
    13,692
    Mentioned
    146 Post(s)
    Quoted
    130 Post(s)

    Default

    First, you need to make 2 bitmaps of the screen instead of one, and compare those.
    THe best way to do this is to check piv's GasCheck.



    The best way to contact me is by email, which you can find on my website: http://wizzup.org
    I also get email notifications of private messages, though.

    Simba (on Twitter | Group on Villavu | Website | Stable/Unstable releases
    Documentation | Source | Simba Bug Tracker on Github and Villavu )


    My (Blog | Website)

  3. #3
    Join Date
    Sep 2006
    Posts
    6,089
    Mentioned
    77 Post(s)
    Quoted
    43 Post(s)

    Default

    You're trying to get a color that is not on the bitmap.

    If you copy the bitmap from, let's say, (100, 100, 200, 200) in the bitmap it'll become (0, 0, 100, 100). So you need to subtract x1 and y1 (how do you spell it?)

    like this:

    SCAR Code:
    TP.x -x1, TP.y -y1) = GetColor(TP.x, TP.y)))
    Hup Holland Hup!

  4. #4
    Join Date
    Apr 2007
    Location
    Perth, Australia
    Posts
    3,926
    Mentioned
    3 Post(s)
    Quoted
    2 Post(s)

    Default

    Ok thanks guys.

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
  •