Results 1 to 16 of 16

Thread: FastFindLadderColor and FindLaddersIn

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

    Default FastFindLadderColor and FindLaddersIn

    Hey,

    I made this for my Lumbridge script. It does practically what it says; it finds the laddercolor on the minimap (and fast ). Works great for me and takes about 15ms.

    SCAR Code:
    function FastFindLadderColor: Integer;
    var
      i, c, n, bmp, Handle, cts:Integer;
      p: TPointArray;
      ca: TIntegerArray;
      pa: TPointArrayArray;
      W, H, S, L: Extended;
    begin
      if (not LoggedIn) then Exit;
      bmp := BitmapFromString(MMX2 - MMX1, MMY2 - MMY1, '');
      CopyClientToBitmap(bmp, MMX1, MMY1, MMX2, MMY2);
      cts := GetColorToleranceSpeed;
      ColorToleranceSpeed(1);
      Handle := GetClientWindowHandle;
      SetTargetBitmap(bmp);
      FindColorsSpiralTolerance(MMCX - MMX1, MMCY - MMY1, p, 79973, 0, 0, MMX2 - MMX1, MMY2 - MMY1, 55);
      pa := SplitTPAEx(p, 2, 2);
      n := Length(pa) -1;
      SortATPAFromSize(pa, 32, True);
      for i := 0 to n do
        if (Length(pa[i]) > 15) and (Length(pa[i]) < 42) then
        begin
          c := FastGetPixel(bmp, pa[i][0].x, pa[i][0].y);
          //WriteLn(IntToStr(c)+'   '+IntToStr(Length(pa[i])));
          ColorToHSL(c, H, S, L);
          if (H < 11.0) and (H > 4.5) then
            if (L < 30.0) and (L > 10.0) then
            begin
              ca := GetColors(pa[i]);
              ClearSameIntegers(ca);
              if (Length(ca) = 1) then
              begin
                p := ReArrangeTPA(pa[i], 0, Length(pa[i]), True, True);
                w := Abs(p[0].x - p[Length(p) -2].x);
                p := ReArrangeTPA(pa[i], 0, Length(pa[i]), False, True);
                h := Abs(p[0].y - p[Length(p) -2].y);
                WriteLn('Color: '+IntToStr(c)+'w: '+FloatToStr(w)+' h: '+ FloatToStr(h));
                WriteLn('ratio: '+FloatToStr(MaxE(w, h) div MinE(w, h)));
                if (MaxE(w, h) div MinE(w, h) >= 1.12) and (MaxE(w, h) div MinE(w, h) <= 1.8) then
                begin
                  Result := c;
                  Break;
                end;
              end;
            end;
        end;
      SetLength(p, 0);
      SetLength(pa, 0);
      SetClientWindowHandle(Handle);
      FreeBitmap(bmp);
      ColorToleranceSpeed(cts);
    end;

    FindLaddersIn also does what it says. It finds all the ladders in an area on the minimap

    SCAR Code:
    function FindLaddersIn(x1, y1, x2, y2: Integer): TPointArray;
    var
      i, n, bmp, Handle, cts, x, y, r:Integer;
      p: TPointArray;
      pa: TPointArrayArray;
      W, H: Extended;
    begin
      if (not LoggedIn) then Exit;
      if (LadderColor = 0) or (not FindColor(x, y, LadderColor, MMX1, MMY1, MMX2, MMY2)) then
        LadderColor := FastFindLadderColor;
      bmp := BitmapFromString(x2 - x1, y2 - y1, '');
      CopyClientToBitmap(bmp, x1, y1, x2, y2);
      cts := GetColorToleranceSpeed;
      ColorToleranceSpeed(1);
      Handle := GetClientWindowHandle;
      SetTargetBitmap(bmp);
      FindColorsSpiralTolerance(((x1 + x2) / 2) - x1, ((y1 + y2) / 2) - y1, p, LadderColor, 0, 0, x2 - x1, y2 - y1, 0);
      pa := SplitTPAEx(p, 2, 2);
      n := Length(pa) -1;
      SortATPAFromSize(pa, 32, True);
      for i := 0 to n do
        if (Length(pa[i]) > 20) and (Length(pa[i]) < 42) then
        begin
          {p := ReArrangeTPA(pa[i], 0, Length(pa[i]), True, True);
          w := Abs(p[0].x - p[Length(p) -2].x);
          p := ReArrangeTPA(pa[i], 0, Length(pa[i]), False, True);
          h := Abs(p[0].y - p[Length(p) -2].y);
          if ((MaxE(w, h) div MinE(w, h)) >= 1.12) and ((MaxE(w, h) div MinE(w, h)) <= 1.8) then
          begin}

            SetLength(Result, r +1);
            Result[r] := MiddleTPA(pa[i]);
            IncEx(Result[r].x, x1);
            IncEx(Result[r].y, y1);
            Inc(r);
          //end;
        end;
      SetLength(p, 0);
      SetLength(pa, 0);
      SetClientWindowHandle(Handle);
      FreeBitmap(bmp);
      ColorToleranceSpeed(cts);
    end;

    Please post bugs/improvements/suggestions

    Nielsie95
    Hup Holland Hup!

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

    Default

    Very nice.



    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
    Oct 2006
    Posts
    2,297
    Mentioned
    1 Post(s)
    Quoted
    0 Post(s)

    Default

    Indeed Wizzup? this is nice.
    Can I ask some questions?
    a.)Am I right that Abs get the abstract value?
    b.)Am I right that once you call SetTargetBitmap that the procedures/fucntions you do are only going to be used in that bitmap?
    c.)What does ReArrangeTPA do?
    d.)Xhat does SetClientWindowHandle do?

    If possible can you explain me??
    My questions can be very stupid, but ple so answer them, I want to learn things and I want to learn them the right way, asking people

    Thanks in advance,

    Stijn.
    [QUOTE=Santa_Clause;277761]I love you too TSN :p[/QUOTE]
    [CENTER][URL="http://www.stats.srl-forums.com/sigs"][IMG]http://www.stats.srl-forums.com/sigs/1324.png[/IMG][/URL][/CENTER]

  4. #4
    Join Date
    Feb 2007
    Location
    Het ademt zwaar en moedeloos vannacht.
    Posts
    7,211
    Mentioned
    26 Post(s)
    Quoted
    72 Post(s)

    Default

    Quote Originally Posted by the scar noob View Post
    Indeed Wizzup? this is nice.
    a.)Am I right that Abs get the abstract value?
    It just converts a negative number in a positive one.
    b.)Am I right that once you call SetTargetBitmap that the procedures/fucntions you do are only going to be used in that bitmap?
    Yes
    d.)Xhat does SetClientWindowHandle do?
    The window handle (Id of a (part) window) gets set (it'll tell scar use the window with that ID)

    Lemme study this a bit first, all that TPA stuff gets confusing after a while.
    edit: this gets the laddercolor by looking at the ratio of a ladder? If so wow, never saw something like that before.
    I made a new script, check it out!.

  5. #5
    Join Date
    Feb 2006
    Location
    Amsterdam
    Posts
    6,136
    Mentioned
    28 Post(s)
    Quoted
    17 Post(s)

    Default

    Very sophisticated. I am glad to see you have outmastered me
    SRL is a Library of routines made by the SRL community written for the Program Simba.
    We produce Scripts for the game Runescape.

  6. #6
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,553
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    i got headache i can dream about i am so good as fawk someday
    ~Hermen

  7. #7
    Join Date
    May 2006
    Location
    Amsterdam
    Posts
    3,620
    Mentioned
    5 Post(s)
    Quoted
    0 Post(s)

    Default

    Well done .
    Verrekte Koekwous

  8. #8
    Join Date
    Feb 2006
    Posts
    920
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

  9. #9
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,553
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by hermpie View Post
    i got headache, i can dream about i am so good as fawk someday
    nielsie i wont forget you
    ~Hermen

  10. #10
    Join Date
    Dec 2006
    Location
    utah
    Posts
    1,427
    Mentioned
    2 Post(s)
    Quoted
    7 Post(s)

    Default

    Quote Originally Posted by the scar noob View Post
    Indeed Wizzup? this is nice.
    Can I ask some questions?
    a.)Am I right that Abs get the abstract value?
    b.)Am I right that once you call SetTargetBitmap that the procedures/fucntions you do are only going to be used in that bitmap?
    c.)What does ReArrangeTPA do?
    d.)Xhat does SetClientWindowHandle do?

    If possible can you explain me??
    My questions can be very stupid, but ple so answer them, I want to learn things and I want to learn them the right way, asking people

    Thanks in advance,

    Stijn.

    1 : Absolute Value

    3 : put the points in order

    4 : sets your client back to rs.
    Co Founder of https://www.tagcandy.com

  11. #11
    Join Date
    Feb 2006
    Location
    Amsterdam
    Posts
    6,136
    Mentioned
    28 Post(s)
    Quoted
    17 Post(s)

    Default

    Quote Originally Posted by WT-Fakawi View Post
    Very sophisticated. I am glad to see you have outmastered me
    Correction: As most of you have done, btw!
    SRL is a Library of routines made by the SRL community written for the Program Simba.
    We produce Scripts for the game Runescape.

  12. #12
    Join Date
    Apr 2007
    Location
    Australia
    Posts
    4,163
    Mentioned
    9 Post(s)
    Quoted
    19 Post(s)

    Default

    wow great stuff

  13. #13
    Join Date
    Nov 2006
    Location
    NSW, Australia
    Posts
    3,487
    Mentioned
    1 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by WT-Fakawi View Post
    Correction: As most of you have done, btw!
    Hah! You obviously underestimate yourself, sir.
    [CENTER][img]http://signatures.mylivesignature.com/54486/113/4539C8FAAF3EAB109A3CC1811EF0941B.png[/img][/CENTER]
    [CENTER][BANANA]TSN ~ Vacation! ~ says :I Love Santy[/BANANA][/CENTER]

    [CENTER][BANANA]Raymond - Oh rilie? says :Your smart[/BANANA][/CENTER]

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

    Default

    Thanks for the nice comments all

    Quote Originally Posted by the scar noob View Post
    Indeed Wizzup? this is nice.
    Can I ask some questions?
    a.)Am I right that Abs get the abstract value?
    b.)Am I right that once you call SetTargetBitmap that the procedures/fucntions you do are only going to be used in that bitmap?
    c.)What does ReArrangeTPA do?
    d.)Xhat does SetClientWindowHandle do?

    If possible can you explain me??
    My questions can be very stupid, but ple so answer them, I want to learn things and I want to learn them the right way, asking people

    Thanks in advance,

    Stijn.

    a.) Yes
    b.) The colorfinding funtions, yes.
    c.) Exactly as it says; it arranges your TPA by x or y, up or down.
    d.) Sets the client back to then window instead of the bitmap.

    Run the script beneath to find out more.

    SCAR Code:
    program new;

    var
      i: Integer;
      p, tp: TPointArray;
    begin
      WriteLn('Abs -10.0 = '+FloatToStr(Abs(-10.0))+', Abs 10.0 = '+ FloatToStr(Abs(10.0)));
      //iAbs for integers..
      WriteLn(' ');
      SetLength(p, 10);
      SetLength(tp, 10);
      for i := 0 to 9 do
      begin
        p[i] := Point(Random(100), Random(100));
        tp[i] := p[i];
      end;
      WriteLn('Arranging the TPA..');
      ReArrangeTPA(tp, 0, High(tp), True, True);
      for i := 0 to 9 do
        WriteLn('before x:'+IntToStr(p[i].x)+' y: '+IntToStr(p[i].y)+'   after x: '+IntToStr(tp[i].x)+' y: '+IntToStr(tp[i].y));
    end.
    Hup Holland Hup!

  15. #15
    Join Date
    Jan 2007
    Location
    USA
    Posts
    1,782
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    very nice. thats all there is to it

    Join the fastest growing merchanting clan on the the net!

  16. #16
    Join Date
    Mar 2007
    Location
    Netherlands->Amersfoort.
    Posts
    1,615
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    looks realy nice. dont understand it atm

    it resurns the color right?. meh,, tryed it in the guild. dind't work..

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
  •