SRL Archive - OSR Help

Check: gate open/closed - need help


Hoodz

2013-11-07 14:41:56

i need to know if this gate is closed or open. i have no ideas anymore…

here are some pics of the gate, its located at edvillage dungeon.





Ashaman88

2013-11-07 14:44:56

If you click on the other side of the door via the minimap does it walk you up to the door and stop? Or does the flag just disappear?

There are ways to do it with the MS, but I think it may be easier to do via minimap the how the flag interacts with obstacles.

Hoodz

2013-11-07 14:50:56

From: Ashaman88
If you click on the other side of the door via the minimap does it walk you up to the door and stop? Or does the flag just disappear?

There are ways to do it with the MS, but I think it may be easier to do via minimap the how the flag interacts with obstacles.


if you stand a few tiles from the gate and you click somewhere behind the gate it will walk to the gate and the flag will disappear.
if you already stand in front of the gate you wont move and the flag wont appear either.

Olly

2013-11-07 15:02:22

Just count the grey gate posts.

program new;

var
img1, img2: integer;

function DownloadToFile(const URL, Filename: string): boolean;
var
FileI: LongInt;
FileC, FileH: string;
begin
Result := False;

FileI := InitializeHTTPClient(False);
try
FileC := GetHTTPPage(FileI, URL);
FileH := GetRawHeaders(FileI);

if ((FileC = '') or (FileH = '')) then
begin
WriteLn('Error downloading "' + URL + '".');
Exit;
end;

