SRL Archive - SRL Archives

Detect Stop Player Movement


Gearsnare

2009-04-08 20:42:14

Here is my function which waits until player stops moving, it helps to overcome if the flags get stuck on the screen.



{*******************************************************************************
function WalkEnd: Boolean;
By: Gearsnare
Description: Waits until player walking or running stops.
*******************************************************************************}

function WalkEnd: Boolean;
var
c, c2, H, i, i2: Integer;
P: array [0..9] of array [0..3] of Integer;
BadColors: TIntegerArray;

begin
BadColors := [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];
repeat
i := 0;
c := 0;
c2 := 9;
repeat
if (not(LoggedIn)) then Exit;
if (not(GetColor(120, 175) = 0)) then
P[i][0] := 571 + Random(110);
P[i][1] := 33 + Random(100);
P[i][2] := GetColor(P[i][0], P[i][1]);
H := High(BadColors);
for i2 := 0 to H do
if (P[i][2] = BadColors[i2]) then Break;
i := i + 1;
until (i = 9);
Wait(1000);
i := 0;
for i := 0 to 9 do
begin
P[i][3] := GetColor(P[i][0], P[i][1]);
for i2 := 0 to H do
if (P[i][3] = BadColors[i2]) then c2 := c2 - 1;
if (P[i][2] = P[i][3]) then c := c + 1;
end;
if (c = 0) then Break;
until (c >= c2);
Result := True;
end;

I'm new to scripting, is it correct to post stuff like this into this part of the forum?

Thanks

mormonman

2009-04-08 20:43:33

Won't work all the time, because of the players and npcs moving. There is a better fix for this.

Gearsnare

2009-04-08 20:53:01

From: mormonman
Won't work all the time, because of the players and npcs moving. There is a better fix for this.


What is better fix?
I will improve by repeating loop if the random points color was that of a NPC, player or drop dot in the morning as it's too late now.

Nadeem

2009-04-08 20:55:57

Hey, nice :) Though I've already released a piece of coding with the same concept, but a bit more reliable :P Although it is not 100% safe/might be slow if other objects are changing on the screen.

Bam Bam

2009-04-08 21:08:07

It may be best to calculate the percent change in the minimap. You could do this a bit like gas checking works.

mormonman

2009-04-08 21:28:47


{*******************************************************************************
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(100, 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);
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);
finally
SetTargetDC(DC);
FreeBitmap(BMP);
FreeBitmap(BMP2);
end;
end;

Gearsnare

2009-04-09 06:57:25

I've edited mine a little so it is much more reliable than what it was.
Yours is too complicated for me, could you please explain how it works?

Thanks

Nava2

2009-04-09 13:18:39

Bullzeye and I actually made it. Anyways, its not all that hard.

All it does is create a bitmap of the minimap. Then, it goes through and sets all of the movable colours to 0.

Following this, it creates another bitmap and finds the same colours, but replaces them with the colour of the original bitmap, so dots will not effect.

Finally, it checks if it can find the old bitmap in the new one, if it can then we have stopped, if it cant then we are moving. :)

Hope I helped :cool:

Richard

2009-04-09 14:18:59

Is that in SRL currently? I can't seem to find it (only looked in FlagChat.scar), I'd find it very useful as its usually the reason my clay softner breaks, used to run for hours, now I get about max 2-3 hours a player.

Gearsnare

2009-04-09 18:25:19

From: Richard
Is that in SRL currently? I can't seem to find it (only looked in FlagChat.scar), I'd find it very useful as its usually the reason my clay softner breaks, used to run for hours, now I get about max 2-3 hours a player.


Are you on about mine or Bullzeye and Nava2's? Neither are currently in SRL though.

Nava2

2009-04-09 20:35:26

Mine is in the dev svn currently. It will be in the next public revision.