Results 1 to 15 of 15

Thread: Find highest number in array

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

    Default Find highest number in array

    EDIT: Got it, thanks for the help.

    I want to know in which box the biggest amount of yellow NPC colors are found. I've split the minimap up in 9 boxes and yeah this is the code:
    Simba Code:
    procedure NPCWalk;
    var
      i: Integer;
      NPCDots: Array[0..8] of Integer;
      // North, Middle, South | North/east, East, South/east | North/west, West, South/west
    begin
      // NPC WALKING
      SMART_ClearCanvas;
      SMART_DrawBoxEx(False, IntToBox(MMCX-25, MMCY-75, MMCX+25, MMCY-25), clRed); // 0
      SMART_DrawBoxEx(False, IntToBox(MMCX-25, MMCY-25, MMCX+25, MMCY+25), clRed); // 1
      SMART_DrawBoxEx(False, IntToBox(MMCX-25, MMCY+25, MMCX+25, MMCY+75), clRed); // 2
      SMART_DrawBoxEx(False, IntToBox(MMCX+25, MMCY-75, MMCX+75, MMCY-25), clRed); // 3
      SMART_DrawBoxEx(False, IntToBox(MMCX+25, MMCY-25, MMCX+75, MMCY+25), clRed); // 4
      SMART_DrawBoxEx(False, IntToBox(MMCX+25, MMCY+25, MMCX+75, MMCY+75), clRed); // 5
      SMART_DrawBoxEx(False, IntToBox(MMCX-75, MMCY+25, MMCX-25, MMCY+75), clRed); // 6
      SMART_DrawBoxEx(False, IntToBox(MMCX-75, MMCY-25, MMCX-25, MMCY+25), clRed); // 7
      SMART_DrawBoxEx(False, IntToBox(MMCX-75, MMCY-75, MMCX-25, MMCY-25), clRed); // 8

      ColorToleranceSpeed(1);
      NPCDots[0] := CountColorTolerance(645100, MMCX-25, MMCY-75, MMCX+25, MMCY-25, 35);
      NPCDots[1] := CountColorTolerance(645100, MMCX-25, MMCY-25, MMCX+25, MMCY+25, 35);
      NPCDots[2] := CountColorTolerance(645100, MMCX-25, MMCY+25, MMCX+25, MMCY+75, 35);
      NPCDots[3] := CountColorTolerance(645100, MMCX+25, MMCY-75, MMCX+75, MMCY-25, 35);
      NPCDots[4] := CountColorTolerance(645100, MMCX+25, MMCY-25, MMCX+75, MMCY+25, 35);
      NPCDots[5] := CountColorTolerance(645100, MMCX+25, MMCY+25, MMCX+75, MMCY+75, 35);
      NPCDots[6] := CountColorTolerance(645100, MMCX-75, MMCY+25, MMCX-25, MMCY+75, 35);
      NPCDots[7] := CountColorTolerance(645100, MMCX-75, MMCY-25, MMCX-25, MMCY+25, 35);
      NPCDots[8] := CountColorTolerance(645100, MMCX-75, MMCY-75, MMCX-25, MMCY-25, 35);

      for i:=0 to 8 do
        WriteLn(''+IntToStr(NPCDots[i])+'');
    end;

    It's probably extremely easy but yeah. How do I find the highest integer in this array? High(NPCDots) gives 8 because it is [0..8]
    Last edited by J J; 05-21-2012 at 07:19 PM.

    Script source code available here: Github

  2. #2
    Join Date
    Jan 2008
    Location
    C:\
    Posts
    1,483
    Mentioned
    2 Post(s)
    Quoted
    2 Post(s)

    Default

    Try this:

    Simba Code:
    for i := 1 to 8 do
    begin
      Highest := NPCDots[0];
      if (NPCDots[i] > Highest) then
        Highest := NPCDots[i];
    end;

    Haven't tested it, but it makes sense

    EDIT: Also, use a really high tolerance. I used NPC dots for walking in my miner and the NPC dot colors change wildy. They can go from 59xxx -> 21xxxxx.
    Last edited by Runaway; 05-21-2012 at 07:09 PM.

  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 Runaway View Post
    Try this:

    Simba Code:
    for i := 1 to 8 do
    begin
      Highest := NPCDots[0];
      if (NPCDots[i] > Highest) then
        Highest := NPCDots[i];
    end;

    Haven't tested it, but it makes sense
    Hm thanks will test
    Also rewrote mine to an array so yeah

    Simba Code:
    procedure NPCWalk;
    var
      i: Integer;
      NPCDots: Array[0..8] of Integer;
      X1, Y1, X2, Y2: Array of Integer;

    begin
      // North, Middle, South | North/east, East, South/east | North/west, West, South/west
      X1 := [-25, -25, -25, 25, 25, 25, -75, -75, -75];
      Y1 := [-75, -25, 25, -75, -25, 25, 25, -25, -75];
      X2 := [25, 25, 25, 75, 75, 75, -25, -25, -25];
      Y2 := [-25, 25, 75, -25, 25, 75, 75, 25, -25];

      ColorToleranceSpeed(1);
      SMART_ClearCanvas;
      for i:=0 to 8 do
        begin
          SMART_DrawBoxEx(False, IntToBox(MMCX+X1[i], MMCY+Y1[i], MMCX+X2[i], MMCY+Y2[i]), clRed); // 0
          NPCDots[i] := CountColorTolerance(645100, MMCX+X1[i], MMCY+Y1[i], MMCX+X2[i], MMCY+Y2[i], 35);
          WriteLn(''+IntToStr(NPCDots[i])+'');
        end;
    end;

    Will edit it now :P

    EDIT: your idea will output the highest number of colors found. That way I still don't know in which box it finds the highest number of colors, but it helped anyway. Trying to figure it out now.

    EDIT 2: By simply declaring HighestBox as i it will work

    Simba Code:
    function NPCWalk: String;
    var
      i, Highest, HighestBox: Integer;
      NPCDots: Array[0..8] of Integer;
      X1, Y1, X2, Y2: Array of Integer;

    begin
      // North, Middle, South | North/east, East, South/east | North/west, West, South/west
      X1 := [-25, -25, -25, 25, 25, 25, -75, -75, -75];
      Y1 := [-75, -25, 25, -75, -25, 25, 25, -25, -75];
      X2 := [25, 25, 25, 75, 75, 75, -25, -25, -25];
      Y2 := [-25, 25, 75, -25, 25, 75, 75, 25, -25];

      ColorToleranceSpeed(1);
      SMART_ClearCanvas;
      Highest:=0;
      for i:=0 to 8 do
        begin
          SMART_DrawBoxEx(False, IntToBox(MMCX+X1[i], MMCY+Y1[i], MMCX+X2[i], MMCY+Y2[i]), clRed); // 0
          NPCDots[i] := CountColorTolerance(645100, MMCX+X1[i], MMCY+Y1[i], MMCX+X2[i], MMCY+Y2[i], 35);
          if (NPCDots[i] > Highest) then
            begin
              Highest := NPCDots[i];
              HighestBox := i;
            end;
        end;
      case i of
        0: Result := 'North';
        1: Result := 'Middle';
        2: Result := 'South';
        3: Result := 'NorthEast';
        4: Result := 'East';
        5: Result := 'SouthEast';
        6: Result := 'NorthWest';
        7: Result := 'West';
        8: Result := 'SouthWest';
      end;
    end;

    Thanks, +rep
    EDIT3: You must spread some Reputation around before giving it to Runaway again
    Hm, I guess you were the last person I gave rep for your TPACluster.

    EDIT4: Might aswell rewrite the results to an array
    Simba Code:
    function NPCWalk: String;
    var
      i, Highest, HighestBox: Integer;
      NPCDots: Array[0..8] of Integer;
      X1, Y1, X2, Y2: Array of Integer;
      PossibleResults: Array of String;

    begin
      // North, Middle, South | North/east, East, South/east | North/west, West, South/west
      PossibleResults := ['North', 'Middle', 'South', 'NorthEast', 'East', 'SouthEast', 'NorthWest', 'West', 'SouthWest'];
      X1 := [-25, -25, -25, 25, 25, 25, -75, -75, -75];
      Y1 := [-75, -25, 25, -75, -25, 25, 25, -25, -75];
      X2 := [25, 25, 25, 75, 75, 75, -25, -25, -25];
      Y2 := [-25, 25, 75, -25, 25, 75, 75, 25, -25];

      ColorToleranceSpeed(1);
      SMART_ClearCanvas;
      Highest:=0;
      for i:=0 to 8 do
        begin
          SMART_DrawBoxEx(False, IntToBox(MMCX+X1[i], MMCY+Y1[i], MMCX+X2[i], MMCY+Y2[i]), clRed); // 0
          NPCDots[i] := CountColorTolerance(645100, MMCX+X1[i], MMCY+Y1[i], MMCX+X2[i], MMCY+Y2[i], 35);
          if (NPCDots[i] > Highest) then
            begin
              Highest := NPCDots[i];
              HighestBox := i;
            end;
        end;
      Result := PossibleResults[HighestBox];
    end;

    Anyways, thanks.
    Last edited by J J; 05-21-2012 at 07:24 PM.

    Script source code available here: Github

  4. #4
    Join Date
    Jan 2008
    Location
    C:\
    Posts
    1,483
    Mentioned
    2 Post(s)
    Quoted
    2 Post(s)

    Default

    Of course

    Simba Code:
    var
      Highest: array[0..1] of Integer;
    ...

    for i := 0 to 8 do
    begin
      if (i = 0) then
      begin
        Highest[0] := NPCDots[i];
        Highest[1] := i;
        Continue;
      end;
      if (NPCDots[i] > Highest[0]) then
      begin
        Highest[0] := NPCDots[i];
        Highest[1] := i;
      end;
    end;

    EDIT: aww you ninja'd me
    Last edited by Runaway; 05-21-2012 at 07:26 PM.

  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 Runaway View Post
    Of course

    Simba Code:
    var
      Highest: array[0..1] of Integer;
    ...

    DONT LOOK
    IM SILLY

    EDIT: aww you ninja'd me
    Haha sorry :P I saw your post before you edited it though and that would spare out one line to declare on top. But that might be getting a bit extreme with all the different arrays lol

    EDIT: Nvm it doesn't save a line because I already have integers declared so it's a line extra anyways, either Highest: Array[0..1] of Integer or declaring another integer. It's actually a line less but still the same amount of variables.. Oh nvm you can delete Highest as an integer then so it would save 1 variable.

    Script source code available here: Github

  6. #6
    Join Date
    Jan 2008
    Location
    C:\
    Posts
    1,483
    Mentioned
    2 Post(s)
    Quoted
    2 Post(s)

    Default

    Quote Originally Posted by J J View Post
    Haha sorry :P I saw your post before you edited it though and that would spare out one line to declare on top. But that might be getting a bit extreme with all the different arrays lol
    Extreme? Bah, just wait til you see my latest function...

    Simba Code:
    var
      ClanToMine: array[0..3] of array[0..1] of array of Integer;
      DungToBank: array[0..1] of array[0..1] of array of Integer;
      MineToSpot: array[0..1] of array of Integer;

    ^ will look like mild array usage

  7. #7
    Join Date
    Feb 2006
    Location
    Helsinki, Finland
    Posts
    1,395
    Mentioned
    30 Post(s)
    Quoted
    107 Post(s)

    Default

    Simba has function for this - MaxA(a: TIntegerArray): Integer;

    Also, there is MinA(a: TIntegerArray): Integer; for getting the smallest value.

    Ahh, you are using array[0..8] of Integer. Wont work for those, sadly. :\

  8. #8
    Join Date
    Oct 2008
    Location
    C:\Simba\Includes\
    Posts
    7,566
    Mentioned
    19 Post(s)
    Quoted
    180 Post(s)

    Default

    Wouldn't something like this be a lot easier?

    Simba Code:
    program new;
    {$i srl/srl.simba}

    var
      NPCDots : array[0..8] of Integer;
      tmpArr : TIntegerArray;
      i : Integer;

    begin
      setupsrl;
      ClearDebug;

      for i := 0 to 7 do
        NPCDots[i] := Random(9); // Adds random values for now, can make it anything

      for i := 0 to High(NPCDots) do
        WriteLn(NPCDots[i]); // Writes the current order

      SetLength(tmpArr, Length(NPCDots)); // Sets the tmpArr length
      tmpArr := NPCDots; // Sets the tmpArr values to NPCDots

      Quicksort(tmpArr); // Sorts the TIA, from lowest to highest
      InvertTIA(tmpArr); // Inverts the TIA, so it's highest to lowest

      WriteLn('=============');

      for i := 0 to High(tmpArr) do
        WriteLn(tmpArr[i]); // Prints out the new order

      WriteLn('Highest # in array is: ' + IntToStr(tmpArr[0]));
    end.
    Away for awhile, life is keeping me busy. | Want to get my attention in a thread? @Kyle Undefined; me.
    { MSI Phoenix || SRL Stats Sigs || Paste || Scripts || Quotes || Graphics }

    When posting a bug, please post debug! Help us, help you!

    I would love to change the world, but they won't give me the source code. || To be the best, you've got to beat the rest. || Logic never changes, just the syntax.
    If you PM me with a stupid question or one listed in FAQ, or about a script that is not mine, I will NOT respond.


    SRL is a Library of routines made by the SRL community written for the Program Simba. We produce Scripts for the game Runescape.


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

    Default

    @ Kyle that doesn't count the amount of NPC's in each box though? What I wanted to do is to count the amount of NPC colors (or dots..) in 9 different boxes. When I know in what box the most NPC colors/dots are found I can let my character walk there. It's useful for many things and especially for fighting monsters or even things such as walking throught the Abyss.



    Added a mousecircle click & mousecircle draw.
    It clicks somewhere randomly in the circle and the circle is where the most NPC's are found.
    At first I wanted to use a mousebox but north/west, north/east, south/east and south/west you will run into some problems are half of the box isn't clickable. So I calculated the middle of the points and draw a circle small enough to make it clickable from every spot.

    Simba Code:
    function NPCWalk: String;
    var
      i, Highest, HighestBox: Integer;
      NPCDots: Array[0..8] of Integer;
      X1, Y1, X2, Y2: Array of Integer;
      PossibleResults: Array of String;

    begin
      PossibleResults := ['North', 'South', 'NorthEast', 'East', 'SouthEast', 'NorthWest', 'West', 'SouthWest'];
      X1 := [-25, -25, 25, 25, 25, -75, -75, -75];
      Y1 := [-75, 25, -75, -25, 25, 25, -25, -75];
      X2 := [25, 25, 75, 75, 75, -25, -25, -25];
      Y2 := [-25, 75, -25, 25, 75, 75, 25, -25];

      ColorToleranceSpeed(1);
      SMART_ClearCanvas;
      Highest:=0;
      for i:=0 to 7 do
        begin
          SMART_DrawBoxEx(False, IntToBox(MMCX+X1[i], MMCY+Y1[i], MMCX+X2[i], MMCY+Y2[i]), clRed);
          NPCDots[i] := CountColorTolerance(645100, MMCX+X1[i], MMCY+Y1[i], MMCX+X2[i], MMCY+Y2[i], 35);
          if (NPCDots[i] > Highest) then
            begin
              Highest := NPCDots[i];
              HighestBox := i;
            end;
        end;
      WriteLn(''+IntToStr(HighestBox)+'');
      SMART_DrawCircle(False, Point(((MMCX+X1[HighestBox]+MMCX+X2[HighestBox])/2), ((MMCY+Y1[HighestBox]+MMCY+Y2[HighestBox])/2)), 5, True, clRed);
      MouseCircle(((MMCX+X1[HighestBox]+MMCX+X2[HighestBox])/2), ((MMCY+Y1[HighestBox]+MMCY+Y2[HighestBox])/2), 5, 1);
      Result := PossibleResults[HighestBox];
    end;

    Script source code available here: Github

  10. #10
    Join Date
    Oct 2008
    Location
    C:\Simba\Includes\
    Posts
    7,566
    Mentioned
    19 Post(s)
    Quoted
    180 Post(s)

    Default

    I know, it was an example of getting the highest number from the array. Much easier than looping through them to find the highest one.
    Away for awhile, life is keeping me busy. | Want to get my attention in a thread? @Kyle Undefined; me.
    { MSI Phoenix || SRL Stats Sigs || Paste || Scripts || Quotes || Graphics }

    When posting a bug, please post debug! Help us, help you!

    I would love to change the world, but they won't give me the source code. || To be the best, you've got to beat the rest. || Logic never changes, just the syntax.
    If you PM me with a stupid question or one listed in FAQ, or about a script that is not mine, I will NOT respond.


    SRL is a Library of routines made by the SRL community written for the Program Simba. We produce Scripts for the game Runescape.


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

    Default

    You may find this link helpful.

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

    Default

    Quote Originally Posted by Kyle Undefined View Post
    I know, it was an example of getting the highest number from the array. Much easier than looping through them to find the highest one.
    Hm I see. Quicksort & InvertTIA might come in handy in the future hehe :P

    Thanks all,

    EDIT: Damn I have edited every post now?
    @ NCDS, I'll check it out, looks interesting.

    Script source code available here: Github

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

    Default

    Basically ,if you use static arrays you exclude use of most simba function ,which work only with dynamic arrays.

    I would make in in another way :

    Simba Code:
    function SplitBox (Box : Tbox ; row ,col : integer) : array of TBox;
    var
    a ,l,w,h :integer;

    begin
      l := row*col;
      w := (Box.x2-Box.x1)/col;
      h := (Box.y2-box.y1)/row;

      SetLength(Result,l);
      for a:= 0 to l-1 do
      begin
        Result[a].x1 := Box.x1 + w * (a mod col);
        Result[a].x2 :=  Result[a].x1 + w;
        Result[a].y1 := Box.y1 + h * (a div col);
        Result[a].y2 :=  Result[a].y1 + h;
      end;
    end;

    var
    NPCDots :TintegerArray;
    BA : array of TBox;
    a ,l ,max: integer;
    begin
      BA := SplitBox(IntToBox(MMX1,MMY1,MMX2,MMY2),3,3);
      l := length(BA);
      SetLength(NPCdots,l);
      for a:=0 to l-1 do
          NPCDots[a] := CountColorTolerance(645100, ba[a].x1 , ba[a].y1, ba[a].x2, ba[a].y2, 35);

      max := maxA(NPCdots);
      for a:= 0 to l-1 do
        if ( NPCdots[a] = max ) then break;

      writeln('Most monsters in box number : ' + tostr (a) );
    end;

    You can also change resolution in SplitBox

    E :I forgot about debug:
    Simba Code:
    SMART_DrawBoxes(FALSE,BA ,clred);
    Last edited by bg5; 05-21-2012 at 10:39 PM.

  14. #14
    Join Date
    Dec 2011
    Location
    Toronto, Ontario
    Posts
    6,424
    Mentioned
    84 Post(s)
    Quoted
    863 Post(s)

    Default

    You working on a Abyss Crafter?

  15. #15
    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
    Basically ,if you use static arrays you exclude use of most simba function ,which work only with dynamic arrays.

    I would make in in another way :

    Simba Code:
    function SplitBox (Box : Tbox ; row ,col : integer) : array of TBox;
    var
    a ,l,w,h :integer;

    begin
      l := row*col;
      w := (Box.x2-Box.x1)/col;
      h := (Box.y2-box.y1)/row;

      SetLength(Result,l);
      for a:= 0 to l-1 do
      begin
        Result[a].x1 := Box.x1 + w * (a mod col);
        Result[a].x2 :=  Result[a].x1 + w;
        Result[a].y1 := Box.y1 + h * (a div col);
        Result[a].y2 :=  Result[a].y1 + h;
      end;
    end;

    var
    NPCDots :TintegerArray;
    BA : array of TBox;
    a ,l ,max: integer;
    begin
      BA := SplitBox(IntToBox(MMX1,MMY1,MMX2,MMY2),3,3);
      l := length(BA);
      SetLength(NPCdots,l);
      for a:=0 to l-1 do
          NPCDots[a] := CountColorTolerance(645100, ba[a].x1 , ba[a].y1, ba[a].x2, ba[a].y2, 35);

      max := maxA(NPCdots);
      for a:= 0 to l-1 do
        if ( NPCdots[a] = max ) then break;

      writeln('Most monsters in box number : ' + tostr (a) );
    end;

    You can also change resolution in SplitBox

    E :I forgot about debug:
    Simba Code:
    SMART_DrawBoxes(FALSE,BA ,clred);
    Thanks, I'll check this out aswell :P

    Quote Originally Posted by Sin View Post
    You working on a Abyss Crafter?
    No, that was just an example of where it could be used. One of the first things that came to my mind. I'm thinking about making one though but I'm kind of fed up with runecrafting right now haha. Also tested it at some other locations, it's pretty useful for a fighting script. Or possibly even my great orb project script :P

    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)

Posting Permissions

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