FileH := Copy(GetRawHeaders(FileI), 10, Pos(#13, FileH) - 10);

if (FileH <> '200 OK') then
begin
WriteLn('Couldn''t download "' + URL + '", Error Code: ' + FileH + '.');
Exit;
end;

finally
FreeHTTPClient(FileI);
end;

try
if not FileExists(Filename) then
FileI := CreateFile(Filename)
else
FileI := OpenFile(Filename, False);

CloseFile(FileI);

FileI := RewriteFile(Filename, False);
Result := WriteFileString(FileI, FileC);
finally
CloseFile(FileI);
end;
end;

procedure init();
begin
DownloadToFile('http://imageshack.us/a/img191/4739/rqck.png', '1.png');
DownloadToFile('http://imageshack.us/a/img542/6435/qh5p.png', '2.png');

img1 := loadBitmap('1.png');
img2 := loadBitmap('2.png');
end;

procedure isGateOpen(img: integer);
var
w, h: integer;
tpa: TPointArray;
atpa: T2DPointArray;
i, posts: integer;
b: TBox;
begin
setTargetBitmap(img);
getBitmapSize(img, w, h);

setColorToleranceSpeed(2);
setToleranceSpeed2Modifiers(0.14, 0.13);

findColorsTolerance(tpa, 8684943, 0, 0, w-1, h-1, 15);

atpa := clusterTPAEx(tpa, 6, 6);
posts := 0;

for i := 0 to high(atpa) do
begin
b := getTPABounds(atpa[i]);

if (length(atpa[i]) < 30) then
continue;

if ((b.y2 - b.y1) < 50) then
continue;

if ((b.x2 - b.x1) > 30) then
continue;

inc(posts);
end;

case posts of
4: writeln('gate is open!');
3: writeln('gate is closed!');
end;
end;

begin
init();

isGateOpen(img1);
isGateOpen(img2);

freeBitmap(img1);
freeBitmap(img2);
end.

Hoodz

2013-11-07 15:20:19

From: Olly
Just count the grey gate posts.

program new;

var
img1, img2: integer;

function DownloadToFile(const URL, Filename: string): boolean;
var
FileI: LongInt;
FileC, FileH: string;
begin
Result := False;

FileI := InitializeHTTPClient(False);
try
FileC := GetHTTPPage(FileI, URL);
FileH := GetRawHeaders(FileI);

if ((FileC = '') or (FileH = '')) then
begin
WriteLn('Error downloading "' + URL + '".');
Exit;
end;

FileH := Copy(GetRawHeaders(FileI), 10, Pos(#13, FileH) - 10);

if (FileH <> '200 OK') then
begin
WriteLn('Couldn''t download "' + URL + '", Error Code: ' + FileH + '.');
Exit;
end;

finally
FreeHTTPClient(FileI);
end;

try
if not FileExists(Filename) then
FileI := CreateFile(Filename)
else
FileI := OpenFile(Filename, False);

CloseFile(FileI);

FileI := RewriteFile(Filename, False);
Result := WriteFileString(FileI, FileC);
finally
CloseFile(FileI);
end;
end;

procedure init();
begin
DownloadToFile('http://imageshack.us/a/img191/4739/rqck.png', '1.png');
DownloadToFile('http://imageshack.us/a/img542/6435/qh5p.png', '2.png');

img1 := loadBitmap('1.png');
img2 := loadBitmap('2.png');
end;

procedure isGateOpen(img: integer);
var
w, h: integer;
tpa: TPointArray;
atpa: T2DPointArray;
i, posts: integer;
b: TBox;
begin
setTargetBitmap(img);
getBitmapSize(img, w, h);

setColorToleranceSpeed(2);
setToleranceSpeed2Modifiers(0.14, 0.13);

findColorsTolerance(tpa, 8684943, 0, 0, w-1, h-1, 15);

atpa := clusterTPAEx(tpa, 6, 6);
posts := 0;

for i := 0 to high(atpa) do
begin
b := getTPABounds(atpa[i]);

if (length(atpa[i]) < 30) then
continue;

if ((b.y2 - b.y1) < 50) then
continue;

if ((b.x2 - b.x1) > 30) then
continue;

inc(posts);
end;

case posts of
4: writeln('gate is open!');
3: writeln('gate is closed!');
end;
end;

begin
init();

isGateOpen(img1);
isGateOpen(img2);

freeBitmap(img1);
freeBitmap(img2);
end.


thanks olly, i dont completely understand the code you wrote above so i first wait if @Ashaman88 knows something.
ps: your code compiled for me only in lape and for srl-osr we still use pascalscript.
and i this was the result:
SRL Compiled in 0 msec
Successfully executed.

but that might be a problem with my includes.

Nebula

2013-11-07 15:27:53

If you're using sps then

repeat
ClickMinimapBehindGate;
While flagpresent or ismoving do wait();
If CurrentPosition.x > PositionOfGate then
break;
OpenGate;
until CurrentPosition.x > PositionOfGate

Ashaman88

2013-11-07 16:22:11

From: Nebula
If you're using sps then

repeat
ClickMinimapBehindGate;
While flagpresent or ismoving do wait();
If CurrentPosition.x < PositionOfGate then
break;
OpenGate;
until CurrentPosition.x < PositionOfGate


Yeah that's pretty much what I was getting at. No need to deal with MS if you don't have to

Hoodz

2013-11-07 16:34:38

From: Nebula
If you're using sps then

repeat
ClickMinimapBehindGate;
While flagpresent or ismoving do wait();
If CurrentPosition.x < PositionOfGate then
break;
OpenGate;
until CurrentPosition.x < PositionOfGate
Ah okay thank you

Enslaved

2013-11-08 11:34:55

hoods, I think olly's way is a nice failsafe to add

This should work in ps tbh.

function isGateOpen():Boolean;
var
w, h: integer;
tpa: TPointArray;
atpa: T2DPointArray;
i, posts: integer;
b: TBox;
begin
//setTargetBitmap(img);
//getBitmapSize(img, w, h);

setColorToleranceSpeed(2);
setToleranceSpeed2Modifiers(0.14, 0.13);

findColorsTolerance(tpa, 8684943, MSX1, MSY1, MSX2, MSY2, 15); // changed search co-ords

atpa := clusterTPAEx(tpa, 6, 6);
posts := 0;

for i := 0 to high(atpa) do
begin
b := getTPABounds(atpa[i]);

if (length(atpa[i]) < 30) then
continue;

if ((b.y2 - b.y1) < 50) then
continue;

if ((b.x2 - b.x1) > 30) then
continue;

inc(posts);
end;

case posts of
4: begin
writeln('gate is open!');
result:=True;
end;
3: begin
writeln('gate is closed!');
result:=False;
end;
end;
end;