+ Reply to Thread
Results 1 to 14 of 14

Thread: Completed Walking.

  1. #1
    Join Date
    Oct 2007
    Location
    #srl
    Posts
    6,102
    Mentioned
    39 Post(s)
    Quoted
    62 Post(s)

    Default Completed Walking.

    All credits go to Blumblebee as he did it all except for the 'WALK_BANK_Final' bit of walking, that was me.

    It's worked 100% for me every time I've tried it so far.

    Please test and post your thoughts.

    SCAR Code:
    program New;
    {.include srl/srl.scar}

    const
      WALK_TREE_Rock  = 0;
      WALK_TREE_Road  = 1;
      WALK_TREE_Path  = 2;
      WALK_TREE_Final = 3;

      WALK_BANK_Rock  = 4;
      WALK_BANK_Path  = 5;
      WALK_BANK_Road  = 6;
      WALK_BANK_Final = 7;

      SRLAC_RoadColour = 6579821;
      SRLAC_VarrockRoadColour = 8291719;
      SRLAC_FallyRoadColour = 7831173;
      SRLAC_LumbyRoadColour = 8225677;
      SRLAC_DirtRoadColour = 1853272;
      SRLAC_WaterColour = 10850700;
      SRLAC_RockColour = 5658967;
      SRLAC_SandColour = 0;
      SRLAC_BankerColour = 1179390;

    Procedure SortColors(var Colors: tIntegerArray; col: Integer);
    var
      tempB: tIntegerArray;
      Tol: ShortInt;
      I: Integer;
      timer, L: LongInt;
    begin
      timer := getsystemtime;
      tempB := Colors;
      SetArrayLength(Colors, 0);
      Tol := 0;
      while Length(Colors) < (Length(tempB)/2 or 5) do
      begin
        if Getsystemtime-timer > 100 then Break;
        for i := 0 to High(tempB) do
        begin
          if SimilarColors(tempB[i], col, Tol) then
          begin
            L := GetArrayLength(Colors);
            SetArrayLength(Colors, L+1);
            Colors[L] := tempB[i];
          end;
          if Tol > 10 then Break;
          Inc(Tol);
        end;
      end;
    end;

    Function AutoColorMM(const color: Integer): Integer;
    var
      TPA: tPointArray;
      List: tIntegerArray;
      I: Integer;
    begin
      for i := 0 to 15 do
      begin
        FindColorsTolerance(TPA, color, MMx1, MMy1, MMx2, MMy2, 10+i);
        if Length(TPA) > 0 then Break;
      end;
      if Length(TPA) <= 0 then Exit;
      List := getColors(TPA);
      sortColors(List, color);
      if Length(List) <= 0 then Exit;
      result := List[0];
    end;

    Function FindNewVarrockRoadColor: Integer;
    begin
      Result := AutoColorMM(SRLAC_VarrockRoadColour);
    end;

    Function CreateWalkTPA(x, y, color, width, height, tolerance: Integer): TpointArray;
    var
      TPA: tPointArray;
      aTPA: t2DPointArray;
      i: Integer;
      L, P: Integer;
    begin
      FindColorsSpiralTolerance(x, y, TPA, color, MMx1, MMy1, MMx2, MMy2, tolerance);
      aTPA := TPAtoATPAEx(TPA, width, height);
      for i := 0 to High(aTPA) do
      begin
        if Length(aTPA) > 5 then
        begin
          l := getarraylength(Result);
          SetArrayLength(Result, l+1);
          Result[l] := MiddleTpa(aTPA[i]);
        end;
      end;
      if Length(result) = 0 then Exit;
      for i := 0 to High(Result) do
        if rs_OnMiniMap(result[i].x, result[i].y) then Inc(p);
      if p = 0 then SetArrayLength(Result, 0);
    end;

    Function walkTPApoint(TPA: tPointArray; sortP: tPoint; flagDist: shortInt): Boolean;
    var
      i: Integer;
      t: LongInt;
    begin
      t := getSystemTime;
      if Length(TPA) <= 0 then Exit;
      SortTPAFrom(TPA, sortP);
      for i := 0 to High(TPA) do
      begin
        if rs_OnMiniMap(TPA[i].x, TPA[i].y) then
        begin
          Mouse(TPA[i].x, TPA[i].y, random(8), random(8), true);
          while not FlagPresent do
          begin
            wait(250+randomRange(150, 350));
            if getSystemTime-t > randomRange(2500, 3750) then
              continue;
          end;
          FFlag(flagDist);
          Result := True;
          Exit;
        end;
      end;
    end;

    Function CreateColorBox(Color: Integer): TBox;
    var
      TPA: tPointArray;
    begin
      FindColors(TPA, Color, MMx1, MMy1, MMx2, MMy2);
      if Length(TPA) <= 0 then Exit;
      Result := GetTPABounds(TPA);
    end;

    Function FindColorInBox(Color: Integer; Box: TBox): Boolean;
    var
      TPA: tPointArray;
      i: Integer;
    begin
      FindColorsTolerance(TPA, Color, Box.x1-5, Box.y1-5, Box.x2+5, Box.y2+5, 15);
      if Length(TPA) <= 0 then Exit;
      SortTPAFrom(TPA, Point(687, 50));
      for i := 0 to High(TPA) do
      begin
        if not rs_OnMiniMap(TPA[i].x, TPA[i].y) then continue;
        Mouse(TPA[i].x, TPA[i].y, 5, 5, True);
        Wait(750+random(450));
        if FlagPresent then
        begin
          FFlag(10);
          Result := True;
          Exit;
        end;
      end;
    end;

    Function CreateWalkIndex(index: Integer): Boolean;
    var
      i: Integer;
      aTPA: t2DPointArray;
      TPA: tPointArray;
      p: tPoint;
      RockColor, TreeColor, BC: Integer;
      t: LongInt;
    begin
      case index of
        WALK_TREE_Rock:
        begin
          if countColor(RoadColor, MMx1, MMy1, MMx2, MMy2) <= 5 then RoadColor := FindNewVarrockRoadColor;
          if FindColorInBox(RoadColor, CreateColorBox(FindRockColor)) then
          begin
            Result := True;
            Exit;
          end;
          TPA := CreateWalkTPA(MMx2, MMy1, RoadColor, 2, 2, 8);
          if Length(TPA) <= 0 then Exit;
          Result := walkTPApoint(TPA, Point(MMx2-randomRange(5, 15), MMy1), random(10));
          Exit;
        end;
        WALK_TREE_Road:
        begin
          TPA := CreateWalkTPA(MMx2, MMcy, RoadColor, 2, 2, 8);
          if Length(TPA) <= 0 then Exit;
          Result := walkTPAPoint(TPA, Point(MMx2, MMcy), random(15));
          if Result then Exit;
          if not LinearWalkTolerance(RoadColor, randomRange(80, 90), randomRange(59, 68), random(8), random(8), 8) then
            if not RadialWalkTolerance(RoadColor, 80, 90, randomRange(55, 69), random(8), random(8), 10) then
          begin
            WriteLn('Walking Failed Here. Submit a Fix.');
            logOut;
            NextPlayer(False);
            Exit;
          end;
          Result := True;
          Exit;
        end;
        WALK_TREE_Path:
        begin
          RockColor := AutoColorMM(SRLAC_RockColour);
          TPA := CreateWalkTPA(MMcx, MMy1, RockColor, 2, 2, 8);
          if length(TPA) <= 0 then Exit;
          for i := 0 to High(TPA) do
          begin
            if TPA[i].y > MMcy then continue;
            Mouse(TPA[i].x, TPA[i].y, 5, 5, true);
            t := getSystemTime;
            while not flagPresent() do
            begin
              if getSystemTime-t > randomRange(2000, 2500) then
                Exit;
              wait(250+random(500));
            end;
            FFlag(random(8));
            Result := True;
            Exit;
          end;
        end;
        WALK_TREE_Final:
        begin
          TreeColor := AutoColorMM(1532978);
          writeLn('Tree AutoColor = '+IntToStr(TreeColor));
          FindColorsTolerance(TPA, TreeColor, MMx1, MMy1, MMx2, MMy2, 8);
          if Length(TPA) <= 0 then Exit;
          aTPA := SplitTPAEx(TPA, 10, 10);
          if Length(aTPA) <= 0 then Exit;
          SortATPASize(aTPA, true);
          p := MiddleTPA(aTPA[0]);
          if (p.x < MMcx+20) and (p.y < MMcy) then
          begin
            Mouse(p.x, p.y, 5, 5, true);
            Flag();
            Result := True;
            Exit;
          end;
        end;
        WALK_BANK_Rock:
        begin
          RockColor := AutoColorMM(SRLAC_RockColour);
          TPA := CreateWalkTPA(MMcx, MMy2, RockColor, 2, 2, randomRange(5, 10));
          if Length(TPA) <= 0 then Exit;
          SortTPAFrom(TPA, point(700, 150));
          for i := 0 to High(TPA) do
          begin
            if (TPA[i].y < MMcy-10) then continue;
            Mouse(TPA[i].x-5, TPA[i].y, Random(8), Random(8), true);
            t := getSystemTime;
            while not flagPresent() do
            begin
              if getSystemTime-t > randomRange(2000, 2500) then
                Exit;
              wait(250+random(500));
            end;
            FFlag(RandomRange(5, 10));
            Result := True;
            Exit;
          end;
        end;
        WALK_BANK_Path:
        begin
          RoadColor := FindNewVarrockRoadColor();
          if not RadialWalkTolerance(RoadColor, 180, 200, 60, 5, 5, 8) then
            if not RadialWalkTolerance(RoadColor, 170, 220, 70, 5, 5, 12) then
          begin
            writeLn('Should''ve made custom TPA walking here XD');
            Exit;
          end;
          Result := True;
          Exit;
        end;
        WALK_BANK_Road:
        begin
          TPA := CreateWalkTPA(MMx1, MMcy, RoadColor, 3, 3, 8);
          if Length(TPA) <= 0 then
            Exit;
          SortTPAFrom(TPA, point(MMx1-10, MMcy));
          for i := 0 to High(TPA) do
          begin
            if not RS_onMinimap(TPA[i].x, TPA[i].y) then Continue;
            Mouse(TPA[i].x, TPA[i].y, 5, 5, true);
             t := getSystemTime;
            while not flagPresent() do
            begin
              if getSystemTime-t > randomRange(2000, 2500) then
                Exit;
              wait(250+random(500));
            end;
            FFlag(RandomRange(1, 5));
            Result := True;
            Exit;
          end;
        end;
        WALK_BANK_Final:
        begin
          for i := 0 to 2 do
          begin
            BC := AutoColorMM(SRLAC_BankerColour);
            FindColorsTolerance(TPA, BC, MMx1, MMCy + 18, MMCx, MMy2, 1);
            if Length(TPA) > 5 then
              Break;
            if i = 2 then
            begin
              MSI_Debug('CreateWalkIndex(WALK_BANK_Final);', 'Failed to find bankers on MiniMap.', Debug_Functions);
              Exit;
            end;
          end;
          SortTPAFrom(TPA, Point(MMCx, MMCy));
          for i := 0 to High(TPA) do
          begin
            t := Random(High(TPA));
            if rs_OnMiniMap(TPA[t].x, TPA[t].y) then
              Break;
            if i = High(TPA) then
            begin
              MSI_Debug('CreateWalkIndex(WALK_BANK_Final);', 'Points not on MiniMap!', Debug_Functions);
              Exit;
            end;
          end;
          Mouse(TPA[t].x, TPA[t].y - RandomRange(3, 7), 3, 3, True);
          t := getSystemTime;
          while not flagPresent() do
          begin
            if getSystemTime-t > randomRange(2000, 2500) then
              Exit;
            wait(250+random(500));
          end;
          FFlag(3);
          Result := True;
        end;
      end;
    end;

    var
      i: Integer;
    begin
      setUpSRL;
      RoadColor := FindNewVarrockRoadColor;
      for i := WALK_TREE_rock to WALK_TREE_final do
        CreateWalkIndex(i);
      CreateWalkIndex(WALK_BANK_Rock);
      CreateWalkIndex(WALK_BANK_Path);
      CreateWalkIndex(WALK_BANK_Road);
      CreateWalkIndex(WALK_BANK_Final);
    end.

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

    Default

    looks good man, thanks for finishing
    “Ignorance, the root and the stem of every evil.”

  3. #3
    Join Date
    Oct 2007
    Location
    #srl
    Posts
    6,102
    Mentioned
    39 Post(s)
    Quoted
    62 Post(s)

    Default

    Quote Originally Posted by Blumblebee View Post
    looks good man, thanks for finishing
    It was my pleasure

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

    Default

    Some names are quite misleading:
    - "Function FindColorInBox(Color: Integer; Box: TBox): Boolean;" also clicks, not just finds
    - "Function CreateWalkIndex(index: Integer): Boolean;" also walks, not just creates the path

    You could've used FindMMLocation..
    I'll try this now

    E: You could actually make it work somehow like this
    CreateWalkIndex(Walk_Varrock_East_Trees[0]);
    CreateWalkIndex(Walk_Varrock_East_Trees[1]);
    CreateWalkIndex(Walk_Varrock_East_Trees[2]);
    and back it would be [2] [1] [0]
    It would look nice if all walking were in this form.

    E: It failed at the first try. Clicked 1 or 2 pixels outside minimap :-\ You should check "if InCircle(X, Y, 72, MMCX, MMCY)" rather than "if rs_OnMinimap"

    E: Changed the rs_OnMinimap -> InCircle and worked perfectly Excellent job! but one suggestion: when arriving at the trees or at the bank, you should do a "if not IsMoving" check because the flag doesn't disappear if you can't reach it, like when you click behind the bank booth.
    Last edited by marpis; 01-30-2010 at 11:55 AM.

  5. #5
    Join Date
    Oct 2007
    Location
    #srl
    Posts
    6,102
    Mentioned
    39 Post(s)
    Quoted
    62 Post(s)

    Default

    Quote Originally Posted by marpis View Post
    Some names are quite misleading:
    - "Function FindColorInBox(Color: Integer; Box: TBox): Boolean;" also clicks, not just finds
    - "Function CreateWalkIndex(index: Integer): Boolean;" also walks, not just creates the path

    You could've used FindMMLocation..
    I'll try this now

    E: You could actually make it work somehow like this
    CreateWalkIndex(Walk_Varrock_East_Trees[0]);
    CreateWalkIndex(Walk_Varrock_East_Trees[1]);
    CreateWalkIndex(Walk_Varrock_East_Trees[2]);
    and back it would be [2] [1] [0]
    It would look nice if all walking were in this form.

    E: It failed at the first try. Clicked 1 or 2 pixels outside minimap :-\ You should check "if InCircle(X, Y, 72, MMCX, MMCY)" rather than "if rs_OnMinimap"

    E: Changed the rs_OnMinimap -> InCircle and worked perfectly Excellent job! but one suggestion: when arriving at the trees or at the bank, you should do a "if not IsMoving" check because the flag doesn't disappear if you can't reach it, like when you click behind the bank booth.
    Care to post your edited version for others to test?

  6. #6
    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
    Excellent job! but one suggestion: when arriving at the trees or at the bank, you should do a "if not IsMoving" check because the flag doesn't disappear if you can't reach it, like when you click behind the bank booth.
    Only do that as a failsafe because in my experience, it's really slow when detecting if the player is moving or not (it takes a few seconds to notice). I my Draynor script, when I switched from IsMoving to the Flag functions, it worked 100% faster.

    Marpis, you may be able to edit you IsMoving function, I don't know. I've never looked at it.

    Otherwise looks very good guys.

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

    Default

    Quote Originally Posted by Coh3n View Post
    Only do that as a failsafe because in my experience, it's really slow when detecting if the player is moving or not (it takes a few seconds to notice). I my Draynor script, when I switched from IsMoving to the Flag functions, it worked 100% faster.

    Marpis, you may be able to edit you IsMoving function, I don't know. I've never looked at it.

    Otherwise looks very good guys.
    For me it works great? o_O

  8. #8
    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
    For me it works great? o_O
    Oh well, not sure then. I could have just been using it the wrong way.

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

    Default

    marpis:

    When I wrote the script I did not have the MSI include handy so I did not know of FindMMLocation (unless its in SRL, then I apologize for my laziness for not looking).

    Naming the functions I start out naming them for a purpose but end up making them complete the task instead of just doing its initial purpose. I don't really like the sound of FindAndClickColorInBox() to much anyways .

    I would assume this [the script] is not "MSI standards" at the moment. I am getting more and more time and my RL "issue" is becoming less of a hassle to me so I could convert if required (although I would need a list of what to convert and why).

    Lastly, I must be interpreting the whole "CreateWalkIndex(Walk_Varrock_East_Trees[0]);" wrong. How can it be 0..2 to the tree's and 2..0 to the bank? unless we are changing the index array to Walk_Varrock_East_bank[i] and the I wouldn't understand why we would count down and not up. If you could further explain your thought process I would much appreciate, I'm sure its just my inability to read/communicate.
    “Ignorance, the root and the stem of every evil.”

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

    Default

    Quote Originally Posted by Blumblebee View Post
    marpis:

    When I wrote the script I did not have the MSI include handy so I did not know of FindMMLocation (unless its in SRL, then I apologize for my laziness for not looking).

    Naming the functions I start out naming them for a purpose but end up making them complete the task instead of just doing its initial purpose. I don't really like the sound of FindAndClickColorInBox() to much anyways .

    I would assume this [the script] is not "MSI standards" at the moment. I am getting more and more time and my RL "issue" is becoming less of a hassle to me so I could convert if required (although I would need a list of what to convert and why).

    Lastly, I must be interpreting the whole "CreateWalkIndex(Walk_Varrock_East_Trees[0]);" wrong. How can it be 0..2 to the tree's and 2..0 to the bank? unless we are changing the index array to Walk_Varrock_East_bank[i] and the I wouldn't understand why we would count down and not up. If you could further explain your thought process I would much appreciate, I'm sure its just my inability to read/communicate.
    SCAR Code:
    function WalkingThing(Step: integer): boolean;
    begin
      case Players[CurrentPlayer].Integers[P_Location] of
        Loc_VarrockEast:
          case Players[CurrentPlayer].Integers[P_Activity] of
            Act_Woodcutting:
              case Step of
                0: begin
                      // Enter bank
                    end;
                1: begin
                      // One step towards the trees
                    end;
                2: begin
                      // 2nd step towards the trees
                    end;
                3: begin
                      // Click the tree spot and we're there
                    end;
    end;


    for I := 1 to 3 do
      WalkingThing(I); // Walks to the trees

    for I := 2 downto 0 do
      WalkingThing(I); // Walks to bank

    Now that I think of it this system couldn't be using radialwalk before you somehow determine with your position on MM which way we're going..

    EDIT: New idea:
    SCAR Code:
    Type
      TColorWalkPath = record
        ToBank: array of function: boolean;
        ToLocation: array of function: boolean;
      end;

    //Walking to trees
    var
      Varrock_East_Trees: TColorWalkPath;

    SetLength(Varrock_East_Trees.ToBank, 4);
    SetLength(Varrock_East_Trees.ToLocation, 4);
    Varrock_East_Trees.ToBank[0] := @FirstStep;
    Varrock_East_Trees.ToBank[1] := @SecondStep;
    etc.etc.

    for I := 0 to High(Varrock_East_Trees.ToBank) do
      if not Varrock_East_Trees.ToBank[I]() then
        writeLn('oh no');
    Last edited by marpis; 02-02-2010 at 08:43 AM.

  11. #11
    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
    SCAR Code:
    function WalkingThing(Step: integer): boolean;
    begin
      case Players[CurrentPlayer].Integers[P_Location] of
        Loc_VarrockEast:
          case Players[CurrentPlayer].Integers[P_Activity] of
            Act_Woodcutting:
              case Step of
                0: begin
                      // Enter bank
                    end;
                1: begin
                      // One step towards the trees
                    end;
                2: begin
                      // 2nd step towards the trees
                    end;
                3: begin
                      // Click the tree spot and we're there
                    end;
    end;


    for I := 1 to 3 do
      WalkingThing(I); // Walks to the trees

    for I := 2 downto 0 do
      WalkingThing(I); // Walks to bank

    Now that I think of it this system couldn't be using radialwalk before you somehow determine with your position on MM which way we're going..

    EDIT: New idea:
    SCAR Code:
    Type
      TColorWalkPath = record
        ToBank: array of function: boolean;
        ToLocation: array of function: boolean;
      end;

    //Walking to trees
    var
      Varrock_East_Trees: TColorWalkPath;

    SetLength(Varrock_East_Trees.ToBank, 4);
    SetLength(Varrock_East_Trees.ToLocation, 4);
    Varrock_East_Trees.ToBank[0] := @FirstStep;
    Varrock_East_Trees.ToBank[1] := @SecondStep;
    etc.etc.

    for I := 0 to High(Varrock_East_Trees.ToBank) do
      if not Varrock_East_Trees.ToBank[I]() then
        writeLn('oh no');
    I like the new idea, and I could not figure out how you can go 2 downto 0 as the walking is not the same (you would continue to walk NW if I were to use the East Tree Example).

    I really like the pointer Idea I think its smart and organized.
    “Ignorance, the root and the stem of every evil.”

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

    Default

    What I would say is get the walking up and running (ha ha pun), then think about tweaking it .
    Although the pointer idea looks cool, I think we should focus on our priorities atm. For example the player form, heh

  13. #13
    Join Date
    Oct 2007
    Location
    #srl
    Posts
    6,102
    Mentioned
    39 Post(s)
    Quoted
    62 Post(s)

    Default

    Quote Originally Posted by marpis View Post
    Now that I think of it this system couldn't be using radialwalk before you somehow determine with your position on MM which way we're going..
    Why do we need to use RadialWalk? The current tpa walking works good?

    Quote Originally Posted by Naum View Post
    What I would say is get the walking up and running (ha ha pun), then think about tweaking it .
    I should be working fine at this point.

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

    Default

    Seems to me that very soon MSI will be cutting some trees....

    ~RM

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

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

Posting Permissions

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