SRL Archive - SRL Archives

Function DifferentMSColours: Boolean; AND Procedure CharacterMoving; [Colour based]


Floor66

2009-04-05 14:00:11


{*******************************************************************************
Function DifferentMSColours: Boolean;
By: Floor66
Description: This function takes the colours of specific MainScreen points,
waits 100 + Random(50), takes new colours, and checks if the
colours are different from the first ones taken.
*******************************************************************************}

Function DifferentMSColours(MS_Points : Integer): Boolean;
Var
BeginColours, CheckColours : Array Of Integer;
ColorCoords : TPointArray;
i : Integer;
Begin
SetLength(ColorCoords, MS_Points);
SetLength(BeginColours, MS_Points);
SetLength(CheckColours, MS_Points);
For i := 0 To High(BeginColours) Do
Begin
ColorCoords[i].x := MSCX + Random(50);
ColorCoords[i].y := MSCY + Random(50);
BeginColours[i] := GetColor(ColorCoords[i].x, ColorCoords[i].y);
End;
Wait(100 + Random(50));
For i := 0 To High(CheckColours) Do
Begin
CheckColours[i] := GetColor(ColorCoords[i].x, ColorCoords[i].y);
If BeginColours[i] <> CheckColours[i] Then
Result := True;
End;
End;

{*******************************************************************************
Procedure CharacterMoving;
By: Floor66
Description: This procedure incorporates the function DifferentMSColours to do
a check if the character is still moving. A real handy check when
doing something with walking!
*******************************************************************************}

Function CharacterMoving: Boolean;
Var
Checks, t : Integer;
Begin
Status('Character is moving.');
Wait(1500 + Random(250));
Result := True;
MarkTime(t);
Repeat
If (Not DifferentMSColours(7)) Then
Inc(Checks);
If (Checks >= 2) Or (Not FlagPresent) Then
Result := False;
If TimeFromMark(t) >= (10 * 1000) Then
Result := False;
Until(Not Result);
Status('Character is not moving.');
End;


Use it as;

While CharacterMoving Do
Wait(10 + Random(50));

In reflection, there is/was a function called CharacterMoving. But reflection breaks all the time because of hooks (no offence; it's great).

I've gotten this idea from Nadeem, who made something like this, and I sort of expanded it.

This waits until the character has 100% STOPPED moving, or if the flag disappears. It does 2 checks to make sure, and there's a 15-sec failsafe.

PLEASE TEST IT! I'M ALREADY USING IT MYSELF AND IT WORKS FOR ME, BUT I WANT TO SEE IT WITH OTHERS!

n3ss3s

2009-04-05 15:24:21

It has some quite obvious things to be fixed,

a) Why use high when you know the length of the array?
b) If MS_Points is more than 7, it won't work. Use SetArrayLength.

Also, at the moment player dots, NPC dots etc might screw it up easily. Use sin and cos to easily get random points from anywhere off the map, not only in a 50x50 box…

Floor66

2009-04-05 15:33:20

It doesn't get the minimap. AFAIK there are no NPC dot's on the MainScreen ;)
Also, I forgot to set the length of these BeginColours/CheckColours, I messed up a bit :p

Fixed it up.

Freddy1990

2009-04-14 16:53:18

Argh, capitalized keywords, it hurts my eyes! Shame on you!

Floor66

2009-04-16 23:06:30

Bah, lots of people do it. I've just gotten used to it.
I keep to standards, but capitalizing is upto the scripter him(/her)self.

Gu3st...

2009-04-18 11:29:11

What if the color it picks is from a monster, npc or other player?

Floor66

2009-04-18 11:36:10

It picks a few colours.
And it does 2 checks for failsafes.

It has always worked for me.

BobboHobbo

2009-04-25 07:25:45

Nice idea, I was just thinking of something like this, a hoverless tree checker ;) ill try it out with this.

Nava2

2009-04-25 18:49:34

From: BobboHobbo
Nice idea, I was just thinking of something like this, a hoverless tree checker ;) ill try it out with this.


Thing is, there are no more ents. :)

E: Check this out:
{*******************************************************************************
function IsMoving(WaitTime: Integer): Boolean;
By: Bullzeye95; Edits by Nava2
Description: Checks if the currently loaded player is moving. Uses Minimap,
ignoring all dots which can move without the player moving.
Nava2 edit: Added try..finally, also changed to work with SMART,
as well added WaitTime Parameter.
*******************************************************************************}
function IsMoving(WaitTime: Integer): Boolean;
var
BMP, BMP2, I, H, x, y: Integer;
ReplaceCols: TIntegerArray;
P: TPointArray;
DC: HDC;
begin
WaitTime := Max(50, WaitTime);
try
DC := GetTargetDC;
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);
H := High(ReplaceCols);
for I:= 0 to H do
FastReplaceColor(BMP, ReplaceCols[i], 0);
wait(WaitTime);
SafeCopyCanvas(GetClientCanvas, GetBitmapCanvas(BMP2), MMCX - 50, MMCY - 50, MMCX + 50, MMCY + 50, 0, 0, 100, 100);
SetTargetDC(GetBitmapDC(BMP2));
for I:= 0 to H do
begin
FindColorsTolerance(P, ReplaceCols[i], 0, 0, 99, 99, 0);
y:= High(P);
for x:= 0 to y 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);
finally
SetTargetDC(DC);
FreeBitmap(BMP);
FreeBitmap(BMP2);
end;
end;

Same things yours does, but more accurate. :)

Floor66

2009-04-25 19:10:40

It IS NOT the same thing …
That looks on the MINIMAP.
Mine on the MAINSCREEN ^^.

Bobarkinator

2009-04-26 03:06:12

From: Nava2
Thing is, there are no more ents. :)



Still need to check if tree is gone…

Nava2

2009-04-26 08:07:48

From: Bobarkinator
Still need to check if tree is gone…


Why the hell would you be looking for movement then.

Bobarkinator

2009-04-27 01:07:05

From: Nava2
Why the hell would you be looking for movement then.


It's not necessarily movement. Their will be different colors when a tree is there and when a tree is absent, so you just have to call this function to check.