Results 1 to 23 of 23

Thread: General treefinder...

  1. #1
    Join Date
    Jul 2007
    Posts
    1,431
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default General treefinder...

    Here it is, big thanks to Nielsie for explaining wizzyplugin functions and Markus for testing

    SCAR Code:
    function FindTree(var x, y: Integer; Treetype : String): Boolean;
    var
      TPA : TpointArray;
      ATPA : Array of TPointArray;
      MSCPoint : Tpoint;
      i, CTS, Color : integer;
      Uptext : String;
    begin
      x := mscx;
      y := mscy;
      MSCPoint.x := mscy;
      MSCPoint.y := mscy;
      Color := 2966339;
      Case lowercase(TreeType) of
        'tree', 'usual' : Uptext := 'Tree';
        'oak'  : UpText := 'Oak';
        'willow' : UpText := 'illo';
        'yew' : UpText := 'Yew';
      end;
      CTS := GetColorToleRanceSpeed;
      ColorToleranceSpeed(2);
      SetColorspeed2Modifiers(0.2, 0.2);
      FindColorsSpiralTolerance(x, y, TPA, Color, msx1, msy1, msx2, msy2, 10)
      ColorToleranceSpeed(CTS);
      if Length(TPA) > 4 then
      begin
        ATPA := SplitTPA(TPA, 15);
        SortATPAFrom(ATPA, MSCPoint);
        for i := 0 to High(ATPA) do
        begin
          MiddleTPAEx(ATPA[i], x, y);
          MMouse(x, y, 3, 3);
          Wait(100 + random(100));
          if IsUpText(UpText) then
          begin
            Result := True;
            Getmousepos(x, y);
            Exit;
          end;
        end;
      end;
    end;

    Edit:
    This one should be lot better xD
    SCAR Code:
    function FindTree(var a, b: Integer; Treetype : String): Boolean;
    var
      TPA : TpointArray;
      ATPA : Array of TPointArray;
      i, C, CTS, Color : integer;
      Uptext : String;
      Colors : Array of integer;
      SortedTPA : TPointArray;
      x, y, z, h, s, l,
      maxx, minx, maxy, miny, maxz, minz,
      maxh, minh, maxs, mins, maxl, minl : extended;
    begin
      Color  := 2446923;
      Minx   := 1;
      Maxx   := 22;
      Miny   := 0;
      Maxy   := 11;
      Minz   := 1;
      Maxz   := 28;
      Minh   := 17;
      Maxh   := 22;
      Mins   := 23;
      Maxs   := 62;
      Minl   := 7;
      Maxl   := 45;
      Case lowercase(TreeType) of
        'tree'   : Uptext := 'ree';
        'oak'    : UpText := 'ak';
        'willow' : UpText := 'llo';
        'yew'    : UpText := 'ew';
        'all'    : UpText := 'hop d';
      end;
      CTS := GetColorToleRanceSpeed;
      ColorToleranceSpeed(2);
      SetColorspeed2Modifiers(0.15, 0.5);
      FindColorsSpiralTolerance(mscx, mscy, TPA, Color, msx1, msy1, msx2, msy2, 9)
      ColorToleranceSpeed(CTS);
      SetColorspeed2Modifiers(0.2, 0.2);
      Colors := GetColors(TPA);
      for C := 0 to High(TPA) do
      begin
        colortoxyz(colors[i], x, y, z);
        if (x > minx) then
          if (x < maxx) then
            if (y > miny) then
              if (y < maxy) then
                if (z > minz) then
                  if (z < maxz) then
        begin
          colortohsl(colors[i], h, s, l);
          if (h > minh) then
            if (h < maxh) then
              if (s > mins) then
                if (s < maxs) then
                  if (l > minl) then
                    if (l < maxl) then
          begin
            Setlength(SortedTPA, length(SortedTPA) + 1);
            SortedTPA[high(SortedTPA)] := TPA[C];
          end;
        end;
      end;
      if Length(SortedTPA) >= 50 then
      begin
        ATPA := SplitTPAEx(SortedTPA, 20, 15);
        SortATPAFrom(ATPA, IntToPoint(MSCX, MSCY));
        for i := 0 to High(ATPA) do
        if Length(ATPA[i]) >= 50 then
        begin
          MiddleTPAEx(ATPA[i], a, b);
          MMouse(a-10, b-10, 21, 21);
          Wait(50 + random(50));
          if IsUpText(UpText) then
          begin
            Result := True;
            Getmousepos(a, b);
            Exit;
          end;
        end;
      end;
    end;

    Edit: I made min, max, etc to vars because I had lot of messing with them...Hard to understand...remove em and put in HSL and XYZ if you want...


    Did like Wizzup? said and now takes only ~250 ms and hard to notice tiny lag
    SCAR Code:
    function FindTree(var a, b: Integer; Treetype : String): Boolean;
    var
      TPA : TpointArray;
      ATPA : Array of TPointArray;
      i, C, CTS, Count : integer;
      Uptext : String;
      Colors : Array of integer;
      SortedTPA : TPointArray;
      x, y, z, h, s, l : extended;
    begin
      Case lowercase(TreeType) of
        'tree'   : Uptext := 'ree';
        'oak'    : UpText := 'ak';
        'willow' : UpText := 'llo';
        'yew'    : UpText := 'ew';
        'all'    : UpText := 'hop d';
      end;
      CTS := GetColorToleRanceSpeed;
      ColorToleranceSpeed(2);
      SetColorspeed2Modifiers(0.15, 0.5);
      FindColorsSpiralTolerance(mscx, mscy, TPA, 2446923, msx1, msy1, msx2, msy2, 9);
      ColorToleranceSpeed(CTS);
      SetColorspeed2Modifiers(0.2, 0.2);
      TPA:=ReArrangeandShortenArrayEx(TPA, 5, 5);
      Colors := GetColors(TPA);
      SetLength(SortedTPA, Length(TPA));
      Count := 0;
      for C := 0 to High(TPA) do
      begin
        colortoxyz(colors[i], x, y, z);
        if(x > 1)and(x < 22)and(y > 0)and(y < 11)and(z > 1)and(z < 28)then
        begin
          colortohsl(colors[i], h, s, l);
          if (h > 17)and(h < 22)and(s > 23)and(s < 62)and(l > 7)and(l < 45) then
          begin
            SortedTPA[Count] := TPA[C];
            Count := Count + 1;
          end;
        end;
      end;
      SetLength(SortedTPA, Count);
      SortedTPA := TPA;
      begin
        ATPA := SplitTPAEx(SortedTPA, 20, 15);
        SortATPAFrom(ATPA, IntToPoint(MSCX, MSCY));
        for i := 0 to High(ATPA) do
        if Length(ATPA[i]) >= 50 then
        begin
          MiddleTPAEx(ATPA[i], a, b);
          MMouse(a-10, b-10, 21, 21);
          Wait(50 + random(50));
          if IsUpText(UpText) then
          begin
            Result := True;
            Getmousepos(a, b);
            Exit;
          end;
        end;
      end;
    end;

    Usage example
    SCAR Code:
    Findtree(x, y, 'yew');


    You can choose between tree, oak, willow and yew and all.
    [CENTER][SIZE="4"]Inactive[/SIZE]I forgot my password[/CENTER]

  2. #2
    Join Date
    Dec 2006
    Location
    Copy pastin to my C#
    Posts
    3,788
    Mentioned
    8 Post(s)
    Quoted
    29 Post(s)

    Default

    Want to hear the sad news?

    SetColorspeed2Modifiers(0.2, 0.2);
    Those, my friend, are the default Hue and Saturation modifiers

    Also, try to avoid using capitalized letters with the UpChars font.

    If you wanna save a var and two lines -

    SortATPAFrom(ATPA, IntToPoint(MSCX, MSCY));


    Also, if you use 15 in SplitTPA, use TPAToATPA instead, 20 should do there, then, in the for loop do like

    "If GetArrayLength(TPAA[i]) >= 60 Then"

    and then the MiddleTPA crap.

    Gj though.

  3. #3
    Join Date
    Jul 2007
    Posts
    1,431
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by n3ss3s View Post
    Want to hear the sad news?



    Those, my friend, are the default Hue and Saturation modifiers

    Also, try to avoid using capitalized letters with the UpChars font.

    If you wanna save a var and two lines -

    SortATPAFrom(ATPA, IntToPoint(MSCX, MSCY));


    Also, if you use 15 in SplitTPA, use TPAToATPA instead, 20 should do there, then, in the for loop do like

    "If GetArrayLength(TPAA[i]) >= 60 Then"

    and then the MiddleTPA crap.

    Gj though.
    I just wanted to be 1337 with using ColorTolerancespeedmodifiers...ok...didn't made out well

    Thanks for IntToPoint, didn't knew that...

    But why should I use TPATpATPA?

    Edit: Nvm, now I got it why TPAToATPA
    [CENTER][SIZE="4"]Inactive[/SIZE]I forgot my password[/CENTER]

  4. #4
    Join Date
    Dec 2006
    Location
    Banville
    Posts
    3,914
    Mentioned
    12 Post(s)
    Quoted
    98 Post(s)

    Default

    Aww... Its noob friendly! Why doesn't it have confusing params like RadialWalk?
    The jealous temper of mankind, ever more disposed to censure than
    to praise the work of others, has constantly made the pursuit of new
    methods and systems no less perilous than the search after unknown
    lands and seas.

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

    Default

    Quote Originally Posted by n3ss3s View Post
    Also, if you use 15 in SplitTPA, use TPAToATPA instead, 20 should do there, then, in the for loop do like
    Why? I think SplitTPA is better in this case, the distance is a bit big though. 5 would've done it.
    Also the distance version of TPAtoATPA and SplitTPA are a lot slower than the Ex versions. So when you use a large tpa (the green color of the trees), it's better to use SplitTPAEx
    Hup Holland Hup!

  6. #6
    Join Date
    Jul 2007
    Posts
    1,431
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by nielsie95 View Post
    Why? I think SplitTPA is better in this case, the distance is a bit big though. 5 would've done it.
    Also the distance version of TPAtoATPA and SplitTPA are a lot slower than the Ex versions. So when you use a large tpa (the green color of the trees), it's better to use SplitTPAEx
    Thanks teacher, I'll try adding some HSL or XYZ thingy today...now I know why you said I should use SplitTpaEx not SplitTpa

    Edit: How could I draw it on canvas and see matching pixels( in red), So I can see how many point it found, and where...
    [CENTER][SIZE="4"]Inactive[/SIZE]I forgot my password[/CENTER]

  7. #7
    Join Date
    Dec 2006
    Location
    Copy pastin to my C#
    Posts
    3,788
    Mentioned
    8 Post(s)
    Quoted
    29 Post(s)

    Default

    Search for DebugTPA


    Hmm, maybe use Hue and Sat mods 0.4, and 15 Tol in the ColorsSpiralTolerance so when you do either SplitTPA(ex) or TPAToATPA(ex) you have more points in your "subTPAs".

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

    Default

    Quote Originally Posted by n3ss3s View Post
    Search for DebugTPA


    Hmm, maybe use Hue and Sat mods 0.4, and 15 Tol in the ColorsSpiralTolerance so when you do either SplitTPA(ex) or TPAToATPA(ex) you have more points in your "subTPAs".
    http://www.villavu.com/forum/showthr...light=debugtpa



    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)

  9. #9
    Join Date
    Jul 2007
    Location
    Right now? Chair.
    Posts
    8,488
    Mentioned
    3 Post(s)
    Quoted
    12 Post(s)

    Default

    wow that confused the hell outta me, especially the posts, will this really find any tree? and are there any tuts on this?

    * goes search*

    ~RM

    I & I know Zion. It is in the spirit, body and mind of every one of us
    RMouse(obj: TMSIObject): boolean;

  10. #10
    Join Date
    Jul 2007
    Posts
    1,431
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by Rasta Magician View Post
    wow that confused the hell outta me,
    ~RM
    I got like 3x more confusing version ready...I just have to pick colors...
    [CENTER][SIZE="4"]Inactive[/SIZE]I forgot my password[/CENTER]

  11. #11
    Join Date
    Dec 2006
    Location
    Copy pastin to my C#
    Posts
    3,788
    Mentioned
    8 Post(s)
    Quoted
    29 Post(s)

    Default

    wow that confused the hell outta me, especially the posts, will this really find any tree? and are there any tuts on this?

    * goes search*

    ~RM
    Go to tuts for advanced, my TPA tut is stickied... Should get you understand the basics.

  12. #12
    Join Date
    Jul 2007
    Posts
    1,055
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    When I used it inplace of FindObjCustom in my script it was terrible, then I changed your default color to 3830377 (my reg color), and it worked prety well. I think I gotta read up on Tpoint junk before I can really mess with this. But I'll probably use it in my next version.

  13. #13
    Join Date
    Dec 2006
    Location
    Copy pastin to my C#
    Posts
    3,788
    Mentioned
    8 Post(s)
    Quoted
    29 Post(s)

    Default

    --- more shit coming ---

    Negaal, instead of exit, use break, so in the end of the procedure you can do:

    ColorToleranceSpeed(CTS) to return it to the original
    SetColorSpeed2Modifiers(0.2, 0.2) to return them to the default.

  14. #14
    Join Date
    Jul 2007
    Posts
    1,431
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by n3ss3s View Post
    --- more shit coming ---

    Negaal, instead of exit, use break, so in the end of the procedure you can do:

    ColorToleranceSpeed(CTS) to return it to the original
    SetColorSpeed2Modifiers(0.2, 0.2) to return them to the default.
    Why break? No difference...

    And if it doesnt find enough pixels it will never reach there...and CTS and CTS2Speedmodifiers will stay what I setted them to...

    Let them be

    And leave me alone

    Edit: Look my first post, I updated it a bit

    Edit: I wouldn't done it without nielsie He taught me everything about HSL's and XYZ'
    [CENTER][SIZE="4"]Inactive[/SIZE]I forgot my password[/CENTER]

  15. #15
    Join Date
    Jul 2007
    Posts
    1,055
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    It is a lot nicer but now it comes with a half second lag =/.

  16. #16
    Join Date
    Jul 2007
    Posts
    1,431
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by osmm View Post
    It is a lot nicer but now it comes with a half second lag =/.
    :S , yeah, it's because it looks every color trough HSL and XYZ,

    And it's not half sec, like 0,1 sec
    [CENTER][SIZE="4"]Inactive[/SIZE]I forgot my password[/CENTER]

  17. #17
    Join Date
    Nov 2006
    Posts
    1,103
    Mentioned
    0 Post(s)
    Quoted
    6 Post(s)

    Default

    try rearrangeandshortenarray, should speed up things a lot especially since trees are rather big.
    Infractions, reputation, reflection, the dark side of scripting, they are.

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

    Default

    Quote Originally Posted by Negaal View Post
    Why break? No difference...

    And if it doesnt find enough pixels it will never reach there...and CTS and CTS2Speedmodifiers will stay what I setted them to...
    You should change them back to the default.

  19. #19
    Join Date
    Jul 2007
    Posts
    1,431
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by ZephyrsFury View Post
    You should change them back to the default.
    ?

    SCAR Code:
    ColorToleranceSpeed(2);
      SetColorspeed2Modifiers(0.15, 0.5);
      FindColorsSpiralTolerance(mscx, mscy, TPA, Color, msx1, msy1, msx2, msy2, 9)
      ColorToleranceSpeed(CTS);
      SetColorspeed2Modifiers(0.2, 0.2);

    It does...

    try rearrangeandshortenarray, should speed up things a lot especially since trees are rather big.
    Thx for the tip...

    Peace?
    [CENTER][SIZE="4"]Inactive[/SIZE]I forgot my password[/CENTER]

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

    Default

    Quote Originally Posted by Negaal View Post
    :S , yeah, it's because it looks every color trough HSL and XYZ,

    And it's not half sec, like 0,1 sec
    A word of advice to speed it up.

    Don't use variables for minx, maxx etc. Either just use numbers, or constants (you can make constants that stay within a funtion). Using ordinairy numbers or constants is much faster, if you use a variable, scar has to check the memory each time you want to access the variable's value. A constant is replaced with it's intended number when the script is being compiled. Speedness++.

    If you intent to use different color spaces, always start off with rgb.
    I think XYZ is faster than HSL, so after RGB use the XYZ check.
    Like this:
    SCAR Code:
    rgbtocolor()
    if r check and b check and g check then
    begin
      xyztocolor()
      if x check and y check and g check then
      begin
        hsltocolor()
        if h check if s check if l check
      end;
    end;

    Also, maybe you do not have to use all the value's? (just use X and Y instead of X Y and Z, just find out whatever ones really determine the color)


    About the arrays.
    Set it to the max value it can take, before you enter the loop.
    SCAR Code:
    SetLength(SortedPoints, Length(TPA));
    Right?

    Then, add another variable (not C). Set it to zero before you enter the loop. I'll call it 'counter'.
    SCAR Code:
    SetLength(SortedPoints, Length(TPA));
    counter := 0;

    Now, you go through the loop.

    Instead of this:

    SCAR Code:
    Setlength(SortedTPA, length(SortedTPA) + 1);
            SortedTPA[high(SortedTPA)] := TPA[C];

    You simply add to the array with index counter, and then do Counter++.
    So:
    SCAR Code:
    SortedTPA[counter] := TPA[C];
    Counter := Counter + 1;

    After the loop, you Set the array (SortedTPA)'s length to Counter.

    SCAR Code:
    SetLength(SortedTPA, C);

    That should definately help.
    Calling SetLength every time required the entire array to be copied to a different point in the memory, and have 1 value added. (Am I right Ben/Ray/Nielsie/Freddy?)
    If you intent to add alot of points to an array, just set it to it's maximum length first. When you finish it, set it to it's 'counter' length.

    Also, I don't think you need this check:
    SCAR Code:
    if Length(SortedTPA) >= 50 then

    Because you also check the ATPA length, and Doing TPAToATPA with a tpointarray which length < 50 is less than 16ms.

    Great, now I just have to add all these speedups to my own VEM procedures.



    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)

  21. #21
    Join Date
    Jul 2007
    Posts
    1,431
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Thx for tips, I can fix it after few hours, atm I'm in computer lesson...

    Woah, I had to read it like 3 or 4 times before I understood it...

    Edit: Did like wizzy said and Killerdou's ReArrangeandshortenArray helped a lot!

    Now it's pretty fast

    Try it

    Edit: It's on front page

    Edit:

    [CENTER][SIZE="4"]Inactive[/SIZE]I forgot my password[/CENTER]

  22. #22
    Join Date
    Jul 2007
    Posts
    1,431
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Sorry for doublepost but I wanted to get it bumped, and some criticism...

    Anyone? What you think about "Wizzup's" fixed version?
    [CENTER][SIZE="4"]Inactive[/SIZE]I forgot my password[/CENTER]

  23. #23
    Join Date
    Jan 2008
    Location
    UK
    Posts
    500
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Looks very good.. I'm going to try in in my script.. will let you know how it goes..

    Edit
    Would be usefull to have a level check in there so that all only detects trees that a user is capable of chopping.
    Obviously needs to support all tree's..
    All in all appears to be very good.. It's also boosted my understanding of the whole TPAToATPAEx thing..
    I'll have a play and get back to you..
    For the Ultimate Monk Fisher: Ultra Monkfish n Bank Click Here


Thread Information

Users Browsing this Thread

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

Similar Threads

  1. general scripting help
    By ben600006 in forum OSR Help
    Replies: 3
    Last Post: 02-02-2009, 12:02 PM
  2. General FailSafes
    By Pyro in forum Outdated Tutorials
    Replies: 24
    Last Post: 07-05-2007, 01:48 AM

Posting Permissions

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