SRL Archive - SRL Archives

CheckMovement and WaitUntilStop <--better and more reliable than FlagPresent and Flag


Macrosoft

2008-05-28 23:48:01

Im sorry, I didn't know this section existed, otherwise I would have posted here in the first place.
UPDATE: This should now work with SMART

CheckMovement
You know how when you click on the other side of a fence, the character walks around it? Most of the time, this means the flag will not be visible! Also, sometimes you can be stuck behind something, but the flag may still be there. This function will check if your character is moving without using the flag.

WaitUntilStop
Uses CheckMovement to wait until you character stops.

The Script
(Last two are the ones that would be used by others. The first two are used in CheckMovement)
program New;
{.include SRL/SRL.scar}

function ColorCheck(Color: Integer; Smart: Boolean): Boolean;
var
Dots, W, H, x, y : Integer;
begin
Dots := BitmapFromString(17, 15, 'beNpjYPgPAwxEA2pp+W9' +
'm9o+HB1nkHxjgNASoXkHhDxvbS1T1QPDmzRusWoDmA9V/ZGA4h6oF' +
'qP7SpUs47GG8ycCwB8yAizx69Ojo0aNIIlh0Ycgy4lVPMmDn5mOgG' +
'fj3T/jfPz6S1P/5w/T1K8Pdu8RqAaoHordvGc6cId4eRqD5YPUkhS' +
'RxIQ8AaQdf5g==');
SetTargetBitmap(Dots);
GetBitmapSize(Dots, W, H);
if(FindColorTolerance(x, y, Color, 0, 0, W, H, 10)or(Color=65536))then Result:=False
else Result:=True;
FreeBitmap(Dots);
if(Smart=True)then SetTargetDC(SmartGetDC)
else ResetDC;
end;

function FindGoodPoint(x1, y1, x2, y2: Integer; Smart: Boolean; var Color: Integer):TPoint; //finds good coords, duh!
var
y, x: Integer;
begin
y:=y1-1;
repeat
begin
y:=y+1;
x:=x1;
repeat
begin
x:=x+1;
Result.x:=x;
Result.y:=y;
Color:=GetColor(x, y);
end;
until(ColorCheck(GetColor(x, y), Smart)or(x=x2+1));
end;
until((ColorCheck(GetColor(x, y), Smart))or((y=y2)and(x=x2+1)));
if((y=y2)and(x=x2+1))then
begin
Result.x:=-1;
Result.y:=-1;
end;
end;
{*******************************************************************************
function CheckMovement(Smart: Boolean): Integer;
By: Macrosoft
Description: Set whether you are useing SMART or not.
Returns 0 if an error occured.
Returns 1 if not moving.
Returns 2 if moving.
*******************************************************************************}
function CheckMovement(Smart: Boolean): Integer;
var
RPoint: Tpoint;
RColor, i, Strikes: Integer;
NColor: Integer;
begin
i:=0;
RPoint:=FindGoodPoint(570, 33, 683, 135, Smart, RColor);
if(RPoint.x=-1)then
begin
WriteLn('Error: Could not find referance point');
Result:=0;
Exit;
end;
Strikes:=0;
repeat
begin
Wait(500);
NColor:=GetColor(RPoint.x, RPoint.y);
if(ColorCheck(NColor, Smart))and(not(NColor= RColor))then //if color changes
begin
i:=i+1;
Strikes:=0;
RColor:=NColor;
end else
begin
i:=0;
Strikes:=Strikes+1;
end;
end;
until(i=3) or (Strikes=3);
if(i=3)then
begin
Result:=2;
WriteLn('We are moving!');
end else
begin
Result:=1;
WriteLn('We are not moving!');
end;
end;

{*******************************************************************************
function WaitUntilStop(Smart: Boolean): Integer;
By: Macrosoft
Description: Waits until the character stops moving.
Set whether you are useing SMART or not.
Returns 0 if and error occured.
Returns 1 if you are caught on something and the flag
remains while you are still
Returns 2 if stopped.
*******************************************************************************}

function WaitUntilStop(Smart: Boolean): Integer;
var
i, Strikes: Integer;
begin
Strikes:=0;
i:=0;
repeat
begin
i:=CheckMovement(Smart);
if(i=0)then Strikes:=Strikes+1 else Strikes:=0;
end;
until(i=1) or (Strikes=3);
if(Strikes=3)then
begin
Writeln('Some error has occured');
Result:=0;
Exit;
end;
if(FlagPresent)then
begin
Writeln('You are caught on something!');
Result:=1;
Exit;
end;
Result:=2;
end;

begin
SetupSRL;
CheckMovement(False);
end.

Camaro'

2008-05-29 07:12:52

From: Macrosoft
Im sorry, I didn't know this section existed, otherwise I would have posted here in the first place.

