Results 1 to 20 of 20

Thread: Finding if the tree is cut down issue..

  1. #1
    Join Date
    Apr 2008
    Location
    Marquette, MI
    Posts
    15,252
    Mentioned
    138 Post(s)
    Quoted
    680 Post(s)

    Default Finding if the tree is cut down issue..

    I can't seem to figure out why it doesn't find when when tree is cut down. It logs in, clicks on the tree, but when it's cut down, it does nothing.

    What I'm trying to do is:

    Get it to make a 40 x 40 box around the point on the tree it clicks, and check how many colours are in that box. If the number of colors changes, the tree has been cut down.

    Here's the script:

    SCAR Code:
    { - need new way of detecting when trees are cut down
      - need new way of detecting which tree the mouse is over}


    program PowerChopper;
      //.Include SRL\SRL\Misc\SMART.SCAR}
      {.include SRL\SRL.scar}

    var
      HatchetDTM : Array of Integer;
      i, x, y, NumOfLogs, TotalProggies, CP : integer;
      TreeColor : TIntegerArray;
     
    procedure DeclarePlayers;
    begin
      HowManyPlayers := 1;
      NumberOfPlayers(HowManyPlayers);
      CurrentPlayer := 0;

      Players[0].Name := '';
      Players[0].Pass := '';
      Players[0].Nick := '';
      Players[0].Active := True;
      Players[0].Pin := '';
      Players[0].Strings[0] := 'willow';//Which tree to cut?
      Players[0].Integers[0] := 270;//How many logs to cut?
      Players[0].BoxRewards := ['Xp', 'mote', 'ostume'];
    end;

    procedure FindRandoms;
    begin
      LampSkill := 'woodcutting';
      FindNormalRandoms;
    end;

    procedure MyAntiBan;
    begin
      case Random(70) of
        0: RandomMovement;
        1: BoredHuman;
        2: HoverSkill('random', false);
        3: RandomRClick;
        4: begin
             case Random(2) of
               0: begin
                    KeyDown(VK_RIGHT);
                    Wait(50 + Random(1300));
                    KeyUp(VK_RIGHT);
                    Wait(60 + Random(2000));
                    KeyDown(VK_LEFT);
                    Wait(70 + Random(1100));
                    KeyUp(VK_LEFT);
                  end;
               1: begin
                    KeyDown(VK_LEFT);
                    Wait(50 + Random(1300));
                    KeyUp(VK_LEFT);
                    Wait(60 + Random(2000));
                    KeyDown(VK_RIGHT);
                    Wait(70 + Random(1100));
                    KeyUp(VK_RIGHT);
                  end;
              end;
           end;
        5: begin
             KeyDown(VK_LEFT);
             Wait(100 + Random(1200));
             KeyUp(VK_LEFT);
           end;
        6: begin
             KeyDown(VK_RIGHT);
             Wait(150 + Random(1100));
             KeyUp(VK_RIGHT);
           end;
        7..69:
      end;
    end;


    procedure HatchetDTMs;
    begin
     SetArrayLength(HatchetDTM, 7);//[0]:= Bronze, [6]:= Rune
       HatchetDTM[0] := DTMFromString('78DA630C646260D8C4C8800C7CAC9519F8813' +
           '44C94D113A86617AA1A982C5C8D1B50CD36026ABC816AD6125013' +
           '0C54B38E809A504C3763A80921EC1E00949107EF');
       HatchetDTM[1] := DTMFromString('78DA630C626260D8C4C8800C02BDBD19F8813' +
           '448F43F1030BA03D5EC47550391859140DA0DA8662B01355E4035' +
           '6B09A80906AA5947404D2850CD06026A42806AB6E157030033F30' +
           'C28');
       HatchetDTM[2] := DTMFromString('78DA630C626260D8C8C8800CCAF3F318F8813' +
           '448F43F10307A02D5EC40550391859140DA0DA8660B01355E4035' +
           '6B09A80904AA5947404D28A69BB1AAD98A5F0D0090050C8D');
       HatchetDTM[3] := DTMFromString('78DA63F4676260D8C0C8800C44454418F8813' +
           '448F43F1030BA03D5EC43550391859140DA05A8661701351E4035' +
           'EB09A80900AA5947404D28A69BB1AAD98A5F0D0095870B78');
       HatchetDTM[4] := DTMFromString('78DA630C646260D8C8C8800C1C1CE319F8813' +
           '44C94D10DA8E600AA1A982C5C8D2B50CD0E026A3C806A36105013' +
           '0054B38E809A504C3763A80901AAD9865F0D00C5940824');
       HatchetDTM[5] := DTMFromString('78DA63EC64626038C0C8800C9C829D18F8813' +
           '44C94B101A8E614AA1A982C8A9A7D04D4F402D5EC2742CD21026A' +
           '6A816AAEE05703006FA208C7');
       HatchetDTM[6] := DTMFromString('78DA630C606260D8C8C8800C5CA2531944803' +
           '44C94D11DA8662FAA1A982C5C8D1B50CD56026ABC806AD6125013' +
           '0C54B38E809A504C3763A80901AAD9865F0D00E749084A');
    end;

    procedure Cut_FindHatchet;
    var
      b: Boolean;
    begin
      for i:= 0 to 6 do
        if(FindDTM(HatchetDTM[i], x, y, MIX1, MIY1, MIX2, MIY2))then
          begin
            b:= True;// assign b:= True, now you know it's found.
            Break;// break the loop - once found, no need to keep going through.
          end;
          begin
            if(b = True)then// since it's only a check, = is needed, rather than :=
              Writeln('Found hatchet.')
            else
            begin
              Writeln('Didn''t find hatchet, logging out.');
              LogOut;
            end;
          end;
    end;

    procedure Cut_TreeColors;
    begin
      SetArrayLength(TreeColor, 4);
        TreeColor := [6266770, 1199164, 8497045, 1718835];
      case LowerCase(Players[CP].Strings[0]) of
        'normal': i := 0;
        'oak': i := 1;
        'willow': i := 2;
        'yew': i := 3;
      else
        begin
          Writeln('No tree specified, logging out.');
          Logout;
          Exit;
        end;
      end;
    end;

    function Cut_TreeCutDown: Boolean;
    var
      TrCols : TPointArray;
      Box : TBox;
    begin
      i := Length(TrCols);
      repeat
        Box := IntToBox(x - 20, y - 20, x + 20, y + 20);
        FindColorsTolerance(TrCols, TreeColor[i], Box.x1, Box.y1, Box.x2, Box.y2, 3);
        if(Length(TrCols) <> i)then
        begin
          Writeln('Tree has been cut down.');
          Exit;
        end;
      until(InvFull or not(LoggedIn));
      Result := True;
    end;

    function Cut_CutTrees: Boolean;
    var
      fx, fy, i : integer;
      TPA : Array of TPoint;
      T2D : T2DPointArray;
    begin
      repeat
        FindColorsSpiralTolerance(fx, fy, TPA, TreeColor[i], MSX1, MSY1, MSX2, MSY2, 5);
        T2D := SplitTPAEx(TPA, 3, 4);
        if Length(T2D) = 0 then exit;

        for i := 0 to High(T2D) do
        begin
          if MiddleTPAEx(T2D[i], fx, fy) then
          begin
            Wait(30 + Random(20));
            MMouse(fx, fy, 4, 4);
          end;
          if(IsUpText('hop'))then
          begin
            GetMousePos(x, y);
            Wait(50 + Random(300));
            Mouse(x, y, 4, 4, True);
            repeat
              Cut_TreeCutDown;
              Wait(80 + Random(100));
              MyAntiBan;
            until(Cut_TreeCutDown = True);
            Result := True;
          end;
        end;
      until(InvFull or not(LoggedIn));
    end;

    procedure Cut_DropLogs;
    begin
      if(InvFull)then
      begin
        Wait(500 + Random(100));
        for i := 2 to 28 do
          DropItem(i);
        NumOfLogs := NumOfLogs + 27;
        if(NumOfLogs >= Players[0].Integers[0])then
        begin
          Writeln('Cut desired number of logs, logging out.');
          Wait(50 + Random(1000));
          Logout;
        end;
      end;
      FindRandoms;
    end;

    procedure ProgReport;
    begin
      Inc(TotalProggies);
      Writeln(' _______________________________________________');
      Writeln(PadR('|            Coh3n''s Power Chopper', 48) + '|');
      Writeln('|_________________First Script__________________|');
      Writeln('|                                               |');
      Writeln(PadR('|  Time run: ' + TimeRunning, 48) + '|');
      Writeln(PadR('|  Loads: ' + IntToStr(NumOfLogs / 27), 48) + '|');
      Writeln(PadR('|  Logs: ' + IntToStr(NumOfLogs), 48) + '|');
      Writeln('|_______________________________________________|');
    end;


    begin
      //SMARTSetupEx(152, False, True, False);
      //Wait(5000);
      //SetTargetDC(SmartGetDC);
      SetupSRL;
      ActivateClient;
      DeclarePlayers;
      LoginPlayer;
      SetAngle(True);
      HatchetDTMs;
      Cut_FindHatchet;
      repeat
        if(ExistsItem(1))then
          Cut_TreeColors;
          Cut_CutTrees;
          Cut_TreeCutDown;
          Cut_DropLogs;
          ProgReport;
          FindRandoms;
      until(not LoggedIn);
    end.
    Last edited by Coh3n; 06-03-2009 at 01:18 AM.

  2. #2
    Join Date
    Aug 2007
    Location
    in a random little world
    Posts
    5,778
    Mentioned
    0 Post(s)
    Quoted
    7 Post(s)

  3. #3
    Join Date
    Mar 2007
    Posts
    4,810
    Mentioned
    3 Post(s)
    Quoted
    3 Post(s)

    Default

    Your not doing it properly,

    You never define the variable Box, and you call it before your color finding procedure, what its doing at the moment it find something a a virtually 0 area box .

    So before you do the find colors put:

    SCAR Code:
    Box := IntToBox(x -20, y - 20, x + 20, y + 20);


  4. #4
    Join Date
    Feb 2007
    Posts
    3,616
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    I had a function called chopping that would return true if the person was still swinging their axe. Once they are not swinging their axe, you know the tree is gone.

    Or you could do what shuttle said.

  5. #5
    Join Date
    Apr 2008
    Location
    Marquette, MI
    Posts
    15,252
    Mentioned
    138 Post(s)
    Quoted
    680 Post(s)

    Default

    Quote Originally Posted by Shuttleu View Post
    yea but the colours could change which will make this inaccurate
    the way i do it is to hover over the tree and wait until the UpText has gone

    ~shut
    That's what I originally had, although when it took the mouse off the tree when doing anti-ban, or walking to the tree, it would either click on the tree again, or click on a different tree. I is especially a problem when cutting normal trees as you're always walking to them. I recall watching it once when I was chopping willows and it literally started walking back and forth between trees, not actually doing anything.

    Quote Originally Posted by NaumanAkhlaQ View Post
    Your not doing it properly,

    You never define the variable Box, and you call it before your color finding procedure, what its doing at the moment it find something a a virtually 0 area box .

    So before you do the find colors put:

    SCAR Code:
    Box := IntToBox(x -20, y - 20, x + 20, y + 20);

    I knew I had to use IntToBox somewhere, Thanks

    Quote Originally Posted by JAD View Post
    I had a function called chopping that would return true if the person was still swinging their axe. Once they are not swinging their axe, you know the tree is gone.

    Or you could do what shuttle said.
    I also thought of that, but didn't really know where to start, that's where Nava2 gave me the idea that I'm working on now.

  6. #6
    Join Date
    Aug 2007
    Location
    in a random little world
    Posts
    5,778
    Mentioned
    0 Post(s)
    Quoted
    7 Post(s)

  7. #7
    Join Date
    Apr 2008
    Location
    Marquette, MI
    Posts
    15,252
    Mentioned
    138 Post(s)
    Quoted
    680 Post(s)

    Default

    Quote Originally Posted by NaumanAkhlaQ View Post
    Your not doing it properly,

    You never define the variable Box, and you call it before your color finding procedure, what its doing at the moment it find something a a virtually 0 area box .
    I fixed that, but the same thing still happens.

    Quote Originally Posted by Shuttleu View Post
    so you wait for something like 2-3 seconds then move the compass to the direction of the tree to make sure the tree is north them move the mouse to that bit on the screen
    have a look at UCB if you dont know what i mean

    ~shut
    I looked at it, and I still don't know what you mean.

  8. #8
    Join Date
    Feb 2007
    Posts
    3,616
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Was just looking for my Chopping function in my old Varrock Lumberjack. It's almost 2 years old now, but it worked then

    SCAR Code:
    function Chopping: Boolean;

    var
      TPA: TPointArray;
      I: Integer;
     
    begin
      for I := 1 to 7 do
      begin
        FindColorsSpiralTolerance(x,y,TPA,939120,204,132,282,202,10);
        Result := GetArrayLength(TPA) - 1 > 6;
        if(Result)then
          Exit;
        wait(30+random(40));
      end;
    end;

    All it did was search for all the colors of the axe handle (939120 probably has to be updated as the axe handle color) with tolerance 10, in the area where characters body is located, and if it found more than 6 matching colors, the axe was out. Simple, but I never had any problems with it not working back then. It searches 7 times and waits to make sure that the axe is in a viewable spot and not behind the character. With the semi-new updated animation for axe chopping it may not even be necessary idk.

  9. #9
    Join Date
    Feb 2009
    Location
    Hungary (GMT + 1)
    Posts
    1,774
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Nadeems detect motion function may help you too. If you are looking for a spot where the axe moves.
    http://www.villavu.com/forum/showthread.php?t=45209

  10. #10
    Join Date
    Feb 2007
    Location
    Access Violation at 0x00000000
    Posts
    2,865
    Mentioned
    3 Post(s)
    Quoted
    18 Post(s)

    Default

    :O
    I use the exact same method in my (never released it, made it like a month ago) willow/maple chop+bank script RazorSharp
    Ce ne sont que des gueux


  11. #11
    Join Date
    Apr 2008
    Location
    Marquette, MI
    Posts
    15,252
    Mentioned
    138 Post(s)
    Quoted
    680 Post(s)

    Default

    Quote Originally Posted by JAD View Post
    Was just looking for my Chopping function in my old Varrock Lumberjack. It's almost 2 years old now, but it worked then
    Wow, it's nice and short too. I'll have to try it out, cause my way seems to be a big pain in the ass.

    Quote Originally Posted by Sabzi View Post
    Nadeems detect motion function may help you too. If you are looking for a spot where the axe moves.
    http://www.villavu.com/forum/showthread.php?t=45209
    Thanks, I'll check it out.

    Quote Originally Posted by Floor66 View Post
    :O
    I use the exact same method in my (never released it, made it like a month ago) willow/maple chop+bank script RazorSharp
    Oh really? Interesting... so would you be able to tell me what my problem is?

  12. #12
    Join Date
    Dec 2006
    Location
    Canada, BC
    Posts
    728
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    no offence shut, but i think that way is kinda bannable :P

    ill show you what i did in my yew chopper:

    SCAR Code:
    procedure ResetTreeVariables; // Reseting the Tpoint to a place where the color will never be found.
    begin
      TreePoint := IntToPoint(0, 0); //Position(0, 0); Outside of the RS window, where the page is Black.
      TreeColor := 16777215; // White
    end;
    //
    function TreeCutDown : Boolean; // Surches for the same Color, with alittle tolerance, within a 20x20 pixle box. The shifting of the screen should not have moved the point so far that it would not be found
    var
      TPA : TPointArray;
    begin
      FindColorsTolerance(TPA, TreeColor, TreePoint.x - 20, TreePoint.y - 20, TreePoint.x + 20, TreePoint.y + 20, 3);
      Writeln('Tree Found, High(TPA) = ' + IntToStr(High(TPA)));
      if High(TPA) >= 0 then
      begin
        Result := False;
      end;
      if High(TPA) <= 0 then
      begin
        Writeln('Tree Has Been Cut Down.');
        Result := True;
      end;
    end;
    //
    function CutTree : boolean;
    begin
    //bla bla bla all the TPA's / w/e you do to find the tree..
      MMouse(x, y, 2, 2);
      if IsUpText('ree') then
      begin
        GetMousePos(x ,y);
        Mouse(x, y, 0, 0, true);
        TreePoint := IntToPoint(x, y);
        TreeColor := GetColor(x, y);
      end;

    Now after you would do any clicking that would move your position on the map, you would want to use the ResetTreeVariables, so that if you move to another tree, and it just happens that the TreePoint is over it, it will say that your still choping down the same tree even though your realy on a new one, and it will just sit there waiting for the new tree to be choped down. i just kinda copied/pasted most of this from my script so it might not compile :P but this is just to give you another idea of how to check if the trees still up. hope i helped :]

    Edit: im gonna explain what i did in words alittle more, cause i think i sound confuseing.
    so you record the TPoint and Color of that point where you click on the tree, then you surch for a TPA in a box 20 pixles around the point where you clicked. (the map shifts slightly so you will never keep the same color at one point longer than a few seconds.) Ok, then you take that TPA and do High(TPA); if the TPA is big enough (meaning there were enough of the same colored points within that 20x20 box then it will return False, meaning the tree is not yet cut down.
    Last edited by Lance; 06-03-2009 at 03:29 AM.
    Lance. Da. Pants.

  13. #13
    Join Date
    Jan 2008
    Location
    Ontario, Canada
    Posts
    7,805
    Mentioned
    5 Post(s)
    Quoted
    3 Post(s)

    Default

    Your use of the variable i throughout your script will mess up your tree colours. Eventually getting an out of range. You need to use local vars where possible, or use something more.. obvious for your TreeColor Index var.
    Writing an SRL Member Application | [Updated] Pascal Scripting Statements
    My GitHub

    Progress Report:
    13:46 <@BenLand100> <SourceCode> @BenLand100: what you have just said shows you 
                        have serious physchological problems
    13:46 <@BenLand100> HE GETS IT!
    13:46 <@BenLand100> HE FINALLY GETS IT!!!!1

  14. #14
    Join Date
    Apr 2008
    Location
    Marquette, MI
    Posts
    15,252
    Mentioned
    138 Post(s)
    Quoted
    680 Post(s)

    Default

    Quote Originally Posted by lancerawks View Post
    Now after you would do any clicking that would move your position on the map, you would want to use the ResetTreeVariables, so that if you move to another tree, and it just happens that the TreePoint is over it, it will say that your still choping down the same tree even though your realy on a new one, and it will just sit there waiting for the new tree to be choped down. i just kinda copied/pasted most of this from my script so it might not compile :P but this is just to give you another idea of how to check if the trees still up. hope i helped :]
    Yeah, you did. Thanks.


    Quote Originally Posted by Nava2 View Post
    Your use of the variable i throughout your script will mess up your tree colours. Eventually getting an out of range. You need to use local vars where possible, or use something more.. obvious for your TreeColor Index var.
    Okay thanks , but it didn't fix my problem.
    Last edited by Coh3n; 06-03-2009 at 03:32 AM.

  15. #15
    Join Date
    Jan 2008
    Location
    California, US
    Posts
    2,765
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    If high >= 0 and if high <= 0 is wrong. If it is zero both conditions will be met. Won't fix , just saying .

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

    Default

    I use the following method and it seems to be working 100% accurate:
    - Find the tree and store it's location in x, y (note: the location must be found when you are at the tree. to do this: find tree, click chop, wait till we have stopped moving, find the tree again, store cords to x, y)
    - use FindColorsSpiralTolerance(x, y, TPA, TREECOLOR, x-25, y-25, x+25, y+25, 2);
    - if Length(TPA) < 10, then the tree is there no more!
    - failsafe: MMouse(x, y, 5, 5); if not IsUptext('Chop') then (TreeIsGone:= true)

    edit: oh, i didn't look your script carefully enough, you seem to have used pretty much the same thing with me ^^
    Last edited by marpis; 06-05-2009 at 07:04 PM.

  17. #17
    Join Date
    Dec 2006
    Location
    Canada, BC
    Posts
    728
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    oh yeah your right Da Owner! thanks for catching that xP
    Lance. Da. Pants.

  18. #18
    Join Date
    Apr 2008
    Location
    Marquette, MI
    Posts
    15,252
    Mentioned
    138 Post(s)
    Quoted
    680 Post(s)

    Default

    Quote Originally Posted by marpis View Post
    I use the following method and it seems to be working 100% accurate:
    - Find the tree and store it's location in x, y (note: the location must be found when you are at the tree. to do this: find tree, click chop, wait till we have stopped moving, find the tree again, store cords to x, y)
    - use FindColorsSpiralTolerance(x, y, TPA, TREECOLOR, x-25, y-25, x+25, y+25, 2);
    - if Length(TPA) < 10, then the tree is there no more!
    - failsafe: MMouse(x, y, 5, 5); if not IsUptext('Chop') then (TreeIsGone:= true)

    edit: oh, i didn't look your script carefully enough, you seem to have used pretty much the same thing with me ^^
    Yeah. It's frustrating trying to work out the little things so it works, especially when this is my first script and I'm not all that experienced. I'm sure I'll get it eventually.

  19. #19
    Join Date
    Feb 2007
    Location
    Alberta,Canada
    Posts
    2,358
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by marpis View Post
    I use the following method and it seems to be working 100% accurate:
    - Find the tree and store it's location in x, y (note: the location must be found when you are at the tree. to do this: find tree, click chop, wait till we have stopped moving, find the tree again, store cords to x, y)
    - use FindColorsSpiralTolerance(x, y, TPA, TREECOLOR, x-25, y-25, x+25, y+25, 2);
    - if Length(TPA) < 10, then the tree is there no more!
    - failsafe: MMouse(x, y, 5, 5); if not IsUptext('Chop') then (TreeIsGone:= true)

    edit: oh, i didn't look your script carefully enough, you seem to have used pretty much the same thing with me ^^
    wouldnt it be smarter to start the seach from mmcx, mmcy as if you clicked something in the top left then walk to it, you start your search int hetop left making it watch another tree? Your character should always be in the middle of the screen so i think the middle co ords would be more benificial and accurate.
    “Ignorance, the root and the stem of every evil.”

  20. #20
    Join Date
    Oct 2007
    Location
    Denmark
    Posts
    409
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    This is whta I do:

    SCAR Code:
    function FollowTree(W: TPoint): TPoint;
    var
      T, T2: TPoint;
      TPA: array of TPoint;
      nx, ny, M, Col: Integer;
      Run: Boolean;
    begin
      Col := ReturnCol;
      T := W;
      Wait(400);
      MarkTime(M);
      repeat
        FindColorsTolerance(TPA, 5753055, 715, 105, 731, 110, 15);
        if (Length(TPA) > 10) then
          Run := True
        else
          Run := False;
        FindColorTolerance(T.x, T.y, Col, T2.x - 15, T2.y - 15, T2.x + 15, T2.y + 15, 5);
        if Run then
          Wait(140)
        else
          Wait(400);
        FindColorTolerance(T2.x, T2.y, Col, T.x - 15, T.y - 15, T.x + 15, T.y + 15, 5);
        nx := T.x - T2.x;
        ny := T.y - T2.y;
        if (nx < 0) then
          nx := nx * -1;
        if (ny < 0) then
          ny := ny * -1;
        if InRange(nx, 0, 3) and InRange(ny, 0, 3) then
        begin
          Result := T;
          Break;
        end;
      until(TimeFromMark(M) > 7000);
    end;

    It has been working out pretty good so far.

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
  •