Results 1 to 16 of 16

Thread: function SetCompass(Deg: Integer): Boolean;

  1. #1
    Join Date
    Dec 2006
    Location
    Sydney, New South Wales, Australia
    Posts
    4,603
    Mentioned
    15 Post(s)
    Quoted
    42 Post(s)

    Default function SetCompass(Deg: Integer): Boolean;

    I prefer this function over MakeCompass. If you want it, then do the following:
    Replace MapWalk.scar with the following Text:
    SCAR Code:
    //-----------------------------------------------------------------//
    //--               Scar Standard Resource Library                --//
    //--               » MapWalking Routines                         --//
    //-----------------------------------------------------------------//
    // * function SetCompass(Deg: Integer): Boolean;                      // * by Dan's The Man
    // * function MakeCompass(Direction: string): Boolean;                // * by Dan's The Man
    // * Function GetWallAngle(Ps: TPointArray): Extended;                // * by Wizzup?
    // * procedure RunTo(dir: String; runfar: Boolean);                   // * by Mutant Squirrle and nielsie95
    // * procedure RunAway(dir: stri; RunFar: Boolean; Action, WaitTime: Integer); // * by nielsie95 modified by ZephyrsFury
    // * procedure StoreToRoadColorArray;                                 // * by Wizzup? / WT-Fakawi.
    // * function GetOldRoadColors: Boolean;                              // * by Wizzup? / WT-Fakawi.
    // * function GetNewRoadColor(xs, ys, xe, ye, tol: Integer): Boolean; // * by Wizzup? / WT-Fakawi and modified by Ron
    // * function RoadColorChecker: Boolean;                              // * by Wizzup? / WT-Fakawi and modified by Ron
    // * procedure CountFlag(Distance: Integer);                          // * by Wizzup? / WT-Fakawi.
    // * function LinearWalkEx(var tpa: TPointArray; cx, cy, TheColor, tol: Integer; Direction: Integer; Radius: Integer): Boolean;              // * by nielsie95
    // * function RadialWalkEx(var tpa: TPointArray; cx, cy, TheColor, tol: Integer; StartRadial, EndRadial: Integer; Radius: Integer): Boolean; // * by nielsie95
    // * function RadialWalk(TheColor: Integer; StartRadial, EndRadial: Integer; Radius: Integer; Xmod, Ymod: Integer): Boolean;                 // * by nielsie95
    // * function LinearWalk(TheColor: Integer; Direction: Integer; Radius: Integer; Xmod, Ymod: Integer): Boolean;                              // * by nielsie95
    // * function RadialRoadWalk(TheColor: Integer; StartRadial, EndRadial: Integer; Radius: Integer; Xmod, Ymod: Integer): Boolean;             // * by nielsie95
    // * function LinearRoadWalk(TheColor: Integer; Direction: Integer; Radius: Integer; Xmod, Ymod: Integer): Boolean;                          // * by nielsie95
    // * function WaterWalk(StartRadial, EndRadial: Integer; Radius, FFlagBreakOut: Integer; Xoff, Yoff, Xmod, Ymod: Integer): Boolean;          // * by nielsie95
    // * procedure SetAngle(highest : Boolen);                           // * by Raymond
    // * function PlayersOnMap(xx1, yy1, xx2, yy2 : integer) : integer;  // * by footballjds
    //-----------------------------------------------------------------//

    var
      RoadColors: array[1..256] of Integer;
    //* Roadwalk
    { var DebugRadialRoad: Boolean;
      Description: Shows Debug Info on RRW. }

    var
      DebugRadialRoad: Boolean;

    {*******************************************************************************
    function SetCompass(Deg: Integer): Boolean;
    By: Dan's The Man
    Description: Set's the RS compass to degrees Deg and returns True if it does so
      correctly.
    *******************************************************************************}

    function SetCompass(Deg: Integer): Boolean;
    var
      i, bI, bDeg: Integer;
    begin
      Result := False;
      i := (Floor(FixD(Deg)));
      bDeg := Floor(AdjustD(i, (RandomRange(-7, 7))));
      bI := Floor(rs_GetCompassAngleDegrees);
      if(bI < bDeg) then
      begin
        KeyDown(VK_RIGHT);
        while (not(Floor(rs_GetCompassAngleDegrees) >= bDeg)) do
          Wait(2 + RandomRange(1, 3));
        KeyUp(VK_RIGHT);
        Result := True;
      end else
        if(bI > bDeg) then
        begin
          KeyDown(VK_LEFT);
          while (not(Floor(rs_GetCompassAngleDegrees) <= bDeg)) do
            Wait(2 + RandomRange(1, 3));
          KeyUp(VK_LEFT);
          Result := True;
        end else
          Result := (bI = i);
    end;

    {*******************************************************************************
    function MakeCompass(d: Variant): Boolean;
    By: Dan's The Man
    Description: Set's the RS compass to degrees Direction and returns True if it does so
      correctly. This is only in place so it doesn't break scripts which use
      MakeCompass.
    NOTE: I haven't added any fail safes in case Direction isn't a string or an
      Extended/Integer.
    *******************************************************************************}

    function MakeCompass(Direction: Variant): Boolean;
    begin
      case (Direction) of
        'n': Result := SetCompass(360);
        's': Result := SetCompass(180);
        'e': Result := SetCompass(90);
        'w': Result := SetCompass(270);
      end else
        Result := SetCompass(Floor(d));
    end;

    {$DEFINE WALL_ANGLELEFT}

    {*******************************************************************************
    Function GetWallAngle(Ps: TPointArray): Extended;
    by: Wizzup?
    Description: Get's the Minimap angle using Walls. Returns Angle in Radians.
    Used in Maze.scar, but feel free to use for Perfect map aligning projects.
    *******************************************************************************}

    Function GetWallAngle(Ps: TPointArray): Extended;

    Var
       L, I, C: Integer;
       ATPA, gATPA: T2DPointArray;
       P, P2: TPoint;
       B: TBox;

    Begin
      Result := -1.0;
      If High(Ps) = -1 Then
        Exit;
      SortTPAFrom(Ps, Point((550 + 703) / 2, 0));  // Sort it from the center.
      {$IFDEF WALL_ANGLELEFT}
      ATPA := SplitTPAEx(Ps, 0, 1);   // This turns a PointArray into
                                      // vertical lines
      {$ELSE}
      ATPA := SplitTPAEx(Ps, 1, 0); //horizontal lines
      {$ENDIF}

      SortATPASize(ATPA, True);     // longest 'line'.
      L := High(aTPA);
      If L = -1 Then
        Exit;

      SetLength(gATPA, L + 1);
      C := 1;
      gATPA[0] := aTPA[0];
      P := MiddleTPA(aTPA[0]);        // get middle of the line.

      For I := 1 To L Do
      Begin // this loops adds any points that are in a dist of 10 pixels.
            // if vert, then x, hori then y (A wall isn't straight.)
        If Length(aTPA[I]) < 4 Then
          Continue;
        P2 := MiddleTPA(aTPA[I]);
        {$IFDEF WALL_ANGLELEFT} If Abs(P.X - P2.X) < 10 Then
        {$ELSE} If Abs(P.Y - P2.Y) < 10 Then {$ENDIF}
        Begin
          gATPA[C] := aTPA[I];
          C := C + 1;
        End;
      End;
      SetLength(gATPA, C);
      SetLength(Ps, 0);

      Ps := MergeATPA(gATPA);   //Combine all the points. within 10pix
      B := GetTPABounds(Ps);
      SortTPAFrom(Ps, Point((B.X1 + B.X2) / 2, 0));   // sort from center

      SetLength(ATPA, 0);
      ATPA := SplitTPA(Ps, 3);  // split dist three, the left over walls
                                // were all in Ps, and now we split them again.

      SetLength(Ps, 0);
      SortATPASize(ATPA, True);   // longest wall.

      Ps := ATPA[0];
      L := High(Ps);   //angle getting
      Result := ArcTan2(Ps[L].Y -Ps[0].Y, Ps[L].X - Ps[0].X) - (Pi * 0.5);
      {$IFDEF WALL_ANGLELEFT} {$ELSE} Result := Result + 0.5 * Pi {$ENDIF}
    End;

    {*******************************************************************************
    procedure RunAway(dir: string; RunFar: Boolean; Action, WaitTime: Integer);
    By: nielsie95 modified by ZephyrsFury
    Description: Runs away in minimap related direction, based on north.
    Dir can be 'N', 'E', 'S', 'W' or an angle in degrees (145, 93, 180, etc).
    RunFar will run further than normal.
    Action can be either 1, 2 or 3.
     1: RunAway + Wait(WaitTime) + RunBack
     2: RunAway + Wait(WaitTime)
     3: RunBack
    Note: WaitTime is in milliseconds!
    *******************************************************************************}


    procedure RunAway(dir: string; RunFar: Boolean; Action, WaitTime: Integer);
    var
      Rad, Deg, Tab, t: Integer;
    begin
      if not LoggedIn then exit;
      Tab := GetCurrentTab;
      if RunFar then
        Rad := 63
      else
        Rad := 30;
      case UpperCase(dir) of
        'N': Deg := 0;
        'E': Deg := 90;
        'S': Deg := 180;
        'W': Deg := 270;
      else Deg := StrToIntDef(Dir, -1);
      end;
      if (Deg = -1) then
      begin
        srl_Warn('RunAway', '' + Dir + ' is not a valid direction.', warn_AllVersions);
        Exit;
      end;
      if (Action < 3) then
      begin
        SetRun(True);
        MFNF(Trunc(Rad * Sin(Radians(FixD(Rs_GetCompassAngleDegrees + Deg))) + MMCX + Random(5)),
            Trunc(-Rad * Cos(Radians(FixD(Rs_GetCompassAngleDegrees + Deg))) + MMCY + Random(5)),
            1, 1);
        FFlag(0);
        Wait(700);
        t := GetSystemTime;
        while ((GetSystemTime - t) < WaitTime) and LoggedIn do
          if (Random(5) = 0) then
            IdleTime(2000, 500, 1.0)
          else
            Wait((WaitTime - (GetSystemTime - t)) / 5);
      end;
      if (Action = 1) or (Action = 3) then
      begin
        MFNF(Trunc(Rad * Sin(Radians(FixD(Rs_GetCompassAngleDegrees + (Deg + 180)))) + MMCX - Random(5)),
            Trunc(-Rad * Cos(Radians(FixD(Rs_GetCompassAngleDegrees + (Deg + 180)))) + MMCY - Random(5)),
            1, 1);
        FFlag(0);
        Wait(700);
      end;
      SetRun(False);
      GameTab(Tab);
    end;

    {*******************************************************************************
    procedure RunTo(Dir: String; RunFar: Boolean);
    By: EvilChicken!
    Description: Runs to direction
    *******************************************************************************}


    procedure RunTo(Dir: string; RunFar: Boolean);
    begin
      RunAway(dir, RunFar, 2, 0);
    end;

    {*******************************************************************************
    procedure StoreToRoadColorArray;
    By: Wizzup? / WT-Fakawi.
    Description: Stores RoadColor to Array. Debugging and logging purposes.
    *******************************************************************************}

    procedure StoreToRoadColorArray;
    var
      I: Integer;
    begin
      for I := 1 to 256 do
        if RoadColor = RoadColors[i] then
          Exit
        else
          if RoadColors[i] = 0 then
          begin
            RoadColors[i] := RoadColor;
            Exit;
          end;
    end;

    {*******************************************************************************
    function GetOldRoadColors: Boolean;
    By: Wizzup? / WT-Fakawi.
    Description: Tries to find the stored Roadcolor on the minimap and sets RoadColor.
    *******************************************************************************}

    function GetOldRoadColors: Boolean;
    var
      EC, FX, FY: Integer;
    begin
      Result := False;
      for EC := 1 to 256 do
        if RoadColors[EC] <> 0 then
          if FindColorTolerance(FX, FY, RoadColors[EC], MMX1, MMY1, MMX2, MMY2, 10) then
          begin
            RoadColor := RoadColors[EC];
            Result := True;
            Exit;
          end;
    end;

    {*******************************************************************************
    function GetNewRoadColor(xs, ys, xe, ye, tol: Integer): Boolean;
    By: Wizzup? / WT-Fakawi and modified by Ron
    Description: Copies and compares a Bitmap of 20* 20 around Flag with known RoadColor.
    Results the new global RoadColor.
    *******************************************************************************}


    function GetNewRoadColor(xs, ys, xe, ye, tol: Integer): Boolean;
    var
      DebugCanvas, ClientCanvas, MMCanvas: TCanvas;
      fpx, fpy, bmp, w, h: Integer;
      TC: TColor;
      bmp1: Integer;
    begin
      if (DebugRadialRoad) then
      begin
        if (XS > XE) then
          WriteLn('Error with RadialRoadWalk XS : ' + IntToStr(XS) + '  XE : ' +
            IntToStr(XE));
        if (YS > YE) then
          WriteLn('Error with RadialRoadWalk YS : ' + IntToStr(YS) + '  YE : ' +
            IntToStr(YE));
      end;
      w := xe - xs;
      h := ye - ys;
      ActivateClient;
      if (not (LoggedIn)) then Exit;
      if (DebugRadialRoad) then
      begin
        DisplayDebugImgWindow(w, h);
        DebugCanvas := GetDebugCanvas;
        ClientCanvas := GetClientCanvas;
        SafeCopyCanvas(ClientCanvas, DebugCanvas, xs, ys, xe, ye, 0, 0, w, h);
      end;
      bmp1 := BitmapFromString(w, h, '');
      Wait(1);
      MMCanvas := GetBitmapCanvas(bmp1);
      Wait(1);
      try
        bmp := BitmapFromString(w, h, '');
        Wait(1);
        SafeCopyCanvas(getclientcanvas, GetBitmapCanvas(bmp), xs, ys, xe, ye, 0, 0,
          w, h)
      except
        WriteLn('Error with RadialRoadWalk');
        WriteLn('Should be fixed though, so lets debug.');
        WriteLn('xs = ' + IntToStr(xs) + '  ys = ' + IntToStr(ys) + '  xe = ' +
          IntToStr(xe) + '  ye = ' + IntToStr(ye));
        GetClientDimensions(w, h);
        WriteLn('and client area is 0, 0, ' + IntToStr(w) + ', ' + IntToStr(h));
        SaveBitmap(bmp, 'RoadWalkBMP');
        SaveBitmap(bmp1, 'RoadWalkBMP1');
        repeat
          Wait(1000);
        until (not (LoggedIn));
        FreeBitmap(bmp);
        FreeBitmap(bmp1);
        Exit;
      end;
      Wait(1);
      for fpy := 1 to h do
        for fpx := 1 to w do
        begin
          TC := FastGetPixel(bmp, fpx, fpy);
          if SimilarColors(TC, RoadColor, tol) then
          begin
            RoadColor := TC;
            StoreToRoadColorArray;
            Result := True;
            Exit;
          end
        end;
      FreeBitmap(bmp1);
    end;

    {*******************************************************************************
    function RoadColorChecker: Boolean;
    By: Wizzup? / WT-Fakawi and modified by Ron
    Description: Checks for presence of RoadColor. If not found will call GetNewRoadColor
    *******************************************************************************}


    function RoadColorChecker: Boolean;
    var
      Tx, Ty, Flag4, x, y: Integer;
    begin
      if (not (LoggedIn)) then Exit;

      Flag4 := BitmapFromString(4, 4, 'z78DA7373330002379A9100' +
        'F46D14C1'); // New Flag! (maybe, rather big... 4*4)

    // function FindColorCircle(var  x, y: Integer; color, radius, MidPointx, MidPointy: Integer): Boolean;
    // if not FindColorEllipse(x,y,RoadColor,0,MMX1,MMY1,MMX2,MMY2) then  // is there RoadColor ?
    //  if not FindColorCircle(x,y,RoadColor,(MMCY-MMY1),MMCX,MMCY) then
      if (not (FindColor(x, y, RoadColor, MMX1 + 20, MMY1 + 20, MMX2 - 20, MMY2 -
        20))) then // is there RoadColor ?
      begin
        if (FindBitmapIn(Flag4, TX, TY, MMX1, MMY1, MMX2, MMY2)) then
          // is there flag ?
        begin
          if GetNewRoadColor(TX - 14, TY - 14, TX + 26, TY + 26, 10) then
            // then Copycount Bitmap...
          begin
            Result := True;
            if (DebugRadialRoad) then
              WriteLn('THROUGH FLAG!!!!!!!! ---> ' + IntToStr(RoadColor));
          end
          else
          begin
            if (GetOldRoadColors) then
              if (DebugRadialRoad) then
                WriteLn('THROUGH GetOldRoadColors =  ---> ' + IntToStr(RoadColor))
              else
              begin
                if (DebugRadialRoad) then
                  WriteLn('Couldnt Find RoadColor while Flag');
                Players[CurrentPlayer].loc := 'no RoadColor';
                FreeBitmap(Flag4);
                Exit;
              end;
          end;
        end
        else
        begin
          if (GetNewRoadColor(MMCX - 20, MMCY - 20, MMCX + 20, MMCY + 20, 10)) then
            // just grab from centre when no flag
          begin
            Result := True;
            if (DebugRadialRoad) then
              WriteLn('THROUGH MINIMAP!!!!!!!!---> ' + IntToStr(RoadColor));
          end
          else
          begin
            if (GetOldRoadColors) then
              if (DebugRadialRoad) then
                WriteLn('THROUGH GetOldRoadColors =  ---> ' + IntToStr(RoadColor))
              else
              begin
                if (DebugRadialRoad) then
                  WriteLn('Couldnt Find RoadColor while NO Flag');
                Players[CurrentPlayer].loc := 'no RoadColor';
                FreeBitmap(Flag4);
                Exit;
              end;
          end;
        end;
      end;
      FreeBitmap(Flag4);
    end;

    {*******************************************************************************
    procedure CountFlag(Distance: Integer);
    By: Wizzup? / WT-Fakawi.
    Description: Waits until Flag is within "Distance" distance and check for RoadColor
    changes.
    *******************************************************************************}


    procedure CountFlag(Dist: Integer);
    var
      XK, YK, XL, YL, x, y: Integer;
    var
      T1, T2: Extended;
    begin
      T1 := GetTickCount;
      repeat
        T2 := GetTickCount;
        RoadColorChecker;
        Wait(100);
        if FindColor(x, y, 255, MMX1, MMY1, MMX2, MMY2) Then
          if (Dist > Distance(MMCX, MMCY, x + 1, y + 14)) then
            Break;
        RoadColorChecker;
        Wait(100);
        if T2 - T1 > 30000 then
        begin
          if FindColor(XL, YL, 255, MMX1, MMY1, MMX2, MMY2) then
            MFNF(XL, YL, 1, 1)
          else Mouse(MMCX, MMCY, 0, 0, True);
          Break;
        end;
        if not LoggedIn then Exit;
      until (not FindColor(XK, YK, 255, MMX1, MMY1, MMX2, MMY2));
    end;

    {*******************************************************************************
    function LinearWalkEx(var tpa: TPointArray; cx, cy, TheColor, tol: Integer; Direction: Integer; Radius: Integer): Boolean;
    By: Nielsie95
    Description: Finds TheColor from Radial (scanning outwards) for Radius Distance.
    Valid Arguments:
    tpa: Result points.
    Direction: Any number between 0-720. 0=N,90=E,180=S,270=W.
    Radius: Distance from the centre of minimap, i.e. how far away the mouse clicks. Use numbers 20-72
    *******************************************************************************}


    function LinearWalkEx(var tpa: TPointArray; cx, cy, TheColor, tol: Integer; Direction: Integer; Radius: Integer): Boolean;
    var
      i, SD, ED: Integer;
    begin
      Result := False;
      if (not LoggedIn) then Exit;
      i := GetSystemTime;
      Direction := Direction mod 360;
      if (Direction < 50) then
        SD := ((Direction + 360) - 50)
      else
        SD := (Direction - 50);
      ED := (Direction + 50);
      while (SD > 360) do
        SD := SD - 360;
      while (ED > 360) do
        ED := ED - 360;
      try
        FindColorsTolerance(tpa, TheColor, MMX1, MMY1, MMX2, MMY2, tol);
        FilterPointsPie(tpa, SD, ED, 10, Radius, cx, cy);
        LinearSort(tpa, cx, cy, Direction, False);
        Result := (Length(tpa) > 0);
      except srl_Warn('LinearWalkEx', 'LWex error!', warn_AllVersions); Exit; end;
    // Uncomment this for debug
    //  WriteLn('LWex time: '+IntToStr(GetSystemTime - i)+'ms. Found points: '+IntToStr(Length(tpa)));
    end;

    {*******************************************************************************
    function RadialWalkEx(var tpa: TPointArray; cx, cy, TheColor, tol: Integer; StartRadial, EndRadial: Integer; Radius: Integer): Boolean;
    By: Nielsie95
    Description: Finds TheColor from StartRadial to EndRadial for Radius Distance.
    Valid Arguments:
    tpa: Result points.
    StartRadial/EndRadial: Any number between 0-720. 0=N,90=E,180=S,270=W.
    Radius: Distance from the centre of minimap, i.e. how far away the mouse clicks. Use numbers 20-72
    *******************************************************************************}


    function RadialWalkEx(var tpa: TPointArray; cx, cy, TheColor, tol: Integer; StartRadial, EndRadial: Integer; Radius: Integer): Boolean;
    var
      i, SD, ED: Integer;
    begin
      Result := False;
      SD := StartRadial;
      ED := EndRadial;
      if (SD = ED) then
      begin
        WriteLn('Using LinearWalkEx, equal values.');
        Result := LinearWalkEx(tpa, cx, cy, TheColor, tol, StartRadial, Radius);
      end;
      if (SD > ED) then
        Swap(SD, ED);
      while (SD > 360) do
        SD := SD - 360;
      while (ED > 360) do
        ED := ED - 360;
      if (not LoggedIn) then Exit;
      i := GetSystemTime;
      try
        FindColorsTolerance(tpa, TheColor, MMX1, MMY1, MMX2, MMY2, tol);
        FilterPointsPie(tpa, SD, ED, 10, Radius, cx, cy);
        SortCircleWise(tpa, cx, cy, StartRadial, False, StartRadial > EndRadial);
        Result := (Length(tpa) > 0);
      except srl_Warn('RadialWalkEx', 'An exception has occured', warn_AllVersions); Exit; end;
    // Uncomment this for debug
    //  WriteLn('RWex time: '+IntToStr(GetSystemTime - i)+'ms. Found points: '+IntToStr(Length(tpa)));
    end;

    {*******************************************************************************
    function RadialWalk(TheColor: Integer; StartRadial, EndRadial: Integer; Radius: Integer; Xmod, Ymod: Integer): Boolean;
    By: Nielsie95
    Description: Walks TheColor from StartRadial to EndRadial for Radius Distance
    Valid Arguments:
    TheColor: Any Color, but Road- or WaterColor will do fine :)
    StartRadial/EndRadial: Any number between 0-720. 0=N,90=E,180=S,270=W.
    Radius: Distance from the centre of minimap, i.e. how far away the mouse clicks. Use numbers 20-72
    XMod, YMod: deviation from MouseFindFlag. -2 to 2.
    *******************************************************************************}


    function RadialWalk(TheColor: Integer; StartRadial, EndRadial: Integer; Radius: Integer; Xmod, Ymod: Integer): Boolean;
    var
      tpa: TPointArray;
      i: Integer;
    begin
      Result := False;
      if RadialWalkEx(tpa, MMCX, MMCY, TheColor, 0, StartRadial, EndRadial, Radius) then
        for i := 0 to High(tpa) do
          if MFNF(tpa[i].x, tpa[i].y, Xmod, Ymod) then
          begin
            FFlag(10);
            Result := True;
            Break;
          end;
    end;

    {*******************************************************************************
    function LinearWalk(TheColor: Integer; Direction: Integer; Radius: Integer; Xmod, Ymod: Integer): Boolean;
    By: Nielsie95
    Description: Walks TheColor from Direction MIDDLE OUT!by performing windscreenlike scanning movements for Radius Distance
    Valid Arguments:
    TheColor: Any Color, but Road- or WaterColor will do fine :)
    Direction: Any number between 0-720. 0=N,90=E,180=S,270=W.
    Radius: Distance from the centre of minimap, i.e. how far away the mouse clicks. Use numbers 20-72
    XMod, YMod: deviation from MouseFindFlag. -2 to 2.
    *******************************************************************************}


    function LinearWalk(TheColor: Integer; Direction: Integer; Radius: Integer; Xmod, Ymod: Integer): Boolean;
    var
      tpa: TPointArray;
      i: Integer;
    begin
      Result := False;
      if LinearWalkEx(tpa, MMCX, MMCY, TheColor, 0, Direction, Radius) then
        for i := 0 to High(tpa) do
          if MFNF(tpa[i].x, tpa[i].y, Xmod, Ymod) then
          begin
            FFlag(10);
            Result := True;
            Break;
          end;
    end;

    {*******************************************************************************
    function RadialRoadWalk(TheColor: Integer; StartRadial, EndRadial: Integer; Radius: Integer; Xmod, Ymod: Integer): Boolean;
    By: Nielsie95
    Description: Walks TheColor from StartRadial to EndRadial for Radius Distance
    Valid Arguments:
    TheColor: RoadColor. RoadColor will be dynamically updated.
    StartRadial/EndRadial: Any number between 0-720. 0=N,90=E,180=S,270=W.
    Radius: Distance from the centre of minimap, i.e. how far away the mouse clicks. Use numbers 20-72
    XMod, YMod: deviation from MouseFindFlag. -2 to 2.
    *******************************************************************************}


    function RadialRoadWalk(TheColor: Integer; StartRadial, EndRadial: Integer; Radius: Integer; Xmod, Ymod: Integer): Boolean;
    var
      tpa: TPointArray;
      i: Integer;
    begin
      Result := False;
      if (not LoggedIn) then Exit;
      if (RoadColorChecker) then
        if (DebugRadialRoad) then
          WriteLn(' THROUGH RADIALROADWALK=  ---> ' + IntToStr(RoadColor));
      if RadialWalkEx(tpa, MMCX, MMCY, TheColor, 0, StartRadial, EndRadial, Radius) then
        for i := 0 to High(tpa) do
          if MFNF(tpa[i].x, tpa[i].y, Xmod, Ymod) then
          begin
            CountFlag(10);
            Result := True;
            Break;
          end;
    end;


    {*******************************************************************************
    function LinearRoadWalk(TheColor: Integer; Direction: Integer; Radius: Integer; Xmod, Ymod: Integer): Boolean;
    By: Nielsie95
    Description: Walks TheColor from Direction MIDDLE OUT!by performing windscreenlike scanning movements for Radius Distance
    Valid Arguments:
    TheColor: Any Color, but Road- or WaterColor will do fine :)
    Direction: Any number between 0-720. 0=N,90=E,180=S,270=W.
    Radius: Distance from the centre of minimap, i.e. how far away the mouse clicks. Use numbers 20-72
    XMod, YMod: deviation from MouseFindFlag. -2 to 2.
    *******************************************************************************}


    function LinearRoadWalk(TheColor: Integer; Direction: Integer; Radius: Integer; Xmod, Ymod: Integer): Boolean;
    var
      tpa: TPointArray;
      i: Integer;
    begin
      Result := False;
      if (not LoggedIn) then Exit;
      if (RoadColorChecker) then
        if (DebugRadialRoad) then
          WriteLn(' THROUGH RADIALROADWALK=  ---> ' + IntToStr(RoadColor));
      if LinearWalkEx(tpa, MMCX, MMCY, TheColor, 0, Direction, Radius) then
        for i := 0 to High(tpa) do
          if MFNF(tpa[i].x, tpa[i].y, Xmod, Ymod) then
          begin
            CountFlag(10);
            Result := True;
            Break;
          end;
    end;

    {*******************************************************************************
    function WaterWalk(StartRadial, EndRadial: Integer; Radius, FFlagBreakOut: Integer; Xoff, Yoff, Xmod, Ymod: Integer): Boolean;
    By: Nielsie95
    Description: Walks alongside Water.
    StartRadial/EndRadial := Any number between 0-720. 0=N,90=E,180=S,270=W.
    Radius: Distance from the centre of minimap, i.e. how far away the mouse clicks. Use numbers 20-72
    FFlagBreakOut: Distance to flag where it will break out. 15 - 10 is good.
    Xoff, Yoff: Added to found point.
    XMod, YMod: deviation from MouseFindFlag. -2 to 2.
    *******************************************************************************}


    function WaterWalk(StartRadial, EndRadial: Integer; Radius, FFlagBreakOut: Integer; Xoff, Yoff, Xmod, Ymod: Integer): Boolean;
    var
      tpa: TPointArray;
      i: Integer;
    begin
      Result := False;
      if RadialWalkEx(tpa, MMCX, MMCY, WaterColor, 0, StartRadial, EndRadial, Radius) then
        for i := 0 to High(tpa) do
          if MFNF(tpa[i].x + Xoff, tpa[i].y + Yoff, Xmod, Ymod) then
          begin
            FFLag(FFlagBreakOut);
            Result := True;
            Break;
          end;
    end;

    {*******************************************************************************
    procedure SetAngle(Highest : Boolean);
    By: Raymond
    Description: Sets the mainscreen at highest\lowest angle (Depends on the boolean)
    *******************************************************************************}

    procedure SetAngle(Highest : Boolean);
    var
      Key : Byte;
    begin;
      if Highest then
        Key := 38
      else
        Key := 40;
      if (LoggedIn) then
      begin
        KeyDown(Key);
        Sleep(1000 + Random(100) + Random(200));
        KeyUp(Key);
        Wait(500 + Random(100));
      end;
    end;

    {*******************************************************************************
    function PlayersOnMap(xx1, yy1, xx2, yy2 : integer) : integer;
    By: footballjds
    Description: Counts the players on the minimap, not including your own player.
    *******************************************************************************}

    function PlayersOnMap(xx1, yy1, xx2, yy2 : integer) : integer;
    var
      playerses : TPointArray;
    begin
      FindColorsTolerance(playerses, 16711422, xx1, yy1, xx2, yy2, 19);
      RAaSTPA(playerses, 4);
      Result := getArrayLength(playerses) - 1;
    end;

    Now enjoy

    How To Use:
    Extremely simple, just set the parametre Deg to the degrees you want to the compass to turn to For example, if i want the compass East, i'd do:
    SCAR Code:
    begin
      if(SetCompass(90)) then
        Null;
    end.
    Of course replacing null with any piece of script xD
    Or if i want to just use a string, i could do:
    SCAR Code:
    begin
      if(MakeCompass('e')) then
        Null;
    end.

    NOTE: MakeCompass has been over-written in the above include (MapWalk.scar) to use SetCompass.

    For reference, here are some frequently used degrees':
    • North - 360 (or 0)
    • North East - 45
    • East - 90
    • South East - 135
    • South - 180
    • South West - 225
    • West - 270
    • North West - 315


    Credits to BobboHobbo for extra testing

    Hope you use it and enjoy
    Last edited by Daniel; 06-21-2009 at 07:36 PM.
    You may contact me with any concerns you have.
    Are you a victim of harassment? Please notify me or any other staff member.

    | SRL Community Rules | SRL Live Help & Chat | Setting up Simba | F.A.Q's |

  2. #2
    Join Date
    May 2007
    Location
    NSW, Australia
    Posts
    2,823
    Mentioned
    3 Post(s)
    Quoted
    25 Post(s)

    Default

    Oh love it. xD <3.

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

    Default

    Looks alright, but I highly doubt it will be added to SRL,

    This part:

    SCAR Code:
    if(bI = i) then
            Result := True;

    Could be shortened to:

    SCAR Code:
    Result := (bI = i);

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

    Default

    use this
    SCAR Code:
    function MakeCompass(Direction: Variant): Boolean;
    begin
      case VarType(Direction) of
        256: case Direction of
                 'n': Result := SetCompass(360);
                 's': Result := SetCompass(180);
                 'e': Result := SetCompass(90);
                 'w': Result := SetCompass(270);
               end;
        3, 5: SetCompass(Direction);
      end else
      srl_Warn('MakeCompass', 'Invalid parameter', 1);
    end;
    wont cause any problems now

    ~shut

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

    Default

    So what's the difference?

    you do know you can do MakeCompass(90) ?

    ~RM

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

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

    Default

    I made make comass use a variant for a reason..
    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

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

    Default

    Dan, I still don't understand the difference between this one and MakeCompass.

  8. #8
    Join Date
    Nov 2008
    Location
    Norway, Alesund
    Posts
    924
    Mentioned
    0 Post(s)
    Quoted
    37 Post(s)

    Default

    Quote Originally Posted by ZephyrsFury View Post
    Dan, I still don't understand the difference between this one and MakeCompass.
    i think here is not just like

    PHP Code:
    MakeCompass('e');
    MakeCompass('w');
    MakeCompass('s');
    MakeCompass('n'); 
    with that function you can set

    PHP Code:
    SetCompass(90);  //e
    SetCompass(270); //w
    SetCompass(180); //s
    SetCompass(360); //n

    //also you can set up like
    SetCompass(12); //n+12° 
    but i am not sure about that.

  9. #9
    Join Date
    Oct 2006
    Location
    ithurtsithurtsithurtsithurts
    Posts
    2,930
    Mentioned
    7 Post(s)
    Quoted
    135 Post(s)

    Default

    Quote Originally Posted by Laimonas171 View Post
    i think here is not just like

    PHP Code:
    MakeCompass('e');
    MakeCompass('w');
    MakeCompass('s');
    MakeCompass('n'); 
    with that function you can set

    PHP Code:
    SetCompass(90);  //e
    SetCompass(270); //w
    SetCompass(180); //s
    SetCompass(360); //n

    //also you can set up like
    SetCompass(12); //n+12° 
    but i am not sure about that.
    Except that you can do MakeCompass('12') if you wanted to.

  10. #10
    Join Date
    Nov 2008
    Location
    Norway, Alesund
    Posts
    924
    Mentioned
    0 Post(s)
    Quoted
    37 Post(s)

    Default

    Quote Originally Posted by senrath View Post
    Except that you can do MakeCompass('12') if you wanted to.
    Then idk why is needed this function. but i think SET is better then Make. i mean about function name. i think here can mix makeCompass and RadialRoadWalk do like
    Code:
    MakeCompass('degrees where need to find color')'
    function RadialRoadWalk(TheColor; 315, 45;; Radius: Integer; Xmod, Ymod: Integer): Boolean;
    It allways look at color at the front. Minimap North side.

    Code:
    MakeCompass('0')'//N
    function RadialRoadWalk(TheColor; 315, 45;; Radius: Integer; Xmod, Ymod: Integer): Boolean;
    
     MakeCompass('45')'//NE
     function RadialRoadWalk(TheColor; 315, 45;; Radius: Integer; Xmod, Ymod: Integer): Boolean;
    
     MakeCompass('90')'//E
     function RadialRoadWalk(TheColor; 315, 45;; Radius: Integer; Xmod, Ymod: Integer): Boolean;
    
     MakeCompass('135')'//SE
     function RadialRoadWalk(TheColor; 315, 45;; Radius: Integer; Xmod, Ymod: Integer): Boolean;
    
     MakeCompass('180')'//S
     function RadialRoadWalk(TheColor; 315, 45;; Radius: Integer; Xmod, Ymod: Integer): Boolean;
    
     MakeCompass('225')'//SW
     function RadialRoadWalk(TheColor; 315, 45;; Radius: Integer; Xmod, Ymod: Integer): Boolean;
    
     MakeCompass('270')'//W
     function RadialRoadWalk(TheColor; 315, 45;; Radius: Integer; Xmod, Ymod: Integer): Boolean;
    
     MakeCompass('315')'//NW
     function RadialRoadWalk(TheColor; 315, 45;; Radius: Integer; Xmod, Ymod: Integer): Boolean;

  11. #11
    Join Date
    Nov 2008
    Location
    Norway, Alesund
    Posts
    924
    Mentioned
    0 Post(s)
    Quoted
    37 Post(s)

    Default

    Sorry double post. was same msg.

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

    Default

    That's why we got it in the radialwalk function. No point using RW with static start/end radial.
    And it's not too human-like in my opinion.

  13. #13
    Join Date
    Nov 2008
    Location
    Norway, Alesund
    Posts
    924
    Mentioned
    0 Post(s)
    Quoted
    37 Post(s)

    Default

    Quote Originally Posted by Sabzi View Post
    That's why we got it in the radialwalk function. No point using RW with static start/end radial.
    And it's not too human-like in my opinion.
    Maybe you are right. in that option.

  14. #14
    Join Date
    Dec 2006
    Location
    Sydney, New South Wales, Australia
    Posts
    4,603
    Mentioned
    15 Post(s)
    Quoted
    42 Post(s)

    Default

    Meh, this was just one of my functions that i prefer over SRLs cos' it's mine
    You may contact me with any concerns you have.
    Are you a victim of harassment? Please notify me or any other staff member.

    | SRL Community Rules | SRL Live Help & Chat | Setting up Simba | F.A.Q's |

  15. #15
    Join Date
    May 2007
    Location
    NSW, Australia
    Posts
    2,823
    Mentioned
    3 Post(s)
    Quoted
    25 Post(s)

    Default

    Quote Originally Posted by Dan's The Man View Post
    Meh, this was just one of my functions that i prefer over SRLs cos' it's mine
    Wooooooooooo Dan all the way xD.

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

    Default

    Quote Originally Posted by Dan's The Man View Post
    Meh, this was just one of my functions that i prefer over SRLs cos' it's mine
    This is absolutely pointless... This forum is not to share functions, but to improve SRL. is you wish to share your material you have both the Members and the Free Test corner to do so.

    Closed.

    ~RM

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

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
  •