CheckMovement
You know how when you click on the other side of a fence, the character walks around it? Most of the time, this means the flag will not be visible! Also, sometimes you can be stuck behind something, but the flag may still be there. This function will check if your character is moving without using the flag.

WaitUntilStop
Uses CheckMovement to wait until you character stops.

The Script
(Last two are the ones that would be used by others. The first two are used in CheckMovement)
program New;
{.include SRL/SRL.scar}

function ColorCheck(Color: Integer): Boolean;
var
Dots, W, H, x, y : Integer;
begin
Dots := BitmapFromString(17, 15, 'beNpjYPgPAwxEA2pp+W9' +
'm9o+HB1nkHxjgNASoXkHhDxvbS1T1QPDmzRusWoDmA9V/ZGA4h6oF' +
'qP7SpUs47GG8ycCwB8yAizx69Ojo0aNIIlh0Ycgy4lVPMmDn5mOgG' +
'fj3T/jfPz6S1P/5w/T1K8Pdu8RqAaoHordvGc6cId4eRqD5YPUkhS' +
'RxIQ8AaQdf5g==');
SetTargetBitmap(Dots);
GetBitmapSize(Dots, W, H);
if(FindColorTolerance(x, y, Color, 0, 0, W, H, 10)or(Color=65536))then Result:=False
else Result:=True;
FreeBitmap(Dots);
ResetDC;
end;

function FindGoodPoint(x1, y1, x2, y2: Integer; var Color: Integer):TPoint; //finds good coords, duh!
var
y, x: Integer;
begin
y:=y1-1;
repeat
begin
y:=y+1;
x:=x1;
repeat
begin
x:=x+1;
Result.x:=x;
Result.y:=y;
Color:=GetColor(x, y);
end;
until(ColorCheck(GetColor(x, y))or(x=x2+1));
end;
until((ColorCheck(GetColor(x, y)))or((y=y2)and(x=x2+1)));
if((y=y2)and(x=x2+1))then
begin
Result.x:=-1;
Result.y:=-1;
end;
end;
{*******************************************************************************
function CheckMovement: Integer;
By: Macrosoft
Description: Returns 0 if an error occured.
Returns 1 if not moving.
Returns 2 if moving.
*******************************************************************************}
function CheckMovement: Integer;
var
RPoint: Tpoint;
RColor, i, Strikes: Integer;
NColor: Integer;
begin
i:=0;
RPoint:=FindGoodPoint(570, 33, 683, 135, RColor);
if(RPoint.x=-1)then
begin
WriteLn('Error: Could not find referance point');
Result:=0;
Exit;
end;
Strikes:=0;
repeat
begin
Wait(500);
NColor:=GetColor(RPoint.x, RPoint.y);
if(ColorCheck(NColor))and(not(NColor= RColor))then //if color changes
begin
i:=i+1;
Strikes:=0;
RColor:=NColor;
end else
begin
i:=0;
Strikes:=Strikes+1;
end;
end;
until(i=3) or (Strikes=3);
if(i=3)then
begin
Result:=2;
WriteLn('We are moving!');
end else
begin
Result:=1;
WriteLn('We are not moving!');
end;
end;

{*******************************************************************************
function WaitUntilStop: Integer;
By: Macrosoft
Description: Waits until the character stops moving.
Returns 0 if and error occured.
Returns 1 if you are caught on something and the flag
remains while you are still
Returns 2 if stopped.
*******************************************************************************}

function WaitUntilStop: Integer;
var
i, Strikes: Integer;
begin
Strikes:=0;
i:=0;
repeat
begin
i:=CheckMovement;
if(i=0)then Strikes:=Strikes+1 else Strikes:=0;
end;
until(i=1) or (Strikes=3);
if(Strikes=3)then
begin
Writeln('Some error has occured');
Result:=0;
Exit;
end;
if(FlagPresent)then
begin
Writeln('You are caught on something!');
Result:=1;
Exit;
end;
Result:=2;
end;

begin
SetupSRL;
CheckMovement;
end.


Looks good :P

the scar noob

2008-05-29 17:27:19

Hehe, nicely found! I only saw 1 procedure/function doing this before. Made by fawki, its' in his Fally Guard Fighter:)

Nice job;)

-Tsn.

Macrosoft

2008-05-29 18:29:34

Thanks, you say this has already been made?

Markus

2008-05-30 10:22:05

You know that this will fuck up badly when autoing with SMART? Due to your DC usage :)

Macrosoft

2008-05-31 12:07:13

darn, I could find every color in all the dots and check it one by one?

Edit, I think I fixed it.

Freddy1990

2008-05-31 17:31:39

What's the use of this:
  if(Smart=True)then SetTargetDC(SmartGetDC)
else ResetDC;
SetTargetDC(SmartGetDC);
No matter if you set Smart to true or not you still end up selecting it as target…

Macrosoft

2008-05-31 19:54:15

ohhh, woops. Nice catch. That wasn't originally on there, I just added it when I would told this would mess smart up.