Results 1 to 6 of 6

Thread: Need some array help

  1. #1
    Join Date
    Mar 2007
    Location
    Mars, I thought all men were from Mars.
    Posts
    513
    Mentioned
    7 Post(s)
    Quoted
    124 Post(s)

    Default Need some array help

    I'm having a problem with setting a box array length and storing only valid cords.

    if you take a look at the output below, under the red text, you will see...
    Simba Code:
    Converted MS Point 0 := (-1, -1)
    Converted MS Point 1 := (-1, -1)
    Converted MS Point 2 := (-1, -1)
    Converted MS Point 3 := (-1, -1)
    Those are invalid points I need to remove before I try making boxes out of them. Then I will have to set the Abox length. For the Example output below I want the ending results to look like this...
    Simba Code:
    Find Colors 0 in  box (156, 4, 236, 61)
    Find Colors 1 in  box (189, 6, 269, 86)
    Find Colors 2 in  box (117, 27, 197, 107)
    Find Colors 3 in  box (262, 96, 342, 176)
    Find Colors 4 in  box (168, 236, 248, 260)
    not like it is now...
    Simba Code:
    Find Colors 0 in  box (156, 4, 236, 61)
    Find Colors 1 in  box (189, 6, 269, 86)
    Find Colors 2 in  box (117, 27, 197, 107)
    Find Colors 3 in  box (262, 96, 342, 176)
    Find Colors 4 in  box (168, 236, 248, 260)
    Find Colors 5 in  box (0, 0, 0, 0)
    Find Colors 6 in  box (0, 0, 0, 0)
    Find Colors 7 in  box (0, 0, 0, 0)
    Find Colors 8 in  box (0, 0, 0, 0)

    I have a hard time explaining things so let me know if you need further detail of what I'm trying to accomplish.



    The the output of the script below
    Simba Code:
    Number of Player dots found: 8
    MM Point 0 := (604, 38)
    MM Point 1 := (616, 50)
    MM Point 2 := (612, 54)
    MM Point 3 := (619, 58)
    MM Point 4 := (619, 66)
    MM Point 5 := (623, 70)
    MM Point 6 := (615, 73)
    MM Point 7 := (631, 82)
    MM Point 8 := (622, 97)
    Converted MS Point 0 := (-1, -1)
    Converted MS Point 1 := (-1, -1)
    Converted MS Point 2 := (-1, -1)
    Converted MS Point 3 := (-1, -1)
    Converted MS Point 4 := (196, 21)
    Converted MS Point 5 := (229, 46)
    Converted MS Point 6 := (157, 67)
    Converted MS Point 7 := (302, 136)
    Converted MS Point 8 := (208, 276)
    MS Point out of bounds: (-1, -1)
    MS Point out of bounds: (-1, -1)
    MS Point out of bounds: (-1, -1)
    MS Point out of bounds: (-1, -1)
    Find Colors 0 in  box (156, 4, 236, 61)
    Find Colors 1 in  box (189, 6, 269, 86)
    Find Colors 2 in  box (117, 27, 197, 107)
    Find Colors 3 in  box (262, 96, 342, 176)
    Find Colors 4 in  box (168, 236, 248, 260)
    Find Colors 5 in  box (0, 0, 0, 0)
    Find Colors 6 in  box (0, 0, 0, 0)
    Find Colors 7 in  box (0, 0, 0, 0)
    Find Colors 8 in  box (0, 0, 0, 0)


    The Script I am using. This is a striped down ver of the original function.
    Simba Code:
    program new;
    {$DEFINE SMART8}
    {$I SRL/SRL.Simba}
    {$IFDEF SIMBAMAJOR980}
      {$I SRL/SRL/Misc/PaintSmart.Simba}
    {$ELSE}
      {$I SRL/SRL/Misc/SmartGraphics.Simba}
    {$ENDIF}

    function AttackPlayer: Boolean;
    Var
      x, y, i, L, c, tmpCTS: Integer;
      TP: TPoint;
      TPA, TempTPA, TTPA, MMTPA: TPointArray;
      ATPA: T2DPointArray;
      Box: TBox;
      ABox: TBoxArray;
    Begin
      Result := False;
      MMTPA := GetMiniMapDots('w');
      L := High(MMTPA);
      SetArrayLength(ABox, L + 1);

      writeln('Number of Player dots found: ' + ToStr(L));
      for i := 0 to L do
      begin
        Writeln('MM Point ' + ToStr(i) + ' := ' + ToStr(MMTPA[i]));
      end;

      for i := 0 to L do
      begin
        Writeln('Converted MS Point ' + ToStr(i) + ' := ' + ToStr(MMtoMS(MMTPA[i])));
      end;

      //keeps boxes in Main Screen range
      c := 0;
      for i := 0 to L do
      begin
        TP := MMtoMS(MMTPA[i]); // Gets Main Screen Point from MM Point

        // if TPoint is off main screen I need to remove one array length from ABox
        if (TP.x < 0) or (TP.x < 0) then
        begin
        writeln('MS Point out of bounds: ' + ToStr(TP));
        //Dec(DCount); //Couldn't get this way to work
        //SetArrayLength(ABox, DCount);
        end else
        begin
          // if box cord out of bounds, changes it to edge of main screen
          if ((TP.x - 40) < MSX1) then
            ABox[c].x1 := MSX1
          else ABox[c].x1 := TP.x - 40;
          if ((TP.x + 40) > MSX2) then
            ABox[c].x2 := MSX2
          else ABox[c].x2 := TP.x + 40;
          if ((TP.y - 40) < MSY1) then
            ABox[c].y1 := MSY1
          else ABox[c].y1 := TP.y - 40;
          if ((TP.y + 40) > 260) then
            ABox[c].y2 := 260
          else ABox[c].y2 := TP.y + 40;
          Inc(c);
        end;
      end;
      SMART_DrawBoxes(False, False, ABox, clRed);
      for i := 0 to L do
      begin
        writeln('Find Colors ' + ToStr(i) + ' in  box ' + ToStr(ABox[i]));
      end;

    end;

    begin
    ClearDebug;
    AttackPlayer;
    end.
    Not scripting for RS anymore, sorry. Banned too many times.
    MY SCRIPTS

  2. #2
    Join Date
    Jan 2009
    Location
    Turlock/LA, California
    Posts
    1,494
    Mentioned
    3 Post(s)
    Quoted
    66 Post(s)

    Default

    ok, sorta read this quickly but this is what i think ur saying:

    1. u gather mm point in a TPA.
    2. you convert MM point to MS points
    3. you store MS point in seperate(?) TPA.
    4. all of this is in a loop of some sort.

    what i would do:

    1. - same -
    2. - same -

    3.
    - Create tpa of length 0
    - Check if MS.x>0 && MS.y>0
    - If so, increment length of tpa by 1. Then store the tpa(high).x/y values as the MS values.

    4. - same -



    is that what you were looking for?

  3. #3
    Join Date
    Mar 2007
    Location
    Mars, I thought all men were from Mars.
    Posts
    513
    Mentioned
    7 Post(s)
    Quoted
    124 Post(s)

    Default

    EDIT Think I finaly Figured it out...
    Simba Code:
    function AttackPlayer: Boolean;
    Var
      x, y, i, L, c, c2, tmpCTS: Integer;
      TP: TPoint;
      TPA, TempTPA, TTPA, MMTPA: TPointArray;
      ATPA: T2DPointArray;
      Box: TBox;
      ABox: TBoxArray;
    Begin
      Result := False;
      MMTPA := GetMiniMapDots('w');
      L := High(MMTPA) + 1;
      SetArrayLength(ABox, L);

      writeln('Number of Player dots found: ' + ToStr(L));
      for i := 0 to High(MMTPA) do
      begin
        Writeln('MM Point ' + ToStr(i) + ' := ' + ToStr(MMTPA[i]));
      end;

      for i := 0 to High(MMTPA) do
      begin
        Writeln('Converted MS Point ' + ToStr(i) + ' := ' + ToStr(MMtoMS(MMTPA[i])));
      end;

      //keeps boxes in Main Screen range
      c := 0;
      for i := 0 to High(MMTPA) do
      begin
        TP := MMtoMS(MMTPA[i]); // Gets Main Screen Point from MM Point

        // if TPoint is off main screen I need to remove one array length from ABox
        if (TP.x < 0) or (TP.x < 0) then
        begin
        writeln('MS Point out of bounds: ' + ToStr(TP));
        Dec(L); //Couldn't get this way to work
        SetArrayLength(ABox, L);
        end else
        begin
          // if box cord out of bounds, changes it to edge of main screen
          if ((TP.x - 40) < MSX1) then
            ABox[c].x1 := MSX1
          else ABox[c].x1 := TP.x - 40;
          if ((TP.x + 40) > MSX2) then
            ABox[c].x2 := MSX2
          else ABox[c].x2 := TP.x + 40;
          if ((TP.y - 40) < MSY1) then
            ABox[c].y1 := MSY1
          else ABox[c].y1 := TP.y - 40;
          if ((TP.y + 40) > 260) then
            ABox[c].y2 := 260
          else ABox[c].y2 := TP.y + 40;
          writeln(ToStr(c) + ' TP ' + ToStr(TP) + ' := ' + ToStr(ABox[c]));
          Inc(c);

        end;
      end;
      //SMART_DrawBoxes(False, False, ABox, clRed);
      for i := 0 to L - 1 do
      begin
        writeln('Find Colors ' + ToStr(i) + ' in  box ' + ToStr(ABox[i]));
      end;

    end;






    Quote Originally Posted by x[Warrior]x3500 View Post
    ok, sorta read this quickly but this is what i think ur saying:

    1. u gather mm point in a TPA.
    2. you convert MM point to MS points
    3. you store MS point in seperate(?) TPA.
    4. all of this is in a loop of some sort.

    what i would do:

    1. - same -
    2. - same -

    3.
    - Create tpa of length 0
    - Check if MS.x>0 && MS.y>0
    - If so, increment length of tpa by 1. Then store the tpa(high).x/y values as the MS values.

    4. - same -



    is that what you were looking for?
    Sry no, That is exactly what I already tried, just backwards. I set the length to my already known TPA length and decrease it every time "MS.x>0 && MS.y>0".
    Simba Code:
    // if TPoint is off main screen I need to remove one array length from ABox
        if (TP.x < 0) or (TP.x < 0) then
        begin
        writeln('MS Point out of bounds: ' + ToStr(TP));
        Dec(L); //Couldn't get this way to work
        SetArrayLength(ABox, L);
        end

    When I do this I get weird reults and can't figure out why.

    Here is my results trying it.
    Simba Code:
    Number of Player dots found: 5
    MM Point 0 := (566, 40)
    MM Point 1 := (566, 44)
    MM Point 2 := (622, 74)
    MM Point 3 := (622, 78)
    MM Point 4 := (630, 78)
    MM Point 5 := (634, 81)
    Converted MS Point 0 := (-1, -1)
    Converted MS Point 1 := (-1, -1)
    Converted MS Point 2 := (219, 74)
    Converted MS Point 3 := (217, 104)
    Converted MS Point 4 := (291, 104)
    Converted MS Point 5 := (330, 128)
    MS Point out of bounds: (-1, -1)
    MS Point out of bounds: (-1, -1)
    0 TP (219, 74) := (179, 34, 259, 114)
    1 TP (217, 104) := (177, 64, 257, 144)
    Find Colors 0 in  box (179, 34, 259, 114)
    Find Colors 1 in  box (177, 64, 257, 144)
    Find Colors 2 in  box (0, 0, 0, 0)

    From the 6 converted pts 4 are valid points I want to keep. But the end results is...
    Simba Code:
    Find Colors 0 in  box (179, 34, 259, 114)
    Find Colors 1 in  box (177, 64, 257, 144)
    Find Colors 2 in  box (0, 0, 0, 0)
    That is only 3 results and 1 is invalid.

    I know the concept, I'm am doing something wrong in my code.

    Heres the script I used with above results
    Simba Code:
    program new;
    {$DEFINE SMART8}
    {$I SRL/SRL.Simba}
    {$IFDEF SIMBAMAJOR980}
      {$I SRL/SRL/Misc/PaintSmart.Simba}
    {$ELSE}
      {$I SRL/SRL/Misc/SmartGraphics.Simba}
    {$ENDIF}

    function AttackPlayer: Boolean;
    Var
      x, y, i, L, c, c2, tmpCTS: Integer;
      TP: TPoint;
      TPA, TempTPA, TTPA, MMTPA: TPointArray;
      ATPA: T2DPointArray;
      Box: TBox;
      ABox: TBoxArray;
    Begin
      Result := False;
      MMTPA := GetMiniMapDots('w');
      L := High(MMTPA);
      SetArrayLength(ABox, L);

      writeln('Number of Player dots found: ' + ToStr(L));
      for i := 0 to L do
      begin
        Writeln('MM Point ' + ToStr(i) + ' := ' + ToStr(MMTPA[i]));
      end;

      for i := 0 to L do
      begin
        Writeln('Converted MS Point ' + ToStr(i) + ' := ' + ToStr(MMtoMS(MMTPA[i])));
      end;

      //keeps boxes in Main Screen range
      c := 0;
      for i := 0 to L do
      begin
        TP := MMtoMS(MMTPA[i]); // Gets Main Screen Point from MM Point

        // if TPoint is off main screen I need to remove one array length from ABox
        if (TP.x < 0) or (TP.x < 0) then
        begin
        writeln('MS Point out of bounds: ' + ToStr(TP));
        Dec(L); //Couldn't get this way to work
        SetArrayLength(ABox, L);
        end else
        begin
          // if box cord out of bounds, changes it to edge of main screen
          if ((TP.x - 40) < MSX1) then
            ABox[c].x1 := MSX1
          else ABox[c].x1 := TP.x - 40;
          if ((TP.x + 40) > MSX2) then
            ABox[c].x2 := MSX2
          else ABox[c].x2 := TP.x + 40;
          if ((TP.y - 40) < MSY1) then
            ABox[c].y1 := MSY1
          else ABox[c].y1 := TP.y - 40;
          if ((TP.y + 40) > 260) then
            ABox[c].y2 := 260
          else ABox[c].y2 := TP.y + 40;
          writeln(ToStr(c) + ' TP ' + ToStr(TP) + ' := ' + ToStr(ABox[c]));
          Inc(c);

        end;
      end;
      //SMART_DrawBoxes(False, False, ABox, clRed);
      for i := 0 to L - 1 do
      begin
        writeln('Find Colors ' + ToStr(i) + ' in  box ' + ToStr(ABox[i]));
      end;

    end;
    var
      TP: TPoint;

    begin
    ClearDebug;

    MMouse(MMCX,MMCY,0,0);
    GetMousePos(TP.x,TP.y);
    writeln(ToStr(TP));
    //AttackPlayer;
    end.
    Last edited by bud_wis_er_420; 05-30-2013 at 08:12 PM.
    Not scripting for RS anymore, sorry. Banned too many times.
    MY SCRIPTS

  4. #4
    Join Date
    Dec 2007
    Posts
    2,112
    Mentioned
    71 Post(s)
    Quoted
    580 Post(s)

    Default

    Simba Code:
    function AttackPlayers2 : Boolean;
    var
      WhiteDots : TPointArray;
      MSBoxes : TBoxArray;
      TempTBA : TBooleanArray;
      I, C : Integer;
    begin
      WhiteDots := GetMiniMapDots('w');
      SetLength(TempTBA, Length(WhiteDots));
      C := 0;
      for I := 0 to High(WhiteDots) do
      begin
        WhiteDots[I] := MMtoMS(WhiteDots[I]);
        TempTBA[I] := (WhiteDots[I].x > -1);
        if TempTBA[I] then
          inc(C);
      end;
      SetLength(MSBoxes, C);
      C := 0;
      for I := 0 to High(TempTBA) do
      begin
        if (TempTBA[I]) then
        begin
          MSBoxes[C] := IntToBox(WhiteDots[I].x - 40, WhiteDots[I].y - 40, WhiteDots[I].x + 40, WhiteDots[I].y + 40);
          if Not PointInBox(Point(MSBoxes[C].X1, MSBoxes[C].Y1), MSBox) then
            case (MSBoxes[C].X1 < 0) of
              True : MSBoxes[C].X1 := MSX1;
              False : MSBoxes[C].Y1 := MSY1;
            end;
          if Not PointInBox(Point(MSBoxes[C].X2, MSBoxes[C].Y2), MSBox) then
            case (MSBoxes[C].X1 < 0) of
              True : MSBoxes[C].X2 := MSX2;
              False : MSBoxes[C].Y2 := MSY2;
            end;
          inc(C);
          Writeln(MSBoxes[C - 1]);
        end;
      end;
      SMART_DrawBoxes(False, False, MSBoxes, clRed);
      Result := (Length(MSBoxes) > 0);
    end;

    Try that.

    Edit : fixed out of range errors..
    Last edited by Kasi; 05-30-2013 at 08:34 PM.

  5. #5
    Join Date
    Mar 2007
    Location
    Mars, I thought all men were from Mars.
    Posts
    513
    Mentioned
    7 Post(s)
    Quoted
    124 Post(s)

    Default

    Quote Originally Posted by Kasi View Post
    Simba Code:
    function AttackPlayers2 : Boolean;
    var
      WhiteDots : TPointArray;
      MSBoxes : TBoxArray;
      TempTBA : TBooleanArray;
      I, C : Integer;
    begin
      WhiteDots := GetMiniMapDots('w');
      SetLength(TempTBA, Length(WhiteDots));
      C := 0;
      for I := 0 to High(WhiteDots) do
      begin
        WhiteDots[I] := MMtoMS(WhiteDots[I]);
        TempTBA[I] := (WhiteDots[I].x > -1);
        if TempTBA[I] then
          inc(C);
      end;
      SetLength(MSBoxes, C);
      C := 0;
      for I := 0 to High(TempTBA) do
      begin
        if (TempTBA[I]) then
        begin
          MSBoxes[C] := IntToBox(WhiteDots[I].x - 40, WhiteDots[I].y - 40, WhiteDots[I].x + 40, WhiteDots[I].y + 40);
          if Not PointInBox(Point(MSBoxes[C].X1, MSBoxes[C].Y1), MSBox) then
            case (MSBoxes[C].X1 < 0) of
              True : MSBoxes[C].X1 := MSX1;
              False : MSBoxes[C].Y1 := MSY1;
            end;
          if Not PointInBox(Point(MSBoxes[C].X2, MSBoxes[C].Y2), MSBox) then
            case (MSBoxes[C].X1 < 0) of
              True : MSBoxes[C].X2 := MSX2;
              False : MSBoxes[C].Y2 := MSY2;
            end;
          inc(C);
          Writeln(MSBoxes[C - 1]);
        end;
      end;
      SMART_DrawBoxes(False, False, MSBoxes, clRed);
      Result := (Length(MSBoxes) > 0);
    end;

    Try that.

    Edit : fixed out of range errors..
    Thank you I like you way much better :P
    Not scripting for RS anymore, sorry. Banned too many times.
    MY SCRIPTS

  6. #6
    Join Date
    Dec 2007
    Posts
    2,112
    Mentioned
    71 Post(s)
    Quoted
    580 Post(s)

    Default

    Quote Originally Posted by bud_wis_er_420 View Post
    Thank you I like you way much better :P
    thanks was bored at the time

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
  •