Results 1 to 7 of 7

Thread: Need some help/advice with arrays

  1. #1
    Join Date
    Dec 2011
    Location
    The Netherlands
    Posts
    1,631
    Mentioned
    47 Post(s)
    Quoted
    254 Post(s)

    Default Need some help/advice with arrays

    Hi

    I've been pretty busy with the development of my Great Orb Project script, and today I've pretty much finished a big part. The part that is finished now will detect which altar the player is located, and will walk close to the altar. If the player is close to an altar already, it will won't do anything. I've used a couple different methods of walking to make this happen and I'm proud to say that it is working now.

    So yeah, the code
    Simba Code:
    program Test;
    {$DEFINE SMART}
    {$i srl/srl.simba}
    {$i sps/sps.simba}

    Const
      Area_Air = 'Air';
      Area_Earth = 'Earth';
      Area_Water = 'Water';
      Area_Fire = 'Fire';
      Area_Mind = 'Mind';
      Area_Body = 'Body';

    procedure DeclarePlayers;
    begin
      HowManyPlayers := 1;
      NumberOfPlayers(HowManyPlayers);
      CurrentPlayer := 0;

      with Players[0] do
        begin
          Name := '';
          Pass := '';
          Pin := '';
          Active := True;
        end;
    end;

    procedure SetupLogin;
    begin
      ClearDebug;
      Smart_Server := 10;
      Smart_Members := False;
      Smart_Signed := True;
      Smart_SuperDetail := False;
      SetupSRL;
      DeclarePlayers;
      LoginPlayer;
      //Wait(1000 + Random(3000));
      //ClickNorth(0);
    end;

    procedure FindTheEarthAltar;
    var
      EarthAltarDTM, X, Y: Integer;
      aFound: Extended;
      MyPos, EarthAltarPos: TPoint;

    begin
      if not(FindColoredAreaTolerance(X, Y, 6249310, MSX1, MSY1, MSX2, MSY2, 1000, 8)) then
        begin
          EarthAltarDTM := DTMFromString('mVAEAAHicpc+xCwFxGMbxp98VMvkTTCR0V9IJRVw2lzIYxaHLYJQMFv+qRTFQlIlvdzdZ761Pz/OMb0HSKxO74pLkG1ZWysHgwb7hjic++CYaRiqiZOLeh4dessuowIGLDrpowcZ+MdDKr2k7tbWbOVHO/aY2k7qW42rkHLYjp3CkQzDUce3FO3CV54c0LJgU/u8H1cEhEw==');
          if not(FindDTMRotated(EarthAltarDTM, X, Y, MMX1, MMY1, MMX2, MMY2, -Pi/4, Pi/4, Pi/60, aFound)) then
            begin
              SPS_Setup(RUNESCAPE_SURFACE, ['0_8']);
              MyPos:=SPS_GetMyPos;
              Writeln('My position is  x: '+inttostr(MyPos.x)+' y: '+inttostr(MyPos.y));
              EarthAltarPos := Point(RandomRange(223, 247), RandomRange(3415, 3431));
              SPS_BlindWalk(EarthAltarPos);
              FreeDTM(EarthAltarDTM);
            end else
            begin
              WriteLn('We have found the EarthAltarDTM on the minimap');
              MMouse(X, Y, 2, 2);
              Wait(25 + Random(125));
              ClickMouse2(1);
              Wait(100 + Random(100));
              repeat
                Wait(50 + Random(50));
              until (IsMoving=False);
              FreeDTM(EarthAltarDTM);
            end;
        end else
        begin
          WriteLn('We can see the earth altar on our main screen!');
        end;
    end;

    procedure FindTheFireAltar;
    var
      FireAltarDTM, X, Y: Integer;
      aFound: Extended;

    begin
      if not(FindColoredAreaTolerance(X, Y, 6512482, MSX1, MSY1, MSX2, MSY2, 7500, 6)) then
        begin
          FireAltarDTM := DTMFromString('m6wAAAHic42ZgYGhiYmBoBOIiKD0BiKOBeAkQdwBxNRC3A3ElEFsD1esAsQ0QezFA+JZA7ADETkDsCMQmUBztZ80Q5m7AEO1txJDgZ8oQ5KzLoCvNDcYpQeYMWeHWDGkhFmAsAlTPRSRmIgEjAQCZCRFl');
          if not(FindDTMRotated(FireAltarDTM, X, Y, MMX1, MMY1, MMX2, MMY2, -Pi/4, Pi/4, Pi/60, aFound)) then
            begin
              WriteLn('We haven`t found the DTM, radial walking near the altar');
              RadialWalkTolerance(3823718, 0, 359, 75, 5, 5, 5);
              if FindDTMRotated(FireAltarDTM, X, Y, MMX1, MMY1, MMX2, MMY2, -Pi/4, Pi/4, Pi/60, aFound) then
                begin
                  WriteLn('We have found the FireAltarDTM on the minimap this time');
                  MMouse(X, Y, 2, 2);
                  Wait(25 + Random(125));
                  ClickMouse2(1);
                end else
                begin
                  RadialWalkTolerance(3823718, 0, 359, 25, 5, 5, 5);
                  if FindDTMRotated(FireAltarDTM, X, Y, MMX1, MMY1, MMX2, MMY2, -Pi/4, Pi/4, Pi/60, aFound) then
                    begin
                      WriteLn('We have found the FireAltarDTM on the minimap this time');
                      MMouse(X, Y, 2, 2);
                      Wait(25 + Random(125));
                      ClickMouse2(1);
                    end else
                    begin
                      WriteLn('Something has went wrong, not able to navigate to the Fire Altar');
                    end;
                end;
            end else
            begin
              WriteLn('We have found the FireAltarDTM on the minimap');
              MMouse(X, Y, 2, 2);
              Wait(25 + Random(125));
              ClickMouse2(1);
            end;
          FreeDTM(FireAltarDTM);
        end else
        begin
          WriteLn('We can see the fire altar on our main screen!');
        end;
    end;

    procedure FindTheMindAltar;
    var
      MindAltarDTM, X, Y: Integer;
      aFound: Extended;

    begin
      if not(FindColoredAreaTolerance(X, Y, 6249310, MSX1, MSY1, MSX2, MSY2, 500, 3)) then
        begin
          MindAltarDTM := DTMFromString('mwQAAAHic42RgYGBmZ2BgB+IvbAwMbEBaFIj/AtnfgVgIyBYEYgkmBgZOIBYHYg0gFgNiLiBWBGIFIOYF4q62FobaqnK8+D/QPlYiMBMBDAcAPz4Slg==');
          if not(FindDTMRotated(MindAltarDTM, X, Y, MMX1, MMY1, MMX2, MMY2, -Pi/4, Pi/4, Pi/60, aFound)) then
            begin
              RadialWalkTolerance(9474711, 0, 359, 75, 5, 5, 5);
              if FindDTMRotated(MindAltarDTM, X, Y, MMX1, MMY1, MMX2, MMY2, -Pi/4, Pi/4, Pi/60, aFound) then
                begin
                  WriteLn('We have found the MindAltarDTM on the minimap this time');
                  MMouse(X, Y, 2, 2);
                  Wait(25 + Random(125));
                  ClickMouse2(1);
                end else
                begin
                  RadialWalkTolerance(9474711, 0, 359, 25, 5, 5, 5);
                  if FindDTMRotated(MindAltarDTM, X, Y, MMX1, MMY1, MMX2, MMY2, -Pi/4, Pi/4, Pi/60, aFound) then
                    begin
                      WriteLn('We have found the MindAltarDTM on the minimap this time');
                      MMouse(X, Y, 2, 2);
                      Wait(25 + Random(125));
                      ClickMouse2(1);
                    end else
                    begin
                      WriteLn('Something has went wrong, not able to navigate to the Mind Altar');
                    end;
                end;
            end else
            begin
              WriteLn('We have found the MindAltarDTM on the minimap');
              MMouse(X, Y, 2, 2);
              Wait(25 + Random(125));
              ClickMouse2(1);
            end;
          FreeDTM(MindAltarDTM);
        end else
        begin
          WriteLn('We can see the mind altar on our main screen!');
        end;
    end;

    procedure FindTheWaterAltar;
    var
      WaterAltarDTM, X, Y: Integer;
      aFound: Extended;

    begin
      if not(FindColoredAreaTolerance(X, Y, 6380896, MSX1, MSY1, MSX2, MSY2, 400, 4)) then
        begin
          WaterAltarDTM := DTMFromString('mwQAAAHic42RgYEhiYmBIAeJAIE4A4iIgzgfiUCAugNIGQHWyQKwLxI5ArA/EtkBsA8QqQKwExPUN6gwF2UoMJfkqDPllEJxdBOGXlKqAaRGgOi4CmIkIDAcAEVEPAw==');
          if not(FindDTMRotated(WaterAltarDTM, X, Y, MMX1, MMY1, MMX2, MMY2, -Pi/4, Pi/4, Pi/60, aFound)) then
            begin
              RadialWalkTolerance(2389615, 0, 359, 75, 5, 5, 5);
              if FindDTMRotated(WaterAltarDTM, X, Y, MMX1, MMY1, MMX2, MMY2, -Pi/4, Pi/4, Pi/60, aFound) then
                begin
                  WriteLn('We have found the WaterAltarDTM on the minimap this time');
                  MMouse(X, Y, 2, 2);
                  Wait(25 + Random(125));
                  ClickMouse2(1);
                end else
                begin
                  RadialWalkTolerance(2389615, 0, 359, 25, 5, 5, 5);
                  if FindDTMRotated(WaterAltarDTM, X, Y, MMX1, MMY1, MMX2, MMY2, -Pi/4, Pi/4, Pi/60, aFound) then
                    begin
                      WriteLn('We have found the WaterAltarDTM on the minimap this time');
                      MMouse(X, Y, 2, 2);
                      Wait(25 + Random(125));
                      ClickMouse2(1);
                    end else
                    begin
                      WriteLn('Something has went wrong, not able to navigate to the Water Altar');
                    end;
                end;
            end else
            begin
              WriteLn('We have found the WaterAltarDTM on the minimap');
              MMouse(X, Y, 2, 2);
              Wait(25 + Random(125));
              ClickMouse2(1);
            end;
          FreeDTM(WaterAltarDTM);
        end else
        begin
          WriteLn('We can see the water altar on our main screen!');
        end;
    end;

    procedure FindTheAirAltar;
    var
      AirAltarDTM, X, Y: Integer;
      aFound: Extended;

    begin
      if not(FindColoredAreaTolerance(X, Y, 5854551, MSX1, MSY1, MSX2, MSY2, 1500, 4)) then
        begin
          AirAltarDTM := DTMFromString('mwQAAAHic42RgYHjFxsDwGohvQulfQPwPiC8B8VUgZmFnYLBgYmBQA2JzIPYEYksgDgJiJSD2h9IlycoMieGyDOmx8gzJkXJg3Fvpy9Bd7g3GubHWDCJA+7gIYCYiMBwAAPJ8E1k=');
          if not(FindDTMRotated(AirAltarDTM, X, Y, MMX1, MMY1, MMX2, MMY2, -Pi/4, Pi/4, Pi/60, aFound)) then
            begin
              RadialWalkTolerance(2319220, 0, 359, 75, 5, 5, 5);
              if FindDTMRotated(AirAltarDTM, X, Y, MMX1, MMY1, MMX2, MMY2, -Pi/4, Pi/4, Pi/60, aFound) then
                begin
                  WriteLn('We have found the AirAltarDTM on the minimap this time');
                  MMouse(X, Y, 2, 2);
                  Wait(25 + Random(125));
                  ClickMouse2(1);
                end else
                begin
                  RadialWalkTolerance(2319220, 0, 359, 25, 5, 5, 5);
                  if FindDTMRotated(AirAltarDTM, X, Y, MMX1, MMY1, MMX2, MMY2, -Pi/4, Pi/4, Pi/60, aFound) then
                    begin
                      WriteLn('We have found the AirAltarDTM on the minimap this time');
                      MMouse(X, Y, 2, 2);
                      Wait(25 + Random(125));
                      ClickMouse2(1);
                    end else
                    begin
                      WriteLn('Something has went wrong, not able to navigate to the Air Altar');
                    end;
                end;
            end else
            begin
              WriteLn('We have found the AirAltarDTM on the minimap');
              MMouse(X, Y, 2, 2);
              Wait(25 + Random(125));
              ClickMouse2(1);
            end;
          FreeDTM(AirAltarDTM);
        end else
        begin
          WriteLn('We can see the air altar on our main screen!');
        end;
    end;

    procedure FindTheBodyAltar;
    var
      BodyAltarDTM, X, Y: Integer;
      aFound: Extended;

    begin
      if not(FindColoredAreaTolerance(X, Y, 6578018, MSX1, MSY1, MSX2, MSY2, 500, 4)) then
        begin
          BodyAltarDTM := DTMFromString('mwQAAAHic42RgYHjBBsHXoPQvKL4IxFehbHsmBgYNILYBYl8orQnE2lC+DxC3FJYw5MbGMZSnZjAUJyUzFCYkMTTlF4JxV1kFQ2lyKgMX0D5CmIkIDAcAfbMWsg==');
          if not(FindDTMRotated(BodyAltarDTM, X, Y, MMX1, MMY1, MMX2, MMY2, -Pi/4, Pi/4, Pi/60, aFound)) then
            begin
              RadialWalkTolerance(8223117, 0, 359, 75, 5, 5, 5);
              if FindDTMRotated(BodyAltarDTM, X, Y, MMX1, MMY1, MMX2, MMY2, -Pi/4, Pi/4, Pi/60, aFound) then
                begin
                  WriteLn('We have found the BodyAltarDTM on the minimap this time');
                  MMouse(X, Y, 2, 2);
                  Wait(25 + Random(125));
                  ClickMouse2(1);
                end else
                begin
                  RadialWalkTolerance(8223117, 0, 359, 25, 5, 5, 5);
                  if FindDTMRotated(BodyAltarDTM, X, Y, MMX1, MMY1, MMX2, MMY2, -Pi/4, Pi/4, Pi/60, aFound) then
                    begin
                      WriteLn('We have found the BodyAltarDTM on the minimap this time');
                      MMouse(X, Y, 2, 2);
                      Wait(25 + Random(125));
                      ClickMouse2(1);
                    end else
                    begin
                      WriteLn('Something has went wrong, not able to navigate to the Body Altar');
                    end;
                end;
            end else
            begin
              WriteLn('We have found the BodyAltarDTM on the minimap');
              MMouse(X, Y, 2, 2);
              Wait(25 + Random(125));
              ClickMouse2(1);
            end;
          FreeDTM(BodyAltarDTM);
        end else
        begin
          WriteLn('We can see the body altar on our main screen!');
        end;
    end;

    function MaxArray(A : array of Integer; Var Pos : integer) : integer;
    var
      i : integer;
    begin
      Result := MaxA(A);
      for i := low(A) to high(A) do
        if(Result = A[i])then
          begin
            Pos := i;
            break;
          end;
    end;

    function GetAlter: String;  //This is the function that actually returns the alter
    var
      P, i : integer;
      AlterColours, Counts : array of integer;
    begin

      AlterColours := [2450544, 2706787, 2589310, 3688535, 8487814, 7369098]
      SetArrayLength(Counts, 6);

      for i := low(Counts) to high(Counts) do
        Counts[i] := CountColorTolerance(AlterColours[i], MMCX - 30, MMCY - 30, MMCX + 30, MMCY + 30, 15);

      MaxArray(Counts, P);

      case P of
        0 : Result := Area_Air;
        1 : Result := Area_Earth;
        2 : Result := Area_Water;
        3 : Result := Area_Fire;
        4 : Result := Area_Mind;
        5 : Result := Area_Body;
      end;
    end;

    procedure Test2;
    var
    PossibleArea: Array [0..5] of String;
    i: Integer;

    begin
      PossibleArea[0]:=Area_Air;
      PossibleArea[1]:=Area_Earth;
      PossibleArea[2]:=Area_Water;
      PossibleArea[3]:=Area_Fire;
      PossibleArea[4]:=Area_Mind;
      PossibleArea[5]:=Area_Body;

      for i:= 0 to 5 do
        begin
          if GetAlter=PossibleArea[i] then
            begin
              //WriteLn('Our location is '+PossibleArea[i]+'');
              case PossibleArea[i] of
                PossibleArea[0]: begin;
                                   WriteLn('We are at the '+PossibleArea[i]+' Altar');
                                   FindTheAirAltar;
                                 end;
                PossibleArea[1]: begin;
                                   WriteLn('We are at the '+PossibleArea[i]+' Altar');
                                   FindTheEarthAltar;
                                 end;
                PossibleArea[2]: begin;
                                   WriteLn('We are at the '+PossibleArea[i]+' Altar');
                                   FindTheWaterAltar;
                                 end;
                PossibleArea[3]: begin;
                                   WriteLn('We are at the '+PossibleArea[i]+' Altar');
                                   FindTheFireAltar;
                                 end;
                PossibleArea[4]: begin;
                                   WriteLn('We are at the '+PossibleArea[i]+' Altar');
                                   FindTheMindAltar;
                                 end;
                PossibleArea[5]: begin;
                                   WriteLn('We are at the '+PossibleArea[i]+' Altar');
                                   FindTheBodyAltar;
                                 end;
              end;
            end;
        end;
    end;

    begin
      SetUpLogin;
      //FindTheAirAltar;
      //FindTheMindAltar;
      //FindTheWaterAltar;
      //FindTheEarthAltar;
      //FindTheFireAltar;
      //FindTheBodyAltar;
      GetAlter;
      Test2;
    end.

    These procedures are all functioning correctly
    Simba Code:
    //FindTheAirAltar;
      //FindTheMindAltar;
      //FindTheWaterAltar;
      //FindTheEarthAltar;
      //FindTheFireAltar;
      //FindTheBodyAltar;

    After those were working correctly I've been working on making some sort of loop to detect which altar the player is on, to start one of the above listed procedures that matches the altar where the player is. I've used two procedures that someone else has made:
    Simba Code:
    MaxArray and Getalter
    I will be rewriting those to get more accurate results, but for now it works at most of the altars (but it mixes the fire/earth one up).

    Anyways, I've also written my own array/loop to start the procedure which is
    Simba Code:
    Test2;

    I'm looking for some advice about MaxArray, GetAlter and Test2 if I can write those more efficiently. I realise this is a pretty long post but yeah..

    In short:

    Need some help/advice with the procedures/functions MaxArray, GetAlter and Test2 so I can possibly make it faster or cut down the lines.


    Video that shows what this actually does:
    www.youtube.com/watch?v=WzaLJ-4bVDg

    Script source code available here: Github

  2. #2
    Join Date
    Oct 2009
    Location
    Stockton, CA
    Posts
    2,040
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    You can write one function for finding all the altars and short it drastically. I'll show you.
    Join the IRC! irc.rizon.net:6667/srl | SQLite (0.99rc3+) | SRL Doc | Simba Doc | Extra Simba Libraries (openSSL & sqlite3)
    Quote Originally Posted by #srl
    10:45 < Toter> daphil when can get sex anyday I want
    10:45 < Toter> he is always on #SRL
    "A programmer is just a tool which converts caffeine into code"

  3. #3
    Join Date
    Dec 2011
    Location
    The Netherlands
    Posts
    1,631
    Mentioned
    47 Post(s)
    Quoted
    254 Post(s)

    Default

    Quote Originally Posted by Sex View Post
    You can write one function for finding all the altars and short it drastically. I'll show you.
    Would be great
    I think I can definately short the code, which will most likely also speed it up.

    Script source code available here: Github

  4. #4
    Join Date
    Oct 2009
    Location
    Stockton, CA
    Posts
    2,040
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    Well actually, I can't do it right now. What you would do is basically put the data of each altar in an array and then use it (colors, etc.)...this would also allow you to shorten the other functions.
    Join the IRC! irc.rizon.net:6667/srl | SQLite (0.99rc3+) | SRL Doc | Simba Doc | Extra Simba Libraries (openSSL & sqlite3)
    Quote Originally Posted by #srl
    10:45 < Toter> daphil when can get sex anyday I want
    10:45 < Toter> he is always on #SRL
    "A programmer is just a tool which converts caffeine into code"

  5. #5
    Join Date
    Dec 2011
    Location
    The Netherlands
    Posts
    1,631
    Mentioned
    47 Post(s)
    Quoted
    254 Post(s)

    Default

    Quote Originally Posted by Sex View Post
    Well actually, I can't do it right now. What you would do is basically put the data of each altar in an array and then use it (colors, etc.)...this would also allow you to shorten the other functions.
    It is in an array already
    Simba Code:
    function GetAlter: String;  //This is the function that actually returns the alter
    var
      P, i : integer;
      AlterColours, Counts : array of integer;
    begin

      AlterColours := [2450544, 2706787, 2589310, 3688535, 8487814, 7369098]
      SetArrayLength(Counts, 6);

      for i := low(Counts) to high(Counts) do
        Counts[i] := CountColorTolerance(AlterColours[i], MMCX - 30, MMCY - 30, MMCX + 30, MMCY + 30, 15);

      MaxArray(Counts, P);

      case P of
        0 : Result := Area_Air;
        1 : Result := Area_Earth;
        2 : Result := Area_Water;
        3 : Result := Area_Fire;
        4 : Result := Area_Mind;
        5 : Result := Area_Body;
      end;
    end;

    I'm not sure how I can shorten the other codes. Only thing I could do is that I would make an array for all of the walking. Eg if Area = Air_altar then .... and just make a loop for the whole walking process where an array defines which pattern it's going to take.

    Will take quite a lot of time to make and I'm not sure if it's worth it. But yeah it will look neat. Main thing I want to work on is the last three procedures that start the procedure that finds the altar.

    Script source code available here: Github

  6. #6
    Join Date
    Oct 2011
    Posts
    805
    Mentioned
    21 Post(s)
    Quoted
    152 Post(s)

    Default

    Your functions don't look slow. But if you want to cut something :
    Simba Code:
    function GetAlter: String;  //This is the function that actually returns the alter
    var
      P, i ,c, temp ,h: integer;
      AlterColours : array of integer;
    begin

      AlterColours := [2450544, 2706787, 2589310, 3688535, 8487814, 7369098]
      h := High (AlterColours);

      for i := 0 to h do
      begin
        c := CountColorTolerance(AlterColours[i], MMCX - 30, MMCY - 30, MMCX + 30, MMCY + 30, 15);
        if c > temp then
        begin
          temp := c;
          P := i;
        end;
      end;

      case P of
        0 : Result := Area_Air;
        1 : Result := Area_Earth;
        2 : Result := Area_Water;
        3 : Result := Area_Fire;
        4 : Result := Area_Mind;
        5 : Result := Area_Body;
      end;
    end;

    Also if FindTheXAltar functions are similar ,you can make one function to find all altars ,switching only input variables like colors and dtms
    Last edited by bg5; 04-26-2012 at 06:29 PM.

  7. #7
    Join Date
    Dec 2011
    Location
    The Netherlands
    Posts
    1,631
    Mentioned
    47 Post(s)
    Quoted
    254 Post(s)

    Default

    Quote Originally Posted by beginner5 View Post
    Your functions don't look slow. But if you want to cut something :
    Simba Code:
    function GetAlter: String;  //This is the function that actually returns the alter
    var
      P, i ,c, temp ,h: integer;
      AlterColours : array of integer;
    begin

      AlterColours := [2450544, 2706787, 2589310, 3688535, 8487814, 7369098]
      h := High (AlterColours);

      for i := 0 to h do
      begin
        c := CountColorTolerance(AlterColours[i], MMCX - 30, MMCY - 30, MMCX + 30, MMCY + 30, 15);
        if c > temp then
        begin
          temp := c;
          P := i;
        end;
      end;

      case P of
        0 : Result := Area_Air;
        1 : Result := Area_Earth;
        2 : Result := Area_Water;
        3 : Result := Area_Fire;
        4 : Result := Area_Mind;
        5 : Result := Area_Body;
      end;
    end;

    Also if FindTheXAltar functions are similar ,you can make one function to find all altars ,switching only input variables like colors and dtms
    Yeah the script isn't slow, but I could speed it up a little even though it's probably negligable.
    Five out of six procedures are built up the same way and one is different because the colors were too similiar. So I've made a custom SPS map for that one. I can probably make an array with results and cut down some of the code, although I think that will be something I will do after it's finished. Seems to much work for too less result, right now. Have other things I can work on.

    Thanks, though

    Script source code available here: Github

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 not post replies
  • You may not post attachments
  • You may not edit your posts
  •