SRL Archive - Research & Development Lounge

Check Movement- A better version of flag


Macrosoft

2008-05-27 19:00:57

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.
UPDATE: This function should now work with SMART

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.

Your move N1Ke, I told ya so (Were having a little Teacher Student brawl)

Nava2

2008-05-29 17:18:21

Delete the members section one, or close it and make a link to this one ;)

Nava2

Naum

2008-05-29 17:24:18

From: Nava2
Delete the members section one, or close it and make a link to this one ;)

Nava2


Who are you to judge?
Its Macro's Thread Mate.

Macrosoft

2008-05-29 18:34:49

No its fine. He was just giving advice. I had posted in both sections because I thought that the srl member section was for functions that should go to srl, but now I have found the right section for that.

sirlaughsalot

2008-05-29 21:28:26

Dude this is godly! couldn't you use it for things like fishing?

Smartzkid

2008-05-29 21:53:14

Looks great, but does it have any impact on speed?

Macrosoft

2008-05-29 23:18:33

well, not on my computer. It may cause I little lag on really ancient computers. If you think about it, it doesn't do anything too complicated that would cause a lag. Thanks for the feedback.

Nava2

2008-05-31 14:02:41

From: NaumanAkhlaQ
Who are you to judge?
Its Macro's Thread Mate.


He asked for it :(.

On topic;

I think you have some competition; some others are making some better functions than FlagPresent as well. :D

Nava2

Macrosoft

2008-05-31 14:21:53

Did I inspire them? lol

Ill just have to see what they do, and then improve this (Or think of an argument why mine is better:)).

Nava2

2008-05-31 14:34:27

I dunno theirs is damn impressive :)

Nava2

Macrosoft

2008-05-31 14:39:32

Do you have a link?

bullzeye95

2008-05-31 15:55:14

He's talking about me :p
I didn't even know this existed. I just got bored today and decided to make one. I don't want to hijack this thread, but I'll edit this post with the link if you want me to.

Macrosoft

2008-05-31 19:52:29

If anyone sees your link, they are scrolling down and have obviously already read the first post. Go ahead and post the link. Maybe we could combine the ideas to make a master function :).

bullzeye95

2008-06-01 12:56:15

Too lazy to make a link to it… here it is:
program New;
const
MMX1 = 550;
MMX2 = 703;
MMY1 = 8;
MMY2 = 161;
MMCX = 627;
MMCY = 85;

function IsMoving: Boolean;
var
BMP, BMP2, I, x, y, Handle: Integer;
ReplaceCols: TIntegerArray;
P: TPointArray;
begin
Handle:= GetClientWindowHandle;
ReplaceCols:= [65536, 16711422, 12961221, 14869218, 16777215, 15527148, 195836, 56797, 60909, 52428,
13816530, 982782, 1310462, 62965, 2105598, 395004, 789758, 3553023, 217, 188, 241,
206, 233, 64768, 58880, 51456, 49152, 44800, 61440, 16215571, 9716750, 13129742];
BMP:= BitmapFromString(100, 100, '');
BMP2:= BitmapFromString(100, 100, '');
SafeCopyCanvas(GetClientCanvas, GetBitmapCanvas(BMP), MMCX - 50, MMCY - 50, MMCX + 50, MMCY + 50, 0, 0, 100, 100);
for I:= 0 to High(ReplaceCols) do
FastReplaceColor(BMP, ReplaceCols[I], 0);
wait(250);
SafeCopyCanvas(GetClientCanvas, GetBitmapCanvas(BMP2), MMCX - 50, MMCY - 50, MMCX + 50, MMCY + 50, 0, 0, 100, 100);
SetTargetBitmap(BMP2);
for I:= 0 to High(ReplaceCols) do
begin
FindColorsTolerance(P, ReplaceCols[I], 0, 0, 99, 99, 0);
for x:= 0 to High(P) do
FastSetPixel(BMP2, P[x].x, P[x].y, FastGetPixel(BMP, P[x].x, P[x].y));
end;
Result:= not FindBitmapIn(BMP, x, y, 0, 0, 100, 100);
SetClientWindowHandle(Handle);
FreeBitmap(BMP);
FreeBitmap(BMP2);
end;

procedure WaitWhileMoving;
begin
while IsMoving do ;
end;

begin
// writeln(booltostr(IsMoving));
WaitWhileMoving;
end.

Macrosoft

2008-06-01 13:45:34

well, you set target bitmap, but you never resetdc, so im pretty sure that will screw up the script. Im not sure which way is faster. Im too lazy to try and figure out what it does, can you explain?

bullzeye95

2008-06-01 14:26:26

I do reset it.
SetClientWindowHandle(Handle);

Macrosoft

2008-06-01 14:57:14

so whats the difference between that and resetdc?

bullzeye95

2008-06-01 15:02:09

Just the fact that I had no clue that ResetDC existed, so I did it old school.
I just got the handle of the client before doing SetTargetBitmap, then set the handle back to the handle I had previously gotten.

Macrosoft

2008-06-01 15:09:46

when you use settargetbitmap, all the color searching functions are performed on the bitmap. Resetdc undoes this so all the color searching functions are performed on the client. I also have SetTargetDC(SmartGetDC) for those who use smart.

Can you explain what your function does, im too lazy to translate it into english.

Mine finds a point that is not the color of any dot (because it will move) and then waits a bit and checks those same coords. If the color is the same within a tol, then you are not moving. If it is different, but not the color of a dot, then you are moving. I also use my "strikes" failsafe just in case your computer lags.

bullzeye95

2008-06-01 20:41:50

Mine gets a bitmap of part of the center of the minimap and edits all of the colors of dots to 0, so that it will not look for those colors when finding the bitmap later on. It then waits 250 MS to give time for the player to move, and gets that same part of the minimap again. To make sure that minimap dots don't affect it, it makes all the points that the dots are on the color of the original bitmap (so that the colors match no matter what). If it finds the original bitmap in the second one, it returns false. Else true. Simple, but effective.

Macrosoft

2008-06-01 22:34:20

good idea

I think im going to edit mine so that the user can input the amount of points used. Then Ill shorten my strike failsafe a bit and the whole thing should be faster.

Edit: Is it faster to have it check the colors one by one (what you did) or have it search for them on a bitmap (what I did)?

Jackrawl

2008-06-06 20:14:43

From: Macrosoft
good idea

I think im going to edit mine so that the user can input the amount of points used. Then Ill shorten my strike failsafe a bit and the whole thing should be faster.

Edit: Is it faster to have it check the colors one by one (what you did) or have it search for them on a bitmap (what I did)?


The bitmap should be faster.