Results 1 to 5 of 5

Thread: How to use procedure TRSMinimap.SetCompassAngle?

  1. #1
    Join Date
    Oct 2014
    Location
    Belgium
    Posts
    33
    Mentioned
    0 Post(s)
    Quoted
    9 Post(s)

    Question How to use procedure TRSMinimap.SetCompassAngle?

    Dear Villavu Members,

    I need help with how to move the ingame minimap compass.

    I have found some procedures but i realy dont know how to use them

    when i was looking for TRSMinimap.SetCompassAngle i did only find this link https://srldocs.github.io/SRL/minimap.html#minimap and there was no Guide how to use this procedure or function on the forums.

    my goal is when the script starts it has to move it compas to randomly move's to easy find the Gate ingame.

    its realy sad that i even dont know how to make a simple script to move the compass

    I have found this code
    Simba Code:
    Minimap.SetCompassAngle([0,90,180,270][Random(4)]+Random(-15,15));
    on this forums --> https://villavu.com/forum/showthread.php?t=118101

    the code did work but after running the script again i always get this Error -->

    Compiled succesfully in 2078 ms.
    Runtime error: "Index out of range (index:2, low:0, high:0)" at line 255, column 35 in file "C:\Simba SRL\Scripts\Inventory Checker full or not full.simba"
    Succesfully executed in 35110 ms.
    The following bitmaps were not freed: [0, Minimap mask, Smart[10660] Image, 3, 4]

    so if re-open simba and run the script it only works 1 time after that i always get that error above.

    any idea how to use the function or procedure and not getting the error above and using the inbuild procedure?

    anyways you can find my script in this Attachment. Inventory Checker full or not full.simba


    and also here Thanks to "Dan the man"




    Simba Code:
    program Inventory_Checker;
    {$H-}
    {$define SMART}
    {$I SRL/OSR.simba}
    {$I RSWalker/Walker.simba}


    var

      Walker        : TRSWalker;

      Supplies_Path,
      Bank_Path     : TPointArray;

    procedure WalkTo(Path: TPointArray);

    begin
      Walker.WalkPath(Path);
    end;

    const
      LOGIN_NAME = '';    //Username/Email
      LOGIN_PASS = '';    //Password
      RS_WORLD   = -1;                             //Desired World (-1 = Random)
      IS_MEMBER  = false;                          //True if your player is a Member



    procedure declarePlayers();
    begin
      with Players.New()^ do
      begin
        LoginName  := LOGIN_NAME;
        Password   := LOGIN_PASS;
        IsActive   := True;
        IsMember   := IS_MEMBER;
        World      := RS_WORLD;
      end;
      Players.SetCurrent(0);
    end;


    type
          TMSObject = record
          WorldLoc  : TPointArray; //locations on the world map
          Color     : TCTS2Color;  //must have color
          MinCount  : Int32;       //size of TPA
          SplitDist : Int32;
    end;


      function TMSObject.Find(DoSort: Boolean=False; Expand:Int32=0): TRectArray;

    var

        loc, me        : TPoint;
        rect           : TRectangle;
        locations, TPA : TPointArray;
        ATPA           : T2DPointArray;

    begin

        me := Walker.GetMyPos();

        locations := Copy(Self.WorldLoc);

        if DoSort then Locations.Sorted(me);

        for loc in Locations do

    begin

        rect := Walker.GetTileMSEx(me, loc, 1).Expand(Expand);
        if MainScreen.GetBounds.Contains(rect.Bounds) then

    begin

        if (srl.FindColors(TPA, Color, rect.Bounds) < Self.MinCount) then
        Continue;

        if (Self.SplitDist > 0) then

    begin

        TPA    := rect.Filter(TPA);
        ATPA   := TPA.Cluster(Self.SplitDist);
        ATPA.SortByMiddle(rect.Mean);
        Result += ATPA[0].MinAreaRect;

    end else

        Result += rect.Expand(-Expand);

    end;
    end;
    end;

    Function Fill_inventory_wih_supplies(): boolean;

    Begin

    WriteLn('Picking');

    end;

    Function Open_Gate(): boolean;

    var

        i         :   Int32;
        obj       :   TMSObject;
        rectangles:   array of TRectangle;
        tpa       :   TPointArray;
        atpa      :   T2DPointArray;
        Pnts      :   TPointArray;
        Pnt       :   Tpoint;

    begin

        while True do

    begin
             //       Gate Location,          color of Gate, min points, splitDist.
        obj := [[[4374, 2618],[4376, 2620]], CTS2(4813184, 4), 200,         8];

        rectangles := obj.Find(True, 50);

        smart.Image.Clear();

        for i:=0 to High(rectangles) do

        smart.Image.DrawTPA(rectangles[i].ToTPA.Connect, $00FFFF);



    begin

        wait(RandomRange(1320, 1460));

        mouse.Move(rectangles[0].Bounds);

        wait(RandomRange(1320, 1460));

    if MainScreen.IsUpText(['Op', 'en']) then

        mouse.Click(mouse_Left);

        wait(RandomRange(1320, 1460));

        smart.Image.Clear();

        wait(RandomRange(1320, 1460));

        Fill_inventory_wih_supplies();


    if not MainScreen.IsUpText(['Cl', 'ose']) then

    Begin

       WriteLn('The Gate is open');

       Fill_inventory_wih_supplies();

    end else

       Open_Gate();

       wait(RandomRange(1320, 1460));

    end;

    end;

        smart.Image.Clear();



    end;


    Function Walk_to_supplies(): Boolean;

    Begin

    walkTo(Supplies_Path);    //Walks to the Supplies

    Open_Gate();

    Result := True;

    end;

    Function Deposite_Supplies(): boolean;

    Begin

    //test

    end;

    Function Walk_to_Bank(): Boolean;

    Begin

    walkTo(Bank_Path);       //Walks to the Bank

    Deposite_Supplies();

    Result := True;

    end;

    function Check_Inventory(): Boolean;
    begin
      Result := Gametabs.Open(tabInventory);

       while (not Inventory.IsFull) do

    begin

       if Walk_to_supplies() then
          Fill_inventory_wih_supplies();

    end else

       Walk_to_Bank();

    end;


    function setUp(): boolean
    begin

      SRL.Setup([]);                    //Setup SRL to allow us to acces it's functions.

      declarePlayers();                 //Declare the player we are using

      Walker.Init('World.png');         //Setup RSWalker by initializing the map we want to use.

                                        //The path that we plan to walk (Supplies_path = Grain field)
      Supplies_path := [[4538, 2690], [4540, 2658], [4521, 2630], [4500, 2620], [4460, 2611], [4427, 2610], [4402, 2619], [4375, 2623]];
                                        //The path that we plan to walk (Bank_path = Varrock West Bank)
      Bank_path     := [[4373, 2624], [4430, 2625], [4471, 2638], [4509, 2643], [4537, 2688]];

      AddOnTerminate(@Walker.Free);     // automatic free once script shuts down

      Walker.skipClose := 40;           //how close to the target point before we try to click the next point.

      if (not SRL.isLoggedIn) then      //If not logged in then..
      begin
         Players.LoginCurrent();        //Log player in
         MainScreen.setAngle(True);     //Sets the camera angle to the highest point
         wait(RandomRange(2010, 2530));
         Minimap.SetCompassAngle([150][Random(4)]);
      end;


      Result := True;
    end;

    begin //Main

      if setUp then                     //Calls the setup of the script

          writeln('We are set up and ready to go!');

      if Check_Inventory then

          writeln('Inventory is open');

      if Walk_to_Bank then

          writeln('Inventory is full going to bank');

      if Walk_to_supplies then

          writeln('Inventory is not full going to supplies');

      if  Fill_inventory_wih_supplies then

          writeln('Picking supplies');

       Check_Inventory();

    end.

  2. #2
    Join Date
    Feb 2012
    Location
    Canada
    Posts
    1,164
    Mentioned
    26 Post(s)
    Quoted
    433 Post(s)

    Default

    You should be able to set a random angle using the following code:
    Simba Code:
    Minimap.SetCompassAngle(randomRange(0, 360));

    Edit: To explain the function a bit more, you can see that the function requires two parameters:
    Simba Code:
    procedure TRSMinimap.SetCompassAngle(Degrees: Double; Mouse: Boolean = True);

    The first of the two parameters is a double. Here is its definition:
    A double is a double-precision, 64-bit floating-point data type. It accommodates 15 to 16 digits, with a range of approximately 5.0 × 10^-345 to 1.7 × 10^308.
    (Sourced from here)
    Essentially, it is almost any number that can be entered into this spot. To make it work randomly, we want to use the built-in function:
    Simba Code:
    function RandomRange(const aFrom, aTo: Integer): Integer

    This function returns a value between aFrom and aTo. I use this function to choose a random position between 0 and 360 to set the angle as.


    There is also the boolean, which is a simple true or false statement that let's the program know if we want to use the arrow keys or the mouse to change the angle of the screen. By default, it is set to true but can be overwritten by using the following:
    Simba Code:
    Minimap.SetCompassAngle(randomRange(0, 360), False);
    Last edited by StickToTheScript; 02-27-2019 at 04:05 PM.

  3. #3
    Join Date
    Jun 2015
    Posts
    36
    Mentioned
    0 Post(s)
    Quoted
    5 Post(s)

    Default

    The code StickToTheScript posted should work for your needs, but just for reference, the code you referred to:
    Simba Code:
    Minimap.SetCompassAngle([0,90,180,270][Random(4)]+Random(-15,15));
    is creating an array with 4 values stored in it: [0, 90, 180, 270] and then calling a random index from that array [Random(4)] plus adding a little extra randomness to the selected index with +Random(-15, 15).

    The reason your code is causing an error:
    Simba Code:
    Minimap.SetCompassAngle([150][Random(4)]);
    is because you are creating an array with only 1 value stored in it [150] and choosing a random index from 0 to 3 [Random(4)]. So when it happens to pick 0 at random the code works fine, but the rest of the time it chooses 1,2 or 3 it throws the index out of range error.

  4. #4
    Join Date
    Oct 2014
    Location
    Belgium
    Posts
    33
    Mentioned
    0 Post(s)
    Quoted
    9 Post(s)

    Default

    Dear StickToTheScript,

    Thank you for helping me out i did use this code for random compas movement to exact coordinate this

    is the code that i am using now -->
    Simba Code:
    Minimap.SetCompassAngle(RandomRange(150, 0), False);

  5. #5
    Join Date
    Oct 2014
    Location
    Belgium
    Posts
    33
    Mentioned
    0 Post(s)
    Quoted
    9 Post(s)

    Default

    Dear daileyj93,

    Thank you also fot helping me out it realy means alot.

    now i can go further to the next step picking up the supplies

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
  •