Results 1 to 3 of 3

Thread: GetMMPoints, MapWalk.Scar

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

    Default GetMMPoints, MapWalk.Scar

    Well I figured it would help to make TPA walking more readily available for the average person, so here it is.

    SCAR Code:
    Function GetMMPoints(x, y, color, width, height, tolerance: Integer): TpointArray;
    var tpa: TpointArray; atpa: T2DpointArray; l, i, 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;

    there is a little extra at the end there that isnt really needed but I figured a Rs_OnMiniMap check might be a useful thing, however it can be removed to optimize speed.

    Used as so:

    SCAR Code:
    Function WalkExample: Boolean;
    var TPA: TPointArray; I: Integer;
    begin
      TPA := GetMMPoints(MMcx, MMcy, 14630407, 1, 1, 35);
      if Length(TPA) <= 0 then Exit;
      for i := 0 to High(TPA) do
      begin
        if not rs_OnMiniMap(tpa[i].x, tpa[i].y) then Continue; // useless check if rs_OnMiniMap stays in the function
        Mouse(tpa[i].x+xmod, tpa[i].y+ymod, 5, 5, True);
        if FlagPresent then
        begin
          Result := FFlag(10);
          Exit;
        end;
      end;
    end;
    “Ignorance, the root and the stem of every evil.”

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

    Default

    Okay, I need a better example why this is better..
    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

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

    Default

    ummmm, lets see, its a universal code for TPA Walking, it you simply enter the color, height, width and tol and it will find it on the MM. It results in a TPA giving you the option to SortTPAFrom, or turn it back into a ATPA and do size sorts ect. Some examples from my scripts:

    SCAR Code:
    Function MoveFishingSpots: Boolean;
    var TPA: TpointArray;
    begin
      TPA := GetMMPoints(MMcx, MMcy, 2216175, 1, 1, 15);
      SortTPAFrom(TPA, Point(MMcx, MMcy));
      InvertTPA(TPA);
      Result := ClickMMPoints(TPA, 0, -5);
      Flag;
      Wait(1000+random(750));
    end;

    and

    SCAR Code:
    Function CreateTPALibrary(Index:Integer): TPointArray;
    begin
      case Index of
        0: Result := GetMMPoints(MMcx, MMy2, FindWaterColor, 5, 5, 5);
        1: Result := GetMMPoints(MMcx, MMcy, 14630407, 1, 1, 35);
        2: Result := GetMMPoints(MMcx, MMy1, FindWaterColor, 10, 10, 1);
        3: Result := GetMMPoints(MMcx, MMcy, 2216175, 1, 1, 15);
        4: Result := GetMMPoints(MMcx, MMcy, 861546, 2, 2, 25);
      end;
    end;

    Function FollowWaterTPA: Boolean;
    var a, Int1, Int2: Integer;
    begin
      a := GetSystemTime;
      while (Int1 < 5) do
      begin
        if GetSystemTime-a > 75000 then
          Break;
        if ClickMMPoints(CreateTPALibrary(0), -RandomRange(8, 18), 0) then Inc(Int1) else Inc(Int2);
        if Int1 > 0 then Result := FindFishingSymbol;
        if Result then Break;
      end;
      if Int2 > Int1 then WriteLn('Walking has Failed');
      WriteLn('Took ['+IntToStr(Int1+2)+'] Steps to Fishing Area');
      if not Result then
      begin
        WriteLn('Timer Expired, Walking Failed');
        NextPlayer(False);
      end;
    end;

    Function WalkToBankingArea: Boolean;
    var DTM, int1, int2, k, t: Integer; requiredwait: boolean;
    begin
      WriteLn('Walk to [Banking] Area Initiated');
      DTM := DTMFromString('78DA634C666660B8C600068C108A218053806' +
        '1192382CF980B54731B55CD9F3F4C0CFC487CC63CA09ACB04D4E403D' +
        '59CC1AF060071FE0C41');
      SetRunLevelAt(50);
      k := GetsystemTime;
      while ((Length(CreateTPALibrary(3)) < 4) or (Length(CreateTPALibrary(4)) < 4)) do
      begin
        case Int1 of
          0..3: t := -5;
          4: requiredwait := True;
          5: t := -22;
          6: break;
        end;
        if GetSystemTime-k > 120000 then NextPlayer(False);
        if ClickMMPoints(CreateTPALibrary(2), t, 0) then Inc(Int1) else Inc(Int2);
        if requiredwait then Wait(9500+random(3000));
        requiredwait := False;
      end;
      WriteLn('Bank Symbol Length = '+IntToStr(Length(CreateTPALibrary(3))));
      WriteLn('Bank Floor Length = '+IntToStr(Length(CreateTPALibrary(4))));
      if Int2 > Int1 then WriteLn('Walking has Failed');
      Result := DTMLocate(MMx1, MMy1, MMcx+25, MMy2, DTM, 0, RandomRange(-3, 3), True);
      FreeDTM(DTM);
      if not Result then Result := ClickMMPoints(CreateTPALibrary(4), 0, 0);
      if Result then
      begin
        WriteLn('Found Bank DTM, entering Bank');
        WriteLn('Took ['+IntToStr(Int1+1)+'] Steps to Banking Area');
        Players[CurrentPlayer].Loc := 'bank';
        Flag;
      end;
    end;

    Sorry I dont really know how to explain it, I guess you could say its universal code that can be used to find pretty much any MM object with a semi unique color, or some proper sorting. Symbols, Autocolors, walls and even roads can be easily found with this function.

    edit: an autocolor fix for FindVarrockRoadColors:

    SCAR Code:
    Function FindVarrockColor: Integer;
    var t, i, ii: Integer; TPA: TPointArray; aCol, uCol, tCol: TIntegerArray;
    begin
      TPA := GetMMPoints(MMcx, MMcy-25, 8488581, 5, 5, 25);
      aCol := GetColors(TPA);
      uCol := aCol;
      ClearSameIntegers(aCol);
      SetLength(tCol, high(uCol)+1);
      for i := 0 to high(aCol) do
      begin
        for ii := 0 to high(uCol) do
        begin
          if aCol[i] = uCol[ii] then
            Inc(tCol[ii]);
        end;
      end;
      t := 0;
      for i := 0 to high(uCol) do
        if tCol[i] > tCol[t] then
          t := i;
      Result := uCol[t];
    end;

    I hope this helps to prove this function to be invaluable.
    “Ignorance, the root and the stem of every evil.”

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
  •