SRL Archive - OSR Help

Need some array help


bud_wis_er_420

2013-05-30 15:16:35

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…
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…
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…
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
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.
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.

x[Warrior]x3500

2013-05-30 15:35:16

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?

bud_wis_er_420

2013-05-30 15:56:09

EDIT Think I finaly Figured it out…
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;






From: x[Warrior]x3500
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".
// 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.
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…
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
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.

Kasi

2013-05-30 16:15:35


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..

bud_wis_er_420

2013-05-30 19:57:36

From: Kasi

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

Kasi

2013-05-30 20:04:36

From: bud_wis_er_420
Thank you I like you way much better :P


thanks :D was bored at